admin管理员组

文章数量:1434914

UPD: Never mind I am just bad at reading sources!

I am using Colonize extension. The extension adding ; at the end of the line by hitting Shift + Enter. However when I get suggestions they get selected. I don't want this.

First thing I thought of is to check the repo issues : one person also thinks the same. Then I decided to check source code and I don't see anything that actually selects the suggestion.

I've tried to add to keybindings.json all commands to be disabled, and it works without colonize!

    {
        "key": "shift+Enter",
        "command": "-acceptSelectedSuggestion",
        "when": "true"
    },
    {
        "key": "shift+Enter",
        "command": "-acceptSelectedSuggestionOnEnter",
        "when": "true"
    },

    {
      "key": "shift+enter",
      "command": "-acceptAlternativeSelectedSuggestion",
      "when": "true"
    }

The logical next step would be to check the source code of the extension. Fortunately it is very short and it just uses editBuilder to insert semicolon. I suspect that this statement could be the issue, but after commenting this portion in js file of the extension nothing changed it terms of accepting the suggestion :

  vscodemands.executeCommand("acceptSelectedSuggestion").then(() => {
    var lineIndex = editor.selection.active.line;
    var lineObject = editor.document.lineAt(lineIndex);
    var lineLength = lineObject.text.length;

    if (
      lineObject.text.charAt(lineLength - 1) !== ";" &&
      !lineObject.isEmptyOrWhitespace
    ) {
      var insertionSuccess = editor.edit((editBuilder) => {
        editBuilder.insert(new vscode.Position(lineIndex, lineLength), ";lol"); // MOD HERE!
      });

      if (!insertionSuccess) return;
    }

    if (option === "hold") return;

    // MOD HERE !
    // option === 'endline'
    //   ? vscodemands.executeCommand('cursorEnd')
    //   : vscodemands.executeCommand('editor.action.insertLineAfter')
  });

Here is a demo gif (lol shows that I made modification):

Steps to Reproduce:

  1. Download the extension
  2. Start typing to see suggestioins
  3. Press shift + Enter
  4. Watch semicolon added and first suggestion get accepted
  Version: 1.95.3 (user setup)
  Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
  Date: 2024-11-13T14:50:04.152Z
  Electron: 32.2.1
  ElectronBuildId: 10427718
  Chromium: 128.0.6613.186
  Node.js: 20.18.0
  V8: 12.8.374.38-electron.0
  OS: Windows_NT x64 10.0.22631

UPD: Never mind I am just bad at reading sources!

I am using Colonize extension. The extension adding ; at the end of the line by hitting Shift + Enter. However when I get suggestions they get selected. I don't want this.

First thing I thought of is to check the repo issues : one person also thinks the same. Then I decided to check source code and I don't see anything that actually selects the suggestion.

I've tried to add to keybindings.json all commands to be disabled, and it works without colonize!

    {
        "key": "shift+Enter",
        "command": "-acceptSelectedSuggestion",
        "when": "true"
    },
    {
        "key": "shift+Enter",
        "command": "-acceptSelectedSuggestionOnEnter",
        "when": "true"
    },

    {
      "key": "shift+enter",
      "command": "-acceptAlternativeSelectedSuggestion",
      "when": "true"
    }

The logical next step would be to check the source code of the extension. Fortunately it is very short and it just uses editBuilder to insert semicolon. I suspect that this statement could be the issue, but after commenting this portion in js file of the extension nothing changed it terms of accepting the suggestion :

  vscodemands.executeCommand("acceptSelectedSuggestion").then(() => {
    var lineIndex = editor.selection.active.line;
    var lineObject = editor.document.lineAt(lineIndex);
    var lineLength = lineObject.text.length;

    if (
      lineObject.text.charAt(lineLength - 1) !== ";" &&
      !lineObject.isEmptyOrWhitespace
    ) {
      var insertionSuccess = editor.edit((editBuilder) => {
        editBuilder.insert(new vscode.Position(lineIndex, lineLength), ";lol"); // MOD HERE!
      });

      if (!insertionSuccess) return;
    }

    if (option === "hold") return;

    // MOD HERE !
    // option === 'endline'
    //   ? vscodemands.executeCommand('cursorEnd')
    //   : vscodemands.executeCommand('editor.action.insertLineAfter')
  });

Here is a demo gif (lol shows that I made modification):

Steps to Reproduce:

  1. Download the extension
  2. Start typing to see suggestioins
  3. Press shift + Enter
  4. Watch semicolon added and first suggestion get accepted
  Version: 1.95.3 (user setup)
  Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
  Date: 2024-11-13T14:50:04.152Z
  Electron: 32.2.1
  ElectronBuildId: 10427718
  Chromium: 128.0.6613.186
  Node.js: 20.18.0
  V8: 12.8.374.38-electron.0
  OS: Windows_NT x64 10.0.22631
Share Improve this question edited Nov 17, 2024 at 11:27 Askhento asked Nov 16, 2024 at 23:41 AskhentoAskhento 6596 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

First make sure you don't have any extensions that affect the suggestions. Try overriding the behavior of these keys directly, write in keybindings.json

{
    "key": "shift+enter",
    "command": "colonize.insertSemicolonAtEndOfLine",
    "when": "editorTextFocus"
}

You can try disabling autocompletion by writing in settings.json

"editor.acceptSuggestionOnEnter": "off"

If it's not too imperative that shift+enter is used, you can just change the binding :)

本文标签: visual studio codeVSCode editBuilder implicitly accepts suggestionsStack Overflow