Is there any way to disable GitHub Copilot comment suggestions?
Asked Answered
W

4

33

I really like Copilot however its comment suggestions can be nonsensical and really distracting.

Is there any way to leave the code suggestions on but turn Copilot off whenever I'm editing/adding a comment amidst the code?

Waltman answered 3/1, 2022 at 14:36 Comment(1)
Hopefully they'll add a built-in option in the future, but I'm not optimistic.Exhilarant
S
4

Here's a workaround I figured out for how to fix the comment suggestions problem! 🚀

The basic idea is to create a keyboard shortcut that we press in order to disable the inline suggestions from popping up. So before we write a comment, we can just press the keyboard shortcut to disable suggestions, then write the comment, and then press the keyboard shortcut to enable suggestions again. It's not a perfect solution, but it works!

To do this:

  1. Install the Toggle extension.
    • (It's written by a vscode contributor and enables you to toggle settings with keyboard shortcuts. We need to do this because the Copilot extension doesn't actually provide a keyboard shortcut to disable inline suggestions.)
  2. To your keybindings file for vscode, add the keyboard shortcut snippet below. You only need to change the values for key in order to have it work. (As of the time this comment was written, github.copilot.inlineSuggest.enable is the setting we need to toggle here. If they ever change that setting name in the future you'd have to change the below snippet accordingly.)
{
    "key": "shift+cmd+c",  // set this to whatever works for you
    "command": "toggle",
    // By the way, this "when" expression was inspired from the "when" expression for Copilot
    // extension's "Trigger Inline Suggestions" keyboard shortcut.
    "when": "editorTextFocus && !editorHasSelection",
    "args": {
      // This id is just a unique name you come up with yourself
      "id": "toggleGithubCopilotInlineSuggestionsBeingEnabled",
      // The names and values of the setting you want to toggle. In this case, it's to enable/disable the
      // `github.copilot.inlineSuggest.enable` setting.
      "value": [
        {
          "github.copilot.inlineSuggest.enable": true
        },
        {
          "github.copilot.inlineSuggest.enable": false
        }
      ]
    }
},

For more info on how to setup a toggle keyboard shortcut you can look at the extension page for the Toggle extension. You can also read more info about it here.

  1. Press the keyboard shortcut you set up and notice that the corresponding setting in vscode's settings file changes in response. Cool, you're done!

Note: This will allow you to disable inline suggestions from showing up. But it won't make a current inline suggestion, that's already showing, vanish. Just press Esc in that situation if it ever comes up. Ideally, you'd disable inline suggestions ahead of time before they'll pop up. That way you'll never have to press Esc.

Scholz answered 15/2, 2022 at 7:20 Comment(2)
This is not a solutionSourdough
This is the best answer because it allows you to enable/disable copilot while working in the same file!Public
C
4

I was annoyed at this too, and failed to find a decent automated solution anywhere on the web. So, I wrote a VSCode extension that watches the TextMate scopes wherever your active selection is, and if it detects a scope that contains comment, temporarily disables Copilot's inline suggestions until your caret is anywhere without a scope that contains comment.

Or, in short, it makes Copilot get out of your way whenever you're writing a comment, and lets it do its magic everywhere else.

Hopefully you can find some use for it as well.

https://marketplace.visualstudio.com/items?itemName=disable-copilot-comment-completions.disable-copilot-comment-completions

Christy answered 20/3, 2022 at 23:48 Comment(5)
Not sure when this worked, ratings suggest it did, but after I installed the extension today, Copilot was still happily babbling nonsense when I was typing comments in javascriptBobbee
I'm guessing it also doesn't work when using VIM mode?Gilmagilman
@Bobbee if you have the time, could you try to submit a GH issue with steps to replicate? The code for the extension was written in a day and I haven’t updated it since, so I might need to rewire some things if anything’s not working. The GH repo is linked in the extension page.Christy
I added a comment to this existing issue: github.com/jamesonknutson/disable-copilot-comment-completions/…Bobbee
The problem is that you need to type "//" and then SPACE for it to activate (perhaps even waiting a few millis before pressing space). Keep your eye on "Suggestions enabled/disabled" on the bottom right. Would be good if that was fixed, but overall a very useful extension.Sourdough
S
1

Answer based on current state

I think Esc does that (hide the inline suggestions in VSCode). I use the Shift+Esc shortcut to dismiss (hide) the inline suggestions in the editor. From here, we can see that the Esc shortcut is mapped to editor.action.inlineSuggest.hide. In my keybindings.json, I have the following

// Dismiss GitHub copilot suggestions
{
    "key": "shift+escape",
    "command": "editor.action.inlineSuggest.hide",
    "when": "editorTextFocus"
}

I see @jaquinocode's answer probably has a better solution.

Shermanshermie answered 9/3, 2023 at 14:42 Comment(0)
O
0

Press ctrl+shift+p

Enter GitHub Copilot: Enable/Disable Copilot complitions

Now you can assign any keybinding you desire. I use ctrl+capsLock ctrl+capsLock.

Ous answered 26/3, 2024 at 14:47 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.