问题描述
这里是 Vscode 菜鸟,尝试在编辑器上下文菜单中获取保存项。我已经做到了:
{
"name": "vsContextSave","displayName": "vsContextSave","description": "add save item to editor context menu","version": "0.0.0","publisher": "njamescouk","repository": {
"type": "git","url": ""
},"license": "MIT License","engines": {
"vscode": "^1.40.0"
},"contributes": {
"menus": {
"editor/context": [
{
"command": "workbench.action.files.save","group": "9_cutcopypaste","when": "editorTextFocus"
}
]
}
},"__Metadata": {}
}
当包含在 .vscode\extensions 目录中的目录中时,vscode 会看到它,并且 vsContextSave 会显示在扩展列表中并被启用。但是我在上下文菜单中没有看到保存项目。
编辑:
我在元数据语句之前插入了一个激活事件,但显然我需要一个带有 activate() 函数的主模块。
"activation Events": ["onStartupFinished"],
解决方法
这两个文件可让您在编辑器中查找、查找文件并另存为上下文菜单项。
extension.js:
不知道这是做什么的,但似乎是必要的
'use strict';
Object.defineProperty(exports,"__esModule",{ value: true });
const vscode = require("vscode");
function activate(context) {
};
package.json:
{
"name": "mainContext","displayName": "mainContext","description": "add various items to editor context menu","version": "0.0.0","publisher": "njamescouk","repository": {
"type": "git","url": ""
},"license": "MIT License","engines": {
"vscode": "^1.40.0"
},"main": "./extension.js","contributes": {
"menus": {
"editor/context": [
{
"command": "workbench.action.files.save","group": "9_cutcopypaste","when": "editorTextFocus"
},{
"command": "actions.find",{
"command": "workbench.action.quickOpen","when": "editorTextFocus"
}
]
},"commands": [
{
"title": "Save","command": "workbench.action.files.save"
},{
"title": "Find","command": "actions.find"
},{
"title": "Find file","command": "workbench.action.quickOpen"
}
]
},"activationEvents": [
"onStartupFinished"
],"__metadata": {}
}