【问题标题】:VS Code extension - programmatically find keybindingsVS Code 扩展 - 以编程方式查找键绑定
【发布时间】:2016-11-18 16:41:27
【问题描述】:

在编写 vscode 扩展时... 是否有一种编程方式来查找提供的命令的键绑定?

我希望能够查看用户是否更新了命令的默认键映射,以便 UI 可以显示最新的绑定。 (如果没有,请查找默认绑定)

以下是我目前研究过的 API:

  • vscode.workspace.getConfiguration() - 我无法确定如何访问keybindings.json 文件/执行查找。

  • vscode.extensions.getExtension(name/id) 允许访问 package.json,但不允许命令或键绑定覆盖。

  • vscode.getCommands 也不提供对键绑定值的访问...

【问题讨论】:

    标签: visual-studio-code key-bindings vscode-extensions


    【解决方案1】:

    您可以使用 NodeJS 从 keybindings.json 文件中获取键绑定值。

    不同系统上的keybindings.json路径:

    Windows: %APPDATA%\Code\User\keybindings.json
    Mac: $HOME/Library/Application Support/Code/User/keybindings.json
    Linux: $HOME/.config/Code/User/keybindings.json
    

    要构建路径,您需要使用 process.env.{variableName} 获取环境变量。

    例如对于 MacOS,它将是:

    var process = require('process');
    //...
    var keybindingsPath = process.env.HOME + "/Library/Application Support/Code/User/keybindings.json";
    
    vscode.workspace.openTextDocument(keybindingsPath).then((document) => {
        let text = document.getText();
        //then use this JSON file for your needs
        //...
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 2017-11-28
    • 1970-01-01
    相关资源
    最近更新 更多