Let's talk about a very exciting product that was recently launched by GitHub, which is called GitHub Copilot.
GitHub Copilot is your new AI Pair programmer, powered by OpenAI. It helps you to write utilify functions, tests, and explore new API(s) without having to lookup for answers on internet. It generates or autocomplete code for you.
It's currently not available publicly, so if you want to use it, you've to join the waiting list by visiting GitHub Copilot and head over to Sign up page.
It is already enabled on my account 🎉, so I can use it right now.
Once it is enabled, you can install it in Visual Studio Code
After installation and authenticating it with your GitHub, you'll see Copilot icon in Visual Studio Code at bottom right.
You can enable/disable Copilot by tapping this icon.
Let's start with some simple and basic utilify functions.
Suppose, I want to have a function which accepts a number as an argument and returns the double of it, here's how Copilot helps me.
Let's try with a function that finds even numbers in an array
Maybe try something related to dates?
When Copilot gives you a suggestion and you hover the mouse on last character, it gives you options to navigate between Next and Previous , Accept current suggestion or Open Copilot which shows list of all the suggestions available.
These were some simple utility functions, maybe we should give a try to use Node.js default modules, such as
Depending on the what function name you use, Copilot gives different suggestions.
Okay, enough of simple examples, let's quickly build a simple CLI based application that fetch user GitHub details (
CLI Applications start with a shebang which syntax I always forget, but now no more (Yes, Copilot also works for comments
Now let's start using copilot. The very first thing is to extract username from arguments as the user will be passing it dynamically
khattakdev is a GitHub Handle
Here's the code for extracting username from arguments
and here's the code for making an API call, since
axios is imported, so copilot suggests an axios call
Here's the whole code for CLI application, which we created in a minute using copilot.
Copilot is an awesome tool that works for creating utility functions, writing test cases, and exploring new API(s). It also works for comments and it gives you multiple suggestions.
Top comments (0)