Picture3
Productivity hint: Use Ctrl-Enter (Cmd-Enter) instead of just Enter after typing your message, and the @workspace string will be inserted into your message automatically before sending.
Be precise in setting the context using chat variables
In many cases, considering the full solution as the context for your question or request (by using @workspace) is overkill. You might want to point to specific files or even parts of the files in your message. Chat variables can help! Use # to call one from this list:
-
#file: Points to a specific file in your workspace.
-
#codebase: All content of the open workspace. It’s similar to using @workspace and might be useful when you chat with another agent (like @terminal) but still want to reference the full solution.
-
#editor: Source code in the editor’s viewport (visible part).
-
#git: Current git repository: branch, remotes, path, etc.
-
#selection: The currently selected code.
-
#terminalLastCommand: Last run command in the editor’s terminal.
-
#terminalSelection: Selection in the editor's terminal.
Example: Let’s get help on improving method names in a specific file (and we want to ensure that the whole content of the file is taken into consideration).
Picture4
Productivity hint: Use the up and down keyboard arrows to pick the chat variable you need after typing #. In the case of #file, use keyboard navigation again to pick one of the suggested files.
Call the most often used actions quickly with slash commands
Chatting with your code using natural language is fun, but having the option to call often-used actions using handy shortcuts is even better. Compare typing the full message "Explain how selected code works" versus typing "/", then using keyboard arrows to pick /explain from the popup overlay. Another benefit of using the predefined syntax for commands is the confidence that GitHub Copilot understands our intent 100% correctly (natural language might have some ambiguity). There are a bunch of slash commands available. You can use them in conjunction with referencing the chat participant to provide the desired scope. Some of the commands are:
-
/help: Help about available slash commands, chat participants, chat variables, and more.
-
/doc: Generate documentation for the code.
-
/explain: Explain how the code works (or get help with terminal commands if you prepend @terminal).
-
/fix: Optimize and/or fix issues in the code.
-
/tests: Create unit tests for the code.
-
/new: Scaffold a new workspace.
Example: Let’s get an explanation for one of the regular expressions in our code. Select the code line and use the slash command "
/explain.
Picture5
Productivity hint: Try GitHub Copilot Chat in inline mode instead of having the chat always open in the side pane. Press Ctrl-I (Cmd-I) and type your message in the small overlay dialog that appears right above the line where your cursor is in the code window.
Summary
Use chat participants, chat variables, and slash commands to maintain full control over the conversation context, ensure correct and consistent understanding of your intentions, and ultimately chat and code faster!
Start your free GitHub Copilot trial here: https://aka.ms/try-github-copilot
References