轩哥啊哈OvO 2023-04-13 19:38 采纳率: 90%
浏览 1045
已结题

VSCode扩展开发,上下文菜单无法展开二级菜单,问题出在哪里?

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"
            }
          ]
        }
      ]
    }
  }

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 4月21日
    • 修改了问题 4月15日
    • 专家修改了标签 4月15日
    • 创建了问题 4月13日

    悬赏问题

    • ¥20 有偿:在ubuntu上安装arduino以及其常用库文件。
    • ¥15 请问用arcgis处理一些数据和图形,通常里面有一个根据点划泰森多边形的命令,直接划的弊端是只能执行一个完整的边界,但是我们有时候会用到需要在有很多边界内利用点来执行划泰森多边形的命令
    • ¥30 在wave2foam中执行setWaveField时遇到了如下的浮点异常问题,请问该如何解决呢?
    • ¥20 看图片)删除这个自动化录屏脚本就一直报错找不到脚本文件,如何解决?(相关搜索:bat文件)
    • ¥750 关于一道数论方面的问题,求解答!(关键词-数学方法)
    • ¥200 csgo2的viewmatrix值是否还有别的获取方式
    • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
    • ¥15 请把下列每一行代码完整地读懂并注释出来
    • ¥15 pycharm运行main文件,显示没有conda环境
    • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件