VS Code 扩展 - 以编程方式查找键绑定 [英] VS Code extension - programmatically find keybindings
问题描述
在编写 vscode 扩展程序时...是否有一种编程方式来查找提供的命令的键绑定?
When programming a vscode extension... Is there a programmatic way to find the keybinding for a provided command?
我希望能够查看用户是否已更新命令的默认键映射,以便 UI 可以显示最新的绑定.(如果没有,查找默认绑定)
I would like to be able to see if a user has updated the key mapping from default for a command so that the UI can display the up-to-date binding. (and if not, look up the default binding)
以下是我目前研究过的 API:
Here are the APIs I've looked into so far:
vscode.workspace.getConfiguration()
- 我无法确定如何访问keybindings.json
文件/执行查找.
vscode.workspace.getConfiguration()
- I cannot determine how to access thekeybindings.json
file / perform a lookup.
vscode.extensions.getExtension(name/id)
允许访问 package.json
,但不允许访问命令或键绑定覆盖.
vscode.extensions.getExtension(name/id)
allows access to the package.json
, but not the command or keybinding override.
vscode.getCommands
也不提供对键绑定值的访问...
vscode.getCommands
does not provide access to the keybinding values either...
推荐答案
您可以使用 NodeJS 从 keybindings.json 文件中获取键绑定值.
You can get keybinding values from the keybindings.json file using NodeJS.
不同系统上的keybindings.json路径:
keybindings.json path on diferrent systems:
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} 获取环境变量.
To build the path you'll need to get Environment variables using process.env.{variableName}.
例如对于 MacOS,它将是:
For example for MacOS it'll be:
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
//...
});
这篇关于VS Code 扩展 - 以编程方式查找键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!