VSCode扩展开发,上下文菜单无法展开二级菜单,问题出在哪里?
extension.js:
function activate(context) {
// 显示菜单
const commandShowSubMenu = vscode.commands.registerCommand('vsmarketplace-badges.showSubMenu', () => {
// 获取当前编辑器上下文
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage('No active editor found');
return;
}
// 展开右拉下一级菜单
vscode.commands.executeCommand('editor.action.showContextMenu',
"subMenu1",
"subMenu2",
"subMenu3",
"subMenu4",
"subMenu5",
"subMenu6",
"subMenu7",
"subMenu8",
"subMenu9",
"subMenu10",
"subMenu11",
"subMenu12")
});
// 后面省略其他命令
package.json:
"main": "./src/extension",
"activationEvents": [
"onCommand:vsmarketplace-badges.showSubMenu",
"onCommand:vsmarketplace-badges.ver",
"onCommand:vsmarketplace-badges.ver-s",
"onCommand:vsmarketplace-badges.instl",
"onCommand:vsmarketplace-badges.instl-s",
"onCommand:vsmarketplace-badges.dld",
"onCommand:vsmarketplace-badges.dld-s",
"onCommand:vsmarketplace-badges.rate",
"onCommand:vsmarketplace-badges.rate-s",
"onCommand:vsmarketplace-badges.rate-st",
"onCommand:vsmarketplace-badges.trd",
"onCommand:vsmarketplace-badges.trw",
"onCommand:vsmarketplace-badges.trm"
],
"contributes": {
"snippets": [
{
"language": "html",
"path": "./snippets/html.json",
"when": "editorTextFocus"
},
{
"language": "markdown",
"path": "./snippets/markdown.json",
"when": "editorTextFocus"
}
],
"commands": [
{
"command": "vsmarketplace-badges.showSubMenu",
"title": "Show SubMenu of VSMarketplace Badges"
},
{
"command": "vsmarketplace-badges.ver",
"title": "Add Badge for Version"
},
{
"command": "vsmarketplace-badges.ver-s",
"title": "Add Badge for Version (Short)"
},
{
"command": "vsmarketplace-badges.instl",
"title": "Add Badge for Install Count"
},
{
"command": "vsmarketplace-badges.instl-s",
"title": "Add Badge for Install Count (Short)"
},
{
"command": "vsmarketplace-badges.dld",
"title": "Add Badge for Download Count"
},
{
"command": "vsmarketplace-badges.dld-s",
"title": "Add Badge for Download Count (Short)"
},
{
"command": "vsmarketplace-badges.rate",
"title": "Add Badge for Rating"
},
{
"command": "vsmarketplace-badges.rate-s",
"title": "Add Badge for Rating (Short)"
},
{
"command": "vsmarketplace-badges.rate-st",
"title": "Add Badge for Rating Stars"
},
{
"command": "vsmarketplace-badges.trd",
"title": "Add Badge for Daily Trending"
},
{
"command": "vsmarketplace-badges.trw",
"title": "Add Badge for Weekly Trending"
},
{
"command": "vsmarketplace-badges.trm",
"title": "Add Badge for Monthly Trending"
}
],
"submenus": [
{
"id": "subMenu1",
"label": "Version"
},
{
"id": "subMenu2",
"label": "Version (Short)"
},
{
"id": "subMenu3",
"label": "Install Count"
},
{
"id": "subMenu4",
"label": "Install Count (Short)"
},
{
"id": "subMenu5",
"label": "Download Count"
},
{
"id": "subMenu6",
"label": "Download Count (Short)"
},
{
"id": "subMenu7",
"label": "Rating"
},
{
"id": "subMenu8",
"label": "Rating (Short)"
},
{
"id": "subMenu9",
"label": "Rating Stars"
},
{
"id": "subMenu10",
"label": "Trending Daily"
},
{
"id": "subMenu11",
"label": "Trending Weekly"
},
{
"id": "subMenu12",
"label": "Trending Monthly"
}
],
"menus": {
"editor/context": [
{
"command": "vsmarketplace-badges.showSubMenu",
"group": "2_main",
"when": "editorTextFocus",
"submenu": [
{
"id": "subMenu1",
"command": "vsmarketplace-badges.ver",
"label": "Version"
},
{
"id": "subMenu2",
"command": "vsmarketplace-badges.ver-s",
"label": "Version (Short)"
},
{
"id": "subMenu3",
"command": "vsmarketplace-badges.instl",
"label": "Install Count"
},
{
"id": "subMenu4",
"command": "vsmarketplace-badges.instl-s",
"label": "Install Count (Short)"
},
{
"id": "subMenu5",
"command": "vsmarketplace-badges.dld",
"label": "Download Count"
},
{
"id": "subMenu6",
"command": "vsmarketplace-badges.dld-s",
"label": "Download Count (Short)"
},
{
"id": "subMenu7",
"command": "vsmarketplace-badges.rate",
"label": "Rating"
},
{
"id": "subMenu8",
"command": "vsmarketplace-badges.rate-s",
"label": "Rating (Short)"
},
{
"id": "subMenu9",
"command": "vsmarketplace-badges.rate-st",
"label": "Rating Stars"
},
{
"id": "subMenu10",
"command": "vsmarketplace-badges.trd",
"label": "Trending Daily"
},
{
"id": "subMenu11",
"command": "vsmarketplace-badges.trw",
"label": "Trending Weekly"
},
{
"id": "subMenu12",
"command": "vsmarketplace-badges.trm",
"label": "Trending Monthly"
}
]
}
]
}
}