GitHub Copilot — Primer Part 1

Augmented Code Generation with Modern Tools

Graham Waters

--

GitHub Copilot is a new AI-powered code completion tool designed to help developers write code more efficiently. It is now available as a plugin for VS Code, which can be easily integrated into your existing coding workflow.

Photo by Rubaitul Azad on Unsplash

Supplying the following as a comment will automatically produce the function shown in Figure 1 with Copilot.

This function takes a string as its input, and reverses 
the order of the characters in the string.
then it removes all the letters that are in prime positions
in the string such as the first, third, fifth, etc.
an example: "hello" would become "hllo" because...
the first letter is in position 0, which is not considered a
prime, so it is kept.
the second letter is in position 1, which is not prime, so it is kept.
the third letter is in position 2, which is prime, so it is removed.
the fourth letter is in position 3, which is not prime, so it is kept.
the fifth letter is in position 4, which is prime, so it is removed.
the result is "hllo".
The function returns the resulting string.

One of the key features of GitHub Copilot is its ability to understand the context of your code. This means it can suggest more accurate and relevant code completions, reducing the need for you to switch between different tabs or search through documentation.

For example, if you are working on a function that takes an object as an argument, Copilot will suggest methods and properties that are specific to that object rather than showing you a generic list of options.

Figure 1. Autogenerated Function with Copilot.

Another helpful feature of Copilot is its ability to understand the relationships between different parts of your code. It can suggest ways to refactor your code to make it more readable and maintainable or suggest functions that might be helpful based on the code you have written.

You must first install the plugin from the VS Code marketplace to use GitHub Copilot in VS Code. Once it is installed, you can activate it by pressing Ctrl+Space or clicking on the lightbulb icon in the status bar. You can start typing, and Copilot will suggest code completions for you.

Figure 2. Using Auto DocString Generation Plugin to create a boilerplate docstring for the function.

You can customize the settings for GitHub Copilot by going to the settings editor and searching for “copilot.” There are various options available copilot.maxSuggestions etc., to tweak it to your personal preferences.

Figure 3. The grey portion of the docstring is a live suggestion from Copilot.

Summary

Use it!

--

--