Code explanation using GitHub Copilot
Sometimes, you come across a piece of code and you’re not sure what it does. You may spend a lot of time trying to understand it but you may not be able to grasp it completely. In such cases, you can use GitHub Copilot to get a code explanation.
Essentially, you’ll need an existing GitHub Copilot subscription to use this feature. If you don’t have one, you can sign up for the waitlist.
Once you have a subscription, you need to install the GitHub Copilot Labs extension for VS Code. Once installed and enabled, you can select a piece of code and press Ctrl + Shift + P to open the command palette.
Then, you can use the “GitHub Copilot Labs: Focus on Explain View” to focus on the explain view of the extension.
From there on, you can press the “Ask Copilot” button to get an explanation of the code.
Here’s what it looks like.
As you can see, it explains the code in a very simple and easy-to-understand way and in a step-by-step manner which is great!
You can also change the prompt that Copilot uses to explain the code in the “Advanced” tab of the “Explain” tab.