microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.63k stars 29.04k forks source link

Error when editing keyboard shortcuts from the editor if the keybindings file has a trailing comma #31277

Closed greggilbert closed 6 years ago

greggilbert commented 7 years ago
Extension Author (truncated) Version
EditorConfig Edi 0.9.4
vscode-docker Pet 0.0.16
html-css-class-completion Zig 1.8.0
vscode-intelephense-client bme 0.7.2
ruby gro 0.0.6
prettify-json moh 0.0.3
vscode-duplicate mrm 1.1.0
php-docblocker nei 1.2.0
editorconfiggenerator nep 0.2.1
vetur oct 0.9.2
Ruby reb 0.12.1

Steps to Reproduce:

  1. Preferences > Keyboard Shortcuts
  2. Edit the Open Next Editor shortcut and set it to ctrl+tab
  3. Get this error: Error 'Error: Unable to write keybindings. Please open Keybindings file to correct errors/warnings in the file and try again.' while editing keybinding. Please open

Reproduces without extensions: Yes

sandy081 commented 7 years ago

@greggilbert Can you please open your keybindings.json file and check if there are any errors in that file.. you can open that file from the keybindings editor or through the global command Open Keyboard Shortcuts File

greggilbert commented 7 years ago

@sandy081 I tried clearing out my keybindings and I was able to save. The issue is that there was a trailing comma in what I had there:

// Place your key bindings in this file to overwrite the defaults
[
    { "key": "shift+cmd+left",      "command": "workbench.action.previousEditor"},
    { "key": "shift+ctrl+tab",      "command": "workbench.action.previousEditor"},
    { "key": "cmd+1",                "command": "workbench.action.openEditorAtIndex1" },
    { "key": "cmd+2",                "command": "workbench.action.openEditorAtIndex2" },
    { "key": "cmd+3",                "command": "workbench.action.openEditorAtIndex3" },
    { "key": "cmd+4",                "command": "workbench.action.openEditorAtIndex4" },
    { "key": "cmd+5",                "command": "workbench.action.openEditorAtIndex5" },
    { "key": "cmd+6",                "command": "workbench.action.openEditorAtIndex6" },
    { "key": "cmd+7",                "command": "workbench.action.openEditorAtIndex7" },
    { "key": "cmd+8",                "command": "workbench.action.openEditorAtIndex8" },
    { "key": "cmd+9",                "command": "workbench.action.openEditorAtIndex9" },
]

The keybindings file worked just fine with the final comma there, so I guess it just doesn't work when trying to add a keybinding to that sort of list?

sandy081 commented 7 years ago

@greggilbert Yes, we bail out if there are any errors in keybindings file while writing into it from keybindings editor. It's same in settings. But we ignore trailing comma which is not the case here.

Will make it resilient for trailing comma case.