GitHub Copilot extracts to provide code suggestion: - Code snippets (including comments) before and after the cursor in the current file - Relevant code snippets from other open files in your editor This information is prioritized, filtered, and then added to the prompt sent to the LLM. https://github.blog/2023-05-17-how-github-copilot-is-getting-better-at-understanding-your-code/
closures and ensures Copilot has access to the most relevant context. Examples: • Type definition files (.d.ts files) used in TypeScript projects • The code being tested when writing test code, or vice-versa
the names of your symbols like variables, functions, and classes are crucial hints for GitHub Copilot. Use consistent naming conventions and avoid using different names for the same concept. Also, be sure to take advantage of Copilot’s name suggestion feature, which we’ll discuss later.
◦ Copilot may offer several options, so take a look at them all. ◦ Open the command palette and type “GitHub Copilot: Open Completions Panel” • Write Comments in Natural Language ◦ Describe the code you want. ◦ Include examples if necessary. ◦ For instance, “A function that returns ‘xx’ when given input ‘yy’” • Start Writing Code Yourself ◦ The code you start writing also provides context for Copilot.
or enterprise), you can specify files to be excluded from GitHub Copilot. Files that are excluded will: - Lose access to code completion - No longer be used as context for code completion You can exclude files regardless of whether they exist in a GitHub repo. https://docs.github.com/en/copilot/managing-copilot/managing-github-copilot-in-your-organization/setting-policies-for-copilot-in-your-organization/excluding-content-from-github-copilot
files are candidates for context. However, there are exceptions (explained later). 1. When text is selected in the editor: → The selected text is used. 2. When nothing is selected: → The text displayed in the active editor is used. 3. Specified by context variables (explained later)
by including them in your prompts, starting with the “#” symbol. Example) #file:BookDatabaseImpl.java The entire specified file is used as the context.
in the active editor. #file A specific file (a VS Code file selection UI will be displayed) #editor The currently displayed text in the active editor. #terminalLastCommand The result of the last command executed in the active terminal. #terminalSelection The currently selected text in the active terminal.
Code terminal, after displaying the diff with “git diff”, execute the following prompt: Please review the code from the following perspectives and point out any areas that need to be fixed: • Can the code be written more concisely? • Could this code cause compile or runtime errors? • Have any security bugs been introduced? #terminalLastCommand
input allows you to specify the context from the following options: - Editor Selection - Terminal Selection - Entire Codebase - Specific Symbol - Specific File
for code that will be generated in chat. While chat generates code by referencing files used as context, this feature can be used when you want to provide explicit instructions.
/tests Generates unit tests for the selected code. /doc Generates documentation comments for the selected code (inline chat only). /fix Fixes problems in the selected code. /new Generates a template for the specified workspace.
specify where to gather context from. Example) @workspace This part specifies the agent. In this example, even unopened files can be included in the context.
a group of files you want to modify, then describe the desired changes in natural language, and Copilot will make changes across those files accordingly.
receive a code review from Copilot on your current changes. Review comments will be displayed in the editor, and where possible, change suggestions will also be provided. You can choose to adopt these suggested changes.