21

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?

Gustavo Maximo
  • 4,426
  • 3
  • 17
  • 26
  • 1
    Hopefully [they'll add a built-in option in the future](https://github.com/community/community/discussions/8062), but I'm not optimistic. – Ian Dunn Mar 09 '23 at 18:43

3 Answers3

3

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.

jaquinocode
  • 634
  • 7
  • 12
2

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

Robert Longson
  • 118,664
  • 26
  • 252
  • 242
JamesK
  • 106
  • 4
  • 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 javascript – Hinton Mar 29 '23 at 08:23
  • I'm guessing it also doesn't work when using VIM mode? – AntonOfTheWoods Mar 30 '23 at 01:38
  • @Hinton 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. – JamesK Mar 30 '23 at 07:27
  • I added a comment to this existing issue: https://github.com/jamesonknutson/disable-copilot-comment-completions/issues/4 – Hinton Mar 31 '23 at 11:24
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.

Avneesh Mishra
  • 518
  • 4
  • 9