Github Copilot To Add Code instead Comments?
Asked Answered
T

3

29

Using github copilot, whenever it processes a comment and tab and enter is pressed it just creates the same comment over and over again.

I want it to provide code. How?

Turgot answered 5/2, 2022 at 6:17 Comment(2)
What editor are you using?Incunabula
8 things you didn’t know you could do with GitHub Copilot - The GitHub BlogCordoba
D
35

Go on new line after comment, and start typing what you want to create. In your case type def and wait a while. If not enough give the function name and wait a while again.

Dander answered 5/2, 2022 at 6:34 Comment(5)
If this works, please accept the answer, else tell us whats wrongExtinction
That isn't generating code off of the comment like their asking. I found as of today that my comments generate code like normal in VS Code, but in Jetbrains GoLand I have the same issue as @Maybe Lindow. If I recall when I was in preview this worked fine in GoLand and noticed today it doesn't. I may be recalling incorrectly though.Incunabula
Ok I played around a bit it seems atleast in go in GoLand if I do this comment style /* Create a function that adds two numbers together and returns the result. */ and hit return it works. If I do a comment like // Create a function that adds two numbers together and returns the result I get the same result as @Maybe Lindow.Incunabula
Thanks, the trick was just as you said. Write your comment about what you want GitHub Copilot to do, then move cursor to a line below it and wait, and or begin typing then wait, then the suggested code shows up. Magic!Avina
This is not working for me. Even simple things like "// write X" lead to the suggestion "// write Y" in the next line which is stupid. I wanted to implement Equals or GetHashCode but Copilot just suggested to return base.GetHashCode. Maybe this even comes from builtin Visual Studio. Github Copilot is just useless. The console mostly says "0 completions available". But it works for function creation like "add two numbers". So the easy ones nobody needs work...Christiniachristis
U
7

First Add single line comment in you visual studio code that describe code you want to be written by github copilot like // function to add two numbers in javascript then press Enter wait for little seconds code that do what you described in comment will appear then press tab. Note : in some case your code might be incomplete just keep pressing enter then tab when code look like comment.

Uganda answered 21/7, 2022 at 14:52 Comment(2)
Sometimes copilot will just repeat your comment - when this happens, see the accepted answer.Origen
not working on Intellij IDEVeloz
N
0

I had the exact same problem when I was learning Github Copilot with VS Code. Copilot was helping me complete the comment instead of generating code. I had to use "Ctrl + I" on Windows in order to open a co-pilot prompt dialog and writing the comment there. It didn't show the "Open Completion Panel" however.

Nkvd answered 14/6, 2024 at 10:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.