Introduction
- Get to know GitHub Copilot in VS Code and be productive IMMEDIATELY • Visual Studio Code 📺
Prompting
- Use cases:
- Authoring code:
- Start with a detailed comment at the top of the file, describing the purpose of the file, the libraries you want to use, the high-level inputs/outputs, including examples
- Add additional comments for each function
- Generating unit tests for existing code
- Copilot is great at generating comprehensive unit tests
- Generating comments to document existing code
- Generating dictionaries with lookup data
- provide an example or two and it will suggest how to continue with the list
- Generating regular expressions
- Explaining code:
- Need to update code written in a language you’re less familiar with? Highlight it and ask Copilot Chat to explain what it’s doing
- Authoring code:
- Work in reverse • Visual Studio Code 📺
- Try coding in reverse order by calling the functions and variables you wish existed and then prompting Copilot to define those for you now that it sees how you plan to use them
- Prompting Copilot • Visual Studio Code 📺
- Provide context by…
- opening all relevant files
- clearly defining your preferences via comments
- pasting an example (e.g. example code from a specific version of a library) to show Copilot the code style and syntax you’re looking for
- Provide context by…
- VS Code Tips — Incrementally accepting Copilot suggestions • Visual Studio Code 📺
VS Code shortcuts
ctrl-enter
: open the completions panel (all suggestions) in a split (try using this more often)opt-[]
: navigate through suggestions (improve this)ctrl-/
: accept the suggestion under your cursor
Copilot chat
- Use cases:
- Explaining a codebase (e.g. one you just inherited) with
/explain
or@workspace
- e.g.
@workspace /explain what does this block/file/directory/codebase do?
- e.g.
- Making messy code more tidy
- e.g. “Can you refactor and decompose this code into functions?”
- to reduce misunderstandings, try refactoring one function at a time
- Making fragile code more rubust
- Adding type hints
- Documenting code with
/doc
- e.g. adding comments, docstrings
- Debugging a block of code with a problem
- Answer specific how-to-code questions (e.g. a language feature, a coding concept, a function’s behavior)
- Translate code from one language to another
- e.g. converting bash to python
- Explaining a codebase (e.g. one you just inherited) with
- Open inline with
cmd-i
- Open in side panel with
cmd-ctrl-i
(if more space or a longer conversation would be helpful) - Use slash commands:
/new
= advice (only) about how to scaffold new code@workspace /new
= create a new project based on your description
@workspace /newNotebook
= create a new Jupyter notebook that does what you want@workspace /fix
= propose a fix for bugs in the selected code/tests
= generate tests for the selected code- e.g.
/tests generate unit tests with pytest
- e.g.
/doc
= add documentation (e.g. comments) to the selected code block- e.g.
/doc add google style docstrings
- e.g.
@workspace
= agent that has access to your project files (useful when asking for explanations of more project code that you could select)@workspace /explain
= explain what the selected code is doing- e.g.
@workspace how is login implemented in this project?
@terminal
= agent that provides terminal commands to accomplish your task@vscode
= agent that tells you how to configure/use VS Code the way you want to- context commands with
#
:- e.g.
#file:README.md
how do I run this?
- e.g.
- VS Code Speech extension:
- Amazing!
- I’m using
c-v
to toggle copilot’s listening mode - Much faster than typing a question when spelling is unlikely to be a problem (e.g. with project/library specific naming)
- Resources:
- Use GitHub Copilot to enhance your coding with AI • Visual Studio Code Docs 📚
- #Copilot Explains - Ep 4: Understanding Linked Lists • Nice demonstration of using Copilot Chat to learn and code a new concept • Scott Hanselman 📺
Other Copilot features
- code by commenting
- comments starting with “q:” will be answered with an “a:”
- open copilot preview sidebar with ctrl+enter while GitHub is making a suggestion to view all solution options (is there also a keyboard shortcut for cycling inline suggestions?)
Copilot X features
- copilot sidebar in vs code
- use your codebase as primary context
- highlight code block you want to prompt about (e.g. “write unit tests…”)
- coding by voice in vs code
- saying declarative things (”convert to JSON”) rather than imperative word-by-word transcriptions of what to write
- copilot for docs
- copilot in PR description box
- copilot in terminal
- declaratively describe what you want it to do and it will do it for you (e.g. using the right UNIX tools)
Links:
- Get Started with the Future of Coding: GitHub Copilot • Visual Studio Code 📺
Links:
- Use GitHub Copilot to enhance your coding with AI • VS Code Docs 📚
- GitHub Copilot X: The AI-powered developer experience - The GitHub Blog • GitHub Copilot is evolving to bring chat and voice interfaces, support pull requests, answer questions, and adopt OpenAI’s GPT-4. 📖
- Game over… GitHub Copilot X announced • Fireship 📺
- Can you use ChatGPT in VS Code?? • Visual Studio Code provides a hands-on look at the new GitHub Copilot Chat features in VS Code. 📺
GitHub Copilot CLI
- GitHub Copilot CLI: AI for the Command-Line • Elijah Manor 📺
- GitHub Copilot CLI: First Look • Vishwas Gopinas explains how with natural language processing and contextual awareness, GitHub Copilot CLI can translate your requests into shell commands, Git commands, or GitHub CLI commands, allowing you to bypass the need for memorizing arcane commands and flags. 📖
Inbox
- How I used GitHub Copilot to build a browser extension • GitHub 📖
- vs code: use
option-[]
to cycle through all inline suggestions - Beyond Chat: Unveiling the New Features in VS Code & GitHub Copilot - a great, quick video walkthrough of all the features of Copilot Chat in VS Code (as of fall 2023)
- Copilot Explains: Exceptions - 10 min demo of using copilot chat to learn about a python exception and how to handle it so the program won’t crash when the error occurs
- New Copilot Features Marathon - quick video demoing some new copilot features as of Dec 2023
- chat: example of using copilot to learn how to handle a python exception: https://www.youtube.com/watch?v=jMjxBo0sDKk