Accept line by line from autocompletion
Asked Answered
G

4

8

I'm using GitHub—Copilot in a VS-Code environment. Given the autocompletion feature, I want to have the possibility to only accept line by line.

For example: The autocomplete shows five lines on TAB, but I just need the first two of them.

Is there a config file or any other possibility to achieve this?

Guyton answered 13/5, 2022 at 10:33 Comment(3)
When you have something autocompleted (in light grey), either you accept it or not, but AFAIK you can't accept only one line. What I do is to start typing what is suggested (if its cool for me), and try to have a better suggestion then.Tolson
Starting with VSCode 1.74, you can now accept a suggestion word by word for the first line by using the new editor.action.inlineSuggest.acceptNextWord command. Assign the command to a shortcut key and press it as many times as needed to complete as much of the first suggested line that you want.Stodge
I believe @Cornelius Roemer has your answer, it worked perfectly for me! https://mcmap.net/q/471804/-accept-line-by-line-from-autocompletionAnthiathia
P
2

Yes, this is now possible but not yet enabled by default (at least in January 2024).

To enable line-by-line acceptance of suggestions, you need to create a custom keybinding, e.g. ctrl+shift+right_arrow, and map it to the editor.action.inlineSuggest.acceptNextLine command.

Paste this into the keybindings.json file (which you can find through the omnibox):

{
  "key": "shift+ctrl+right"    
  "command": "editor.action.inlineSuggest.acceptNextLine",
  "when": "inlineSuggestionVisible && !editorReadonly"
}

In this demo I use different keybindings shift+cmd+l for the same action:

enter image description here

Proscribe answered 15/2, 2024 at 13:19 Comment(1)
Absolutely what i was looking for. Great find, Cornelius!Anthiathia
I
1

There is "Accept next word" action. Default keybinding: ⌘→

Ireland answered 22/6, 2023 at 20:22 Comment(0)
C
0

Method 1 (Config):

  1. Go to Co-pilot extension settings.

  2. Edit advanced settings

  3. paste this in the settings.json file

  4. You must adjust based on the number of tokens. Try it out a few times to see what works best for you

    "github.copilot.advanced": {
    "length": 500
    }

Method 2 (With Intuition):

This is something I found annoying at times. Upon using it for months, I found that if you want only a line but it is showing you 5-6 lines of autocomplete, you just type something in the current line and it should only autosuggest the line you are on.

for eg, let's say you are trying to make a function that counts prime numbers. Let us say you write a comment and expect it to finish the function. Usually, when you comment, it should show you the whole function at once when you name your function or sometimes even hit enter right after the comment.

But instead, you simply name a variable called prim and it should autocomplete the rest based on its approach. It could be primes = 0 and keep on hitting enter, you should see line-by-line.

TLDR;; If you want it to complete, just "restrict" its predictions by telling it how you want it to look by just trying about your business!

Edit:

As Randolph said in the comments, now you have a setting to do this

Credit answered 23/5, 2022 at 10:27 Comment(0)
F
0

The CoPilot extension makes a request to the OpenAI completion API. (see docs for reference: https://api.openai.com/v1/completions )

These settings can be affected by tuning the github.copilot.advanced settings of Copilot.

You could try to increase the limits that are responsible for

github.copilot.advanced": {
    "inlineSuggestCount": 5,
    "length": 700,
    "listCount": 15,
    "stops": {
    }
}

These are the undocumented settings in GitHub Copilot v1.70.8099:

""github.copilot.advanced": {
    "debug.filterLogCategories":[],
    "debug.overrideEngine": "",
    "debug.overrideProxyUrl": "",
    "debug.showScores": false,
    "debug.testOverrideProxyUrl": "",
    "indentationMode": {
        "python": false,
        "javascript": false,
        "javascriptreact": false,
        "jsx": false,
        "typescript": false,
        "typescriptreact": false,
        "go": false,
        "ruby": false,
        "*": true
    },
    "inlineSuggestCount": 3,
    "length": 500,
    "listCount": 10,
    "secret_key": "",
    "stops": {
        "*": [
            "\n\n\n"
        ],
        "python": [
            "\ndef ",
            "\nclass ",
            "\nif ",
            "\n\n#"
        ]
    },
    "temperature":"",
    "top_p": 1
}

Source: Settings in GitHub Copilot v1.70.8099

Flabbergast answered 24/1, 2023 at 21:27 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.