🔨

Using GitHub Copilot with VSCode

2022/06/16に公開約3,800字

日本語

Thoughts ahead

Great to use.
Once you use it, you can't get away from it.

Postscript

GitHub Copilot is now in full release.
This article was written during the beta version, so corrections have been made throughout.

How to use

Sign up for GitHub Copilot at Sign up on the following page (free)

https://copilot.github.com/

You will have to wait for a long time after registering.
In my case, I waited 3~4 months.

Free for the first 60 days, paid thereafter.
($10/month, $100/year.)

You may think it's expensive, but when you read this article, you may be thinking.
"Are you sure you just want to pay $10?"
You may think.
Also, if you are a student or a contributor to OSS, you can use the service for free.

Good and great points

Summarizes the code for you

I want to explain the code

I want GitHub Copilot to explain what this code is doing!

I need you to explain the processing flow of the code

Next, I'll ask GitHub Copilot to explain the code, focusing on the flow of the code process!

It converts the code to another language

I suddenly feel like porting the code I just wrote to Ruby and Python, so I'll have it translated.

Python

Ruby

It is well translated.
It is great that GitHub Copilot understands the default values.

It works surprisingly well without any comments

Example

The following code is generated by itself with just def average or func average.

def average(data):
    return sum(data) / len(data)
func average(data []float64) float64 {
    return sum(data) / float64(len(data))
}

Predict even from variable names

The example below only has input_age input.

input_age = input("Enter your age: ")

Easy to read

The output is in light text, so it is easy to read.

Multiple answers

If there is more than one answer, as shown in the image below, you can select one!

Really understand what the code means

In the code below, all I typed in was def average and print("The average is.
The rest is all automatic.

def average(data):
    return sum(data) / len(data)

print("The average is", average([1, 2, 3, 4, 5]))

If you type in a sequence of numbers, it will guess the rest of the sequence

python only def prime_number
go and typescript only func and const respectively

def prime_number(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True
func prime_number(n int) bool {
    for i := 2; i < n; i++ {
        if n % i == 0 {
            return false
        }
    }
    return true
}
const prime_number = (n: number) => {
    for (let i = 2; i < n; i++) {
        if (n % i === 0) {
            return false
        }
    }
    return true
}

Other examples

I have only written the name of the language except for the first sentence.

Proguraming Language Comment List

Python: #
Go: //
TypeScript: //
JavaScript: //
Java: //
C: //
C++: //
C#: //
PHP: //
Ruby: #
Haskell: //

Unsettling points

  • Licensing issues
  • Is the code correct?
  • Conflicts with code completion.
  • etc...

It's not an official release yet, so it's not surprising that there are some complaints.

Summary

Use at your own risk, but you get a partner like Esper.
Development speed will increase (maybe).

I have a blog.

https://amemiya-riya-blog.oshaburikitchin.com/

Translated with DeepL.

https://www.deepl.com/translator
GitHubで編集を提案

Discussion

ログインするとコメントできます