Enhance Your Coding with GitHub Copilot: AI-Powered Autocomplete, Inline Chat, and Quick Chat Commands 🥷
Learn how to harness its AI capabilities for smarter code autocompletion, contextually relevant suggestions via inline chat, and time-saving quick commands in the chat window.
GitHub Copilot is a fantastic addition to the professional software engineers toolbelt and can help with lot of common day-to-day tasks. I’ve been leveraging its capabilities heavily over the past year and I felt it makes a ton of sense to unpack this in a bit more detail.
In this blog, we’ll use GitHub Copilot to illustrate these interaction modes
Autocomplete suggestions as you type code in your IDE (Integrated development environment)
Inline chat for a specific piece of code or problem
Chat with commands and references
If you are using JetBrains IDE’s like IntelliJ or Pycharm or Visual Studio code
Please make sure to install the Github Copilot plugin or extension in your IDE of choice
Then, follow the steps to authorize them to access your GitHub account.
GitHub recently made Copilot free up to a limited set of autocomplete or chat interactions 🤩 and you can use this to play around with its capabilities 🙌.
Autocomplete ✅
I truly love this feature. ❤️
Why?
So much of writing automated tests involves writing similar code leveraging existing classes, utilities, or helper functions and assertions.
GitHub Copilot can help by helping you speed up the test authoring aspect. It autocompletes code for you as you type by displaying the suggested code in grey.
If the suggestion looks acceptable, you can press the TAB key, and that code is inserted at a given caret location. You can then edit the code to suit your specific requirements. You could also partially accept a suggestion as well.
If not, you can continue writing code and it will try to figure out what you are trying to write and suggest.
Could you make it more effective?
Yes, there are a few distinct things you can try to help Github Copilot make better suggestions. Let’s go over them next
Open relevant files
GitHub Copilot gives preference to what files you have open at the time that you are trying to write a piece of code. It also has context of your workspace but providing targeted reference to correct files would increase the chances of getting a more relevant autocompletion.
This makes logical sense since you would probably not have unnecessary files open when working on a codebase anyway.
Here are a few common use cases
If you are trying to write a new test that follows a given pattern that is already repeated in another file, having that file open would help Copilot suggest better autocompletes.
If you are writing assertions on a given test method and want to reuse existing methods then having the assertions file open would allow Copilot to suggest relevant suggestions for better