Skip to main content

Asking GitHub Copilot questions in your IDE

Use Copilot Chat in your editor to give code suggestions, explain code, generate unit tests, and suggest code fixes.

Prerequisites

Se você tiver acesso ao GitHub Copilot por meio de sua organização ou empresa, não poderá usar o GitHub Copilot Chat se o proprietário da organização ou o administrador corporativo tiver desabilitado a conversa. Confira "Managing policies for Copilot in your organization".

Submitting prompts

You can ask Copilot Chat to give code suggestions, explain code, generate unit tests, and suggest code fixes.

  1. Open the chat view by clicking the chat icon in the activity bar or by entering Control+Command+i (Mac) / Ctrl+Alt+i (Windows/Linux).

    Screenshot of the Copilot Chat icon in the Activity Bar.

    Tip

    For additional ways to access Copilot Chat, including inline with your code, see Additional ways to access Copilot Chat below.

  2. Enter a prompt in the prompt box, or click one of the suggested prompts. For example prompts, see "Example prompts" below.

  3. Evaluate Copilot's response, and make a follow up request if needed.

    The response may contain text, code blocks, buttons, images, URIs, and file trees. The response often includes interactive elements. For example, the response may include a menu to insert a code block, or a button to invoke a Visual Studio Code command.

Using keywords in your prompt

You can use special keywords to help Copilot understand your prompt.

Chat participants

Use chat participants to scope your prompt to a specific domain. To use a chat participant, type @ in the chat prompt box, followed by a chat participant name. Chat participants include:

  • @workspace: Has context about the code in your workspace. Use @workspace when you want Copilot to consider the structure of your project, how different parts of your code interact, or design patterns in your project. See "Ask questions about your project."

  • @vscode: Has context about Visual Studio Code commands and features. Use @vscode when you want help with Visual Studio Code. See "Ask questions about Visual Studio Code."

  • @terminal: Has context about the Visual Studio Code terminal shell and its contents. Use @terminal when you want help creating or debugging terminal commands. See "Ask questions about the command line."

  • @github: Allows you to use GitHub-specific Copilot skills. See "Using GitHub skills for Copilot."

In addition to the built-in Visual Studio Code chat participants, you can also install Copilot Extensions that provide chat participants. You can install these extensions from GitHub Marketplace and from Visual Studio Code Marketplace. For information about extensions from GitHub Marketplace that provide chat participants, see "Using extensions to integrate external tools with Copilot Chat."

To see all available chat participants, type @ in the chat prompt box.

See also Chat participants in the Visual Studio Code documentation.

Slash commands

Use slash commands to avoid writing complex prompts for common scenarios. To use a slash command, type / in the chat prompt box, followed by a command. Slash commands include:

  • /tests: Generate unit tests for the selected code
  • /fix: Propose a fix for problems in the selected code
  • /explain: Explain the selected code
  • /clear: Start a new chat

To see all available slash commands, type / in the chat prompt box. See also Slash commands in the Visual Studio Code documentation.

Chat variables

Use chat variables to include specific context in your prompt. To use a chat variable, type # in the chat prompt box, followed by a chat variable. Chat variables include:

  • #file: Include a specific file as context in the chat.
  • #git: Include information about the current Git repository.
  • #terminalLastCommand: Include the last run command in the active Visual Studio Code terminal.

To see all available chat variables, type # in the chat prompt box. See also Chat variables in the Visual Studio Code documentation.

Example prompts

You can ask Copilot Chat specific questions about your project or general software questions. You can also ask Copilot Chat to write code, fix errors, write tests, and document code.

Ask general software questions

You can ask Copilot Chat general software questions. For example:

  • tell me about nodejs web server frameworks
  • how to create an express app
  • @terminal how to update an npm package (uses the @terminal chat participant)

Ask questions about your project

You can ask Copilot Chat questions about your project.

  • what sorting algorithm does this function use
  • @workspace how are notifications scheduled
  • #file:gameReducer.js #file:gameInit.js how are these files related

To give Copilot the correct context, try some of these strategies:

  • Highlight relevant lines of code
  • Use chat variables like #selection, #file, #editor, #codebase, or #git
  • Use the @workspace chat participant

Write code

You can ask Copilot to write code for you. For example:

  • write a function to sum all numbers in a list
  • add error handling to this function
  • @workspace add form validation, similar to the newsletter page

When Copilot returns a code block, the response includes options to copy the code, or to insert the code at your cursor, into a new file, or into the terminal.

Set up a new project

Use the /new slash command to set up a new project. For example:

  • /new react app with typescript
  • /new python django web application
  • /new node.js express server

Copilot will suggest a directory structure and provide a button to create the suggested files and contents. To preview a suggested file, select the file name in the suggested directory structure.

Use the /newNotebook slash command to set up a new Jupyter notebook. For example:

  • /newNotebook retrieve the titanic dataset and use Seaborn to plot the data

Fix, improve, and refactor code

If your active file contains an error, use the /fix slash command to ask Copilot to fix the error.

You can also make general requests to improve or refactor your code.

  • how would you improve this code?
  • translate this code to C#
  • add error handling to this function

Write tests

Use the /tests slash command to ask Copilot to write tests for the active file or selected code. For example:

  • /tests
  • /tests using the Jest framework
  • /tests ensure the function rejects an empty list

The /tests slash command writes tests for existing code. If you prefer to write tests before writing code (test driven development), omit the /tests command. For example:

  • Add tests for a JavaScript function that should sum a list of integers

Ask questions about Visual Studio Code

Use the @vscode chat participant to ask specific questions about Visual Studio Code. For example:

  • @vscode tell me how to debug a node.js app
  • @vscode how do I change my Visual Studio Code colors
  • @vscode how can I change key bindings

Ask questions about the command line

Use the @terminal chat participant to ask specific questions about the command line. For example:

  • @terminal find the largest file in the src directory
  • @terminal #terminalLastCommand to explain the last command and any errors

Using GitHub skills for Copilot

Note

  • This feature is only available if you have a Copilot Enterprise subscription.
  • The @github chat participant is currently in beta and is subject to change.

Copilot has a collection of GitHub-specific skills that it can use to answer your questions. To access these skills in Copilot Chat in VS Code, include @github in your question.

When you add @github to a question, Copilot dynamically selects an appropriate skill, based on the content of your question. You can also explicitly ask Copilot Chat to use a particular skill. You can do this in two ways:

  • Use natural language to ask Copilot Chat to use a skill. For example, @github Search the web to find the latest GPT4 model from OpenAI.
  • To specifically invoke a web search you can include the #web variable in your question. For example, @github #web What is the latest LTS of Node.js?

Currently available skills

You can generate a list of currently available skills by asking Copilot: @github What skills are available?

The skills you can use in Copilot Chat in VS Code include those shown in the table below.

SkillDescriptionEnabled by default?Example question
Code searchNatural language code search in the default branch of the Git repository. This skill is useful when you want to know where or how certain functionality has been implemented in the code. Note: the repository must be indexed - see "Asking GitHub Copilot questions in GitHub.com."Yes@github Where is the logic that controls the user session management, and how does it work?
Path searchRetrieves a specific file in the default branch of the Git repository. This skill is useful when you provide the exact path of a file in the repository.Yes@github What logic does user_auth.js encapsulate?
Show symbol definitionRetrieves the lines of code that define a specific code symbol (function, class, or struct) in the default branch of the Git repository. This skill is useful when you have the exact name of a symbol, and want to understand it.Yes@github Write unit tests for the AuthUser method
Knowledge base searchTell Copilot Chat to answer a question within the context of a knowledge base. To initiate a knowledge base search, first enter @github #kb.YesEnter @github #kb, then choose your organization's style guide knowledge base, then ask: What is our coding convention for indentation?
Web searchSearches the web using the Bing search engine. This skill is useful for teaching Copilot about recent events, new developments, trends, technologies, or extremely specific, detailed, or niche subjects.No (requires admin approval - see "Gerenciando políticas e recursos do Copilot em sua empresa")@github What are some recent articles about SAT tokens securing against vulnerabilities in Node?

Asking a question about a knowledge base

Note

This feature is only available if you have a Copilot Enterprise subscription.

Organization owners can create knowledge bases, grouping together Markdown documentation across one or more repositories. For more information, see "Gerenciando bases de informações do Copilot."

You can tell Copilot to answer a question within the context of a knowledge base.

  1. At the bottom of the Copilot Chat window, in the Ask Copilot or type / for commands text box, type @github #kb, then press Enter to open the knowledge base selector.
  2. Pick one of your available knowledge bases using the arrow keys, then press Enter.
  3. In the Ask Copilot or type / for commands text box, continue your message with your question, and then press Enter.
  4. Copilot Chat will process your question and provide an answer, with citations from your knowledge base, in the chat window.

Additional ways to access Copilot Chat

In addition to submitting prompts through the chat view, you can submit prompts in other ways:

  • Inline: To start an inline chat directly in the editor or integrated terminal, enter Command+i (Mac) / Ctrl+i (Windows/Linux).
  • Quick chat: To open the quick chat dropdown, enter Shift+Command+i (Mac) / Shift+Ctrl+i (Windows/Linux)
  • Smart actions: To submit prompts via the context menu, right click in your editor, select Copilot in the menu that appears, then select one of the actions. Smart actions can also be accessed via the sparkle icon that sometimes appears when you select a line of code.

See inline chat, quick chat, and chat smart actions in the Visual Studio Code documentation for more details.

Sharing feedback

To indicate whether a response was helpful, use the thumbs up and thumbs down icons that appear next to the response.

To leave feedback about the GitHub Copilot Chat extension, open an issue in the microsoft/vscode-copilot-release repository.

Further reading

Prerequisites

Se você tiver acesso ao GitHub Copilot por meio de sua organização ou empresa, não poderá usar o GitHub Copilot Chat se o proprietário da organização ou o administrador corporativo tiver desabilitado a conversa. Confira "Managing policies for Copilot in your organization".

Submitting prompts

You can ask Copilot Chat to give code suggestions, explain code, generate unit tests, and suggest code fixes.

  1. In the Visual Studio menu bar, click View, then click GitHub Copilot Chat.

  2. In the Copilot Chat window, enter a prompt, then press Enter. For example prompts, see "Example prompts" below.

  3. Evaluate Copilot's response, and submit a follow up prompt if needed.

    The response often includes interactive elements. For example, the response may include buttons to copy, insert, or preview the result of a code block.

    To see the files that Copilot Chat used to generate the response, select the References dropdown below the response.

Using keywords in your prompt

You can use special keywords to help Copilot understand your prompt.

Slash commands

Use slash commands to avoid writing complex prompts for common scenarios. To use a slash command, type / in the chat prompt box, followed by a command. Slash commands include:

  • /tests: Generate unit tests for the selected code
  • /fix: Propose a fix for problems in the selected code
  • /explain: Explain the selected code
  • /optimize: Analyze and improve the runtime of the selected code

To see all available slash commands, type / in the chat prompt box. See also Slash commands in the Visual Studio documentation.

References

By default, Copilot Chat will reference the file that you have open or the code that you have selected. You can also use # followed by a file name, file name and line numbers, or solution to reference a specific file, lines, or solution. For example:

  • Reference a specific file: Where are the tests in #MyFile.cs?
  • Reference multiple files: How are these files related #MyFile.cs #MyFile2.cs
  • Reference specific lines in a file: Explain this function #MyFile.cs: 66-72?
  • Reference the current file: Is there a delete method in this #solution

See also Reference in the Visual Studio documentation.

Example prompts

You can ask Copilot Chat specific questions about your project or general software questions. You can also ask Copilot Chat to write code, fix errors, write tests, and document code.

Ask general software questions

You can ask Copilot Chat general software questions. For example:

  • tell me about nodejs web server frameworks
  • how to create an express app
  • how to update an npm package

Ask questions about your project

You can ask Copilot Chat questions about your project. To give Copilot the correct context, try some of these strategies:

  • Highlight relevant lines of code
  • Open the relevant file
  • Use #file to tell Copilot to reference specific files
  • Use #solution to tell Copilot to reference the active file

For example:

  • what sorting algorithm does this function use
  • #file:gameReducer.js what happens when a new game is requested

Write code

You can ask Copilot to write code for you. For example:

  • write a function to sum all numbers in a list
  • add error handling to this function

When Copilot returns a code block, the response includes options to copy the code, insert the code into a new file, or preview the code output.

Fix, improve, and refactor code

If your active file contains an error, use the /fix slash command to ask Copilot to fix the error.

You can also make general requests to improve or refactor your code.

  • how would you improve this code?
  • translate this code to C#
  • add error handling to this function

Write tests

Use the /tests slash command to ask Copilot to write tests for the active file or selected code. For example:

  • /tests
  • /tests using the Jest framework
  • /tests ensure the function rejects an empty list

The /tests slash command writes tests for existing code. If you prefer to write tests before writing code (test driven development), omit the /tests command. For example:

  • Add tests for a JavaScript function that should sum a list of integers

Using GitHub skills for Copilot (preview)

Note

  • This feature is only available if you have a Copilot Enterprise subscription.
  • The @github chat participant is currently in preview, and only available in Visual Studio 2022 Preview 2 onwards.

Copilot has a collection of GitHub-specific skills that it can use to answer your questions. To access these skills in Copilot Chat in Visual Studio, include @github in your question.

When you add @github to a question, Copilot dynamically selects an appropriate skill, based on the content of your question. You can also explicitly ask Copilot Chat to use a particular skill. For example, @github Search the web to find the latest GPT4 model from OpenAI.

Currently available skills

You can generate a list of currently available skills by asking Copilot: @github What skills are available?

The skills you can use in Copilot Chat in Visual Studio include those shown in the table below.

SkillDescriptionEnabled by default?Example question
Code searchNatural language code search in the default branch of the Git repository. This skill is useful when you want to know where or how certain functionality has been implemented in the code. Note: the repository must be indexed - see "Asking GitHub Copilot questions in GitHub.com."Yes@github Where is the logic that controls the user session management, and how does it work?
Path searchRetrieves a specific file in the default branch of the Git repository. This skill is useful when you provide the exact path of a file in the repository.Yes@github What logic does user_auth.js encapsulate?
Show symbol definitionRetrieves the lines of code that define a specific code symbol (function, class, or struct) in the default branch of the Git repository. This skill is useful when you have the exact name of a symbol, and want to understand it.Yes@github Write unit tests for the AuthUser method
Web searchSearches the web using the Bing search engine. This skill is useful for teaching Copilot about recent events, new developments, trends, technologies, or extremely specific, detailed, or niche subjects.No (requires admin approval - see "Gerenciando políticas e recursos do Copilot em sua empresa")@github What are some recent articles about SAT tokens securing against vulnerabilities in Node?
Knowledge base searchTell Copilot Chat to answer a question within the context of a knowledge base. To initiate a knowledge base search, first enter @github, then press #, then select a knowledge base.YesEnter @github #, then choose your organization's style guide knowledge base, then ask: What is our coding convention for indentation?

Asking a question about a knowledge base (preview)

Note

  • This feature is only available if you have a Copilot Enterprise subscription.
  • Support for knowledge bases is currently in preview, and only available in Visual Studio 2022 Preview 3 onwards.

Organization owners can create knowledge bases, grouping together Markdown documentation across one or more repositories. For more information, see "Gerenciando bases de informações do Copilot."

You can tell Copilot to answer a question within the context of a knowledge base.

  1. At the bottom of the Copilot Chat window, in the Ask Copilot: Type / for commands and # to reference text box, type @github, press #, then select a knowledge base from the list.
  2. In the Type / for commands and # to reference text box, continue your message with your question, and then press Enter.
  3. Copilot Chat will process your question and provide an answer, with citations from your knowledge base, in the chat window.

Additional ways to access Copilot Chat

In addition to submitting prompts through the chat window, you can submit prompts inline. To start an inline chat, right click in your editor window and select Ask Copilot.

See Ask questions in the inline chat view in the Visual Studio documentation for more details.

Sharing feedback

To share feedback about Copilot Chat, you can use the Send feedback button in Visual Studio. For more information on providing feedback for Visual Studio, see the Visual Studio Feedback documentation.

  1. In the top right corner of the Visual Studio window, click the Send feedback button.

    Screenshot of the share feedback button in Visual Studio.

  2. Choose the option that best describes your feedback.

    • To report a bug, click Report a problem.
    • To request a feature, click Suggest a feature.

Further reading

Prerequisites

Se você tiver acesso ao GitHub Copilot por meio de sua organização ou empresa, não poderá usar o GitHub Copilot Chat se o proprietário da organização ou o administrador corporativo tiver desabilitado a conversa. Confira "Managing policies for Copilot in your organization".

Submitting prompts

You can ask Copilot Chat to give code suggestions, explain code, generate unit tests, and suggest code fixes.

  1. Open the Copilot Chat window by clicking the Copilot Chat icon at the right side of the JetBrains IDE window.

    Screenshot of the Copilot Chat icon in the Activity Bar.

  2. Enter a prompt in the prompt box. For example prompts, see "Example prompts" below.

  3. Evaluate Copilot's response, and submit a follow up prompt if needed.

    The response often includes interactive elements. For example, the response may include buttons to copy or insert a code block.

    To see the files that Copilot Chat used to generate the response, select the References dropdown below the response.

Using keywords in your prompt

You can use special keywords to help Copilot understand your prompt.

Slash commands

Use slash commands to avoid writing complex prompts for common scenarios. To use a slash command, type / in the chat prompt box, followed by a command. Slash commands include:

  • /tests: Generate unit tests for the selected code
  • /fix: Propose a fix for problems in the selected code
  • /explain: Explain the selected code
  • /help: Learn more about using Copilot Chat

To see all available slash commands, type / in the chat prompt box.

File references

By default, Copilot Chat will reference the file that you have open or the code that you have selected. You can also tell Copilot Chat which files to reference by dragging a file into the chat prompt box. Alternatively, you can right click on a file, select GitHub Copilot, then select Reference File in Chat.

Example prompts

You can ask Copilot Chat specific questions about your project or general software questions. You can also ask Copilot Chat to write code, fix errors, write tests, and document code.

Ask general software questions

You can ask Copilot Chat general software questions. For example:

  • tell me about nodejs web server frameworks
  • how to create an express app
  • how to update an npm package

Ask questions about your project

You can ask Copilot Chat questions about your project. To give Copilot the correct context, try some of these strategies:

  • Highlight relevant lines of code.
  • Open the relevant file.
  • Add the file as a reference. See File references.

For example:

  • what sorting algorithm does this function use
  • how are these files related (with references to the files in question)

Write code

You can ask Copilot to write code for you. For example:

  • write a function to sum all numbers in a list
  • add error handling to this function

When Copilot returns a code block, the response includes options to copy the code or to insert the code at your cursor.

Fix, improve, and refactor code

If your active file contains an error, use the /fix slash command to ask Copilot to fix the error.

You can also make general requests to improve or refactor your code.

  • how would you improve this code?
  • translate this code to C#
  • add error handling to this function

Write tests

Use the /tests slash command to ask Copilot to write tests for the active file or selected code. For example:

  • /tests
  • /tests using the Jest framework
  • /tests ensure the function rejects an empty list

The /tests slash command writes tests for existing code. If you prefer to write tests before writing code (test driven development), omit the /tests command. For example:

  • Add tests for a JavaScript function that should sum a list of integers

Additional ways to access Copilot Chat

In addition to submitting prompts through the chat window, you can submit built-in requests by right clicking in a file, selecting GitHub Copilot, then selecting one of the options.

Sharing feedback

To share feedback about Copilot Chat, you can use the share feedback link in JetBrains.

  1. At the right side of the JetBrains IDE window, click the Copilot Chat icon to open the Copilot Chat window.

    Screenshot of the Copilot Chat icon in the Activity Bar.

  2. At the top of the Copilot Chat window, click the share feedback link.

    Screenshot of the share feedback link in the Copilot Chat window.

Further reading