Referencing a file in GitHub Copilot for Visual Studio
Published May 09 2024 12:00 AM 1,309 Views
Microsoft

When you start a new project from scratch in Visual Studio, a few files get created. Many templates are available, for many types of applications, from simple console apps to complex web applications, as well as mobile, serverless, and many many more. All these projects consist of multiple files. You have your code files, containing the software that will be run, organized in classes, with often each class in its own file. You have the configuration files, be it JSON, XML, YAML or other. You may even have data files, embedded in the application when it's built. 

 

In the new video we just posted, my colleague Gwyn shows how you can use the Hash shortcut (#) to reference another file.

 


Context is everything

As we mentioned many times in this series, what makes a good Copilot output starts with a good prompt. But the prompt is more than "just" asking the large language model to do something. You also need to provide context. In AI parlance, we talk about "grounding" the model with data, or Retrieval Augmented Generation RAG.

 

Through its training, Copilot has access to general knowledge about the platform that you are using. It also has specific knowledge about libraries and frameworks. But what's missing is your own private code, the code that the rest of the world doesn't see. For example, you can let Copilot know that another file contains a series of methods that the current class can use.

 

In the example, Gwyn points Copilot to a JSON file containing data so a test can be generated. This adds precious context so that Copilot generates the correct code faster. 

 

More information

As always you can find many resources in this collection. I also added all the blog posts and videos in this series so you can easily find past episodes and gain more knowledge. And of course, the best way to stay up to date is to subscribe to the Visual Studio YouTube channel, the Visual Studio DevBlog and of course this blog here.

 

20240410D Referenrencing a file in GitHub Copilot for Visual Studio.png

Co-Authors
Version history
Last update:
‎May 09 2024 05:06 AM
Updated by: