命令
一、自定义命令
在package.json
的contributes
中加入配置
"commands": [
{
"command": "good-tool.hello",
"title": "hello",
// 可选项,如果需要将命令添加到菜单则需要配置图标
"icon": {
// 浅色主题图标
"light": "./images/logo.svg",
// 深色主题图标
"dark": "./images/logo.svg"
}
}
],
二、注册命令到vscode
在extension.js
的activate
方法中进行注册
// 注册一个命令并在vscode中订阅该命令
context.subscriptions.push(vscode.commands.registerCommand('good-tool.hello', () => {
vscode.window.showInformationMessage('您执行了good-tool.hello命令!');
}));
如果将命令添加到编辑器菜单中,那么在编辑器中右击执行命令时会传入当前文件的uri
context.subscriptions.push(