KKKelly's Blog

Snippets, cheatsheets, & musings on web development

All posts

GitHub Copilot Notes

By Kelly King
3 min read

Notes from LinkedIn Learning Copilot certificate course.

Autocomplete tips

Multiple suggestions

When you are offered ghost text for a suggestion, there are sometimes multiple options you can choose from!

GitHub Copilot multiple suggestions

You can cycle through prev and next suggestions via:

  • Option + ]
  • Option + [

This seemed to work better / more consistently for me after I hovered over the "ghost text" suggestion to get the context menu, and then selected "Always Show Toolbar."

Accepting a partial suggestion

I typically click tab to accept an entire suggestion, but also learned that you can accept one word at a time via:

  • Command + →

This is the default keyboard shortcut, but to get this one working, I had to open Keyboard Settings (via Command Palette) and clear and then retype the keys.*

Improving suggestions

There are a few tricks you can use to help Copilot give you better suggestions:

  • Descriptive function names: to help Copilot understand what you want!
  • Psuedocode comments: Add a comment with instructions for Copilot, eg.
    // Create tr with tds for name and age. Use template strings.
  • Paste reference code: In your comment, you can paste (and then later delete) relevant variables/fields to hint to Copilot
    // These are model fields: name=models.Char, amount=models.decimal,
  • Extract a variable: Pulling values into a well-named array or enum can improve places those values are referenced later

Context

By default, Copilot only uses open files for context.

  • Specific file: You can reference a particular file by typing # and the filename. Once you type #, Copilot should suggest existing files in a typeahead menu!
  • All project files: You can make Copilot consider the entire codebase by prefacing your message with @workspace.

Chat and Agent Modes

Chat mode

  • Type a / for available commands
  • Good questions to ask:
    • How can I refactor this?
    • How can I improve readability?
    • Create unit testing headers for this file
    • Ask for executable code like "How do I start a python server in my terminal", etc

Agent mode

With Agent mode, it will make changes and create files for you rather than responding as a chat conversation. It will still offer the diff for you to accept or modify or reject.


To switch to Agent mode:

  • Use the command palette: >Chat: Open Chat (Agent)
  • Commad + Shift + i also seems to work!