Loading...

How to use Comments as Prompts in GitHub Copilot for Visual Studio

How to use Comments as Prompts in GitHub Copilot for Visual Studio

GitHub Copilot is a coding assistant powered by Artificial Intelligence (AI), which can run in various environments and help you be more efficient in your daily coding tasks. In this new series of content, we will show you how GitHub Copilot works in Visual Studio specifically and how it helps you being more productive.

 

In the second short video in this series, my colleague Bruno Capuano will use comments to trigger GitHub Copilot to generate code directly inline in the current file.

 

In case you are not sure, check how to install GitHub Copilot for Visual Studio in the first article of this series.

 

What’s interesting with GitHub Copilot for Visual Studio is that it’s not just suggesting code, but it is also suggesting completion for your comments. This can be quite useful when you write documentation, for example.

 

In the example, Bruno is typing a comment looking like this:

 

 

 

 

// function to get the year of birth

 

 

 

 

Immediately Copilot jumps to action and proposes to complete the comment as follows:

 

 

 

 

// function to get the year of birth *from the age*

 

 

 

 

(Note: in this example I added *stars* around the suggested code. In the Visual Studio IDE, the suggestion would appear greyed out).

 

In order to validate the suggestion and add it to the code, you can simply press the Tab key. Then, if you press Enter, Copilot is going to suggest some code. Based on your internet connection, this can be either immediate or take a couple of seconds. The code suggestion will also be added inline and greyed out. And here too, you can accept the suggestion by pressing the Tab key.
 

Validating the output

The most important concept to keep in mind when dealing with Artificial Intelligence is that the user (that’s you) should always validate the output of the model. You have the opportunity to check the Copilot output when the code is added and greyed out, or after you press the Tab key. I often accept the suggestion and then go back to the generated code to change small details to “make the code mine” or even to fix it.

 

GitHub Copilot is not a compiler!

 

What this means is that the code generated by GitHub Copilot can very well fail compilation, leaving you, the Pilot in charge, responsible to check and correct the code.

Disabling completion

Note that you might not always want Copilot to suggest completions in your code files. It’s quite easy to deactivate it, either for all code files, or even just for specific files such as markdown or C#. Simply click on the small Copilot icon on the Visual Studio taskbar and then select the appropriate option.

 

LBugnion_0-1710942845668.png

LBugnion_1-1710942916712.png
 

More information

For more information, check our collection with resources here. Also, you can see the full length video here. Stay tuned to this blog for more content posted regularly. And of course, you can also subscribe to our YouTube channel to get more video content!

Published on:

Learn more
Azure Developer Community Blog articles
Azure Developer Community Blog articles

Azure Developer Community Blog articles

Share post:

Related posts

This Month in Azure Static Web Apps | 09/2024

    We are back with another edition of the Azure Static Web Apps Community! :party_popper:   September was yet another month ...

1 year ago

GitHub Copilot for Azure: 6 Must-Try Features

As developers, we are constantly seeking tools that streamline our workflows and boost productivity. … Enter GitHub Copilot for Azure, now in ...

1 year ago

Responsible AI Mitigation Layers

Generative AI is increasingly being used in various kinds of systems to augment humans and infuse intelligent behavior into existing and new a...

1 year ago

Streamline Your Azure Workflow: Introducing GitHub Copilot for Azure in VS Code

I'm excited to announce the public preview of GitHub Copilot for Azure - a new addition to your toolkit that seamlessly integrates with G...

1 year ago

Build Intelligent Apps Code-First with Prompty and Azure AI

      Building Generative AI applications can feel daunting for traditional app developers. What does the end-to-end applicati...

1 year ago

Certificación AI-900 (Fundamentos de IA) con Chicas en IA

La inteligencia artificial ha llegado para quedarse, ¡y más aún con la revolucionaria IA generativa! Para ayudar a los profesionales a especia...

1 year ago

Get certified with Learn Live GitHub series!

GitHub Universe is coming, and Microsoft and GitHub are partnering to offer a new special Learn Live series in Brazilian Portuguese, English a...

1 year ago

Certifícate con Learn Live GitHub en Español

Microsoft y GitHub se han unido para ofrecer una nueva serie especial de Learn Live en inglés y español: GitHub 2024. Del 10 al 24 de Octubre,...

1 year ago

Evaluating generative AI: Best practices for developers

As a developer working with generative AI, you've likely marveled at the impressive outputs your models can produce. But how do you ensure the...

1 year ago

Introducing Azure Product Retirement Livestreams

The Azure Retirements team, in collaboration with key partner groups, is excited t...

1 year ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.