Implementing a functionality with GitHub Copilot for Visual Studio
Published Apr 25 2024 08:02 AM 1,601 Views
Microsoft

The main benefit of using Generative AI in Visual Studio is that it enables you to type faster. It's important to keep in mind that Copilot is not a compiler, it's not magical, it is just an assistant. It's still important to test the generated code thoroughly (in fact there isn't even a guarantee that Copilot generated code will even compile!)

In our new video, my colleague Gwyn demonstrates how a new feature can be implemented by prompting Copilot in an inline dialog. 

 

 

The example

First Gwyn starts by placing the cursor in an existing method belonging to a web API. The issue here is that the query is case-sensitive. So if the user enters the country Peru, the query works fine. But if they enter peru instead, the query fails. That is an issue because URLs are often considered case-insensitive (in fact it depends on the server...). 

To fix this, Gwyn needs some code converting the user input into title case, in other words, the first letter should be capitalized.

Once the code is generated, Gwyn verifies that it looks correct, and when satisfied she can then test the application and make sure everything works as expected.

 

What does Copilot work best with?

You may wonder what kind of code GitHub Copilot can generate. The answer is of course dependent on the training it received. It will perform great with "popular" languages such as .NET, JavaScript, Python, Java and many more. But with more confidential languages (COBOL...), languages that are not widely available in public repositories, that can prove more difficult. As always with a new tool, the best is to try it out with reasonable expectations, and see how it performs. It's probably similar to what happens when you use a search engine, I can imagine it's quite complex to get answers about COBOL there too...

 

Getting more information

As always you can get more information from our playlist on the Visual Studio YouTube channel, or in this blog. We continue to post regularly about this tropic, so stay tuned! And don't forget to check our collection with additional resources.

 

Co-Authors
Version history
Last update:
‎Apr 25 2024 08:02 AM
Updated by: