Write comments to automatically generate code? Copilot tasting

Time:2021-10-24

Copilot is an AI based programming aid. At present, it has been integrated into vscode. It may be integrated into more platforms and tools in the future. At present, it is still in the test stage. Official website address:https://copilot.github.com/

Support for all languages

Copilot is trained based on machine learning algorithm by using the existing public data in the network, especially the open source code on GitHub. Therefore, copilot theoretically supports all programming languages.

At present, I have tested JS and python, and the results are quite good. Examples of TS, go, py and Rb languages are officially provided.

Comments are codes

You can write comments and then write a complete program according to copilot’s tips all the way.

For example, I want to get user information according to GitHub user name. I just need to write down such a line of comments. Take JS as an example:

//Get user information according to GitHub user name

How does copilot guide you step by step to complete the full function? Let’s take a look.

Step 1:

Write comments to automatically generate code? Copilot tasting

Note: the code color under the comment is light, which is prompted by copilot. The same below, no more explanation.

Press the tab key and the light code will be filled in and prompted for the next code.

Step 2:

Write comments to automatically generate code? Copilot tasting

Press the tab key again and the overall code is generated.

Write comments to automatically generate code? Copilot tasting

There are many similar examples, waiting for you to explore.

Code completion

A very important function of IDE is code completion. Copilot enhances the completion function of IDE.

Copilot can prompt you for possible input according to your code warehouse and the world’s public code warehouse, so as to reduce the number of keystrokes, write more code in a shorter time and get more fishing time.

For example, still take JS as an example. I want to send a fetch request.


fetch('https://www.leetcode-solution.cn', {

It reminds me:

Write comments to automatically generate code? Copilot tasting

Next, according to its prompt, you can write the following code only by pressing tab without writing code.

fetch("https://leetcode-solution.cn", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    question_id: "1",
    lang: "javascript",
    code: "console.log(1)",
  }),
}).then((res) => {
  console.log(res);
});

For my warehouse function, a small part of the above code is problematic. But I just need to change it a little. Efficiency improvement is good.

How to use?

Search in the vscode plug-in Marketgithub copilot, click Install, and then follow the prompts to install.

After installation, you can experience it! Write notes? Knock the code? Press tab? The code Duang is generated at once.

summary

Copilot is an AI programming aid similar to tabnine. At present, it provides free services in the form of vscode plug-in. At present, it is in the test stage and has not been finally released. It has many exciting functions, such as automatic prompt, writing code according to comments and so on.

For more features and the latest developments, please visit the official website:https://copilot.github.com/