Search code examples
javascripttypescriptvisual-studio-codevscode-extensions

Why Is My SubMenu In Context Menu Not Appearing Vscode Extension


I wanted to show a submenu with menus inside it in the right click context menu and i had this setup:

"categories": [
    "Other"
  ],
  "activationEvents": [
    "onCommand:colorquick.helloWorld"
  ],
  "main": "./dist/extension.js",
  "contributes": {
    "commands": [
      {
        "command": "colorquick.helloWorld",
        "title": "Hello World"
      }
    ],
    "menus": {
      "editor/context": [
        {
          "submenu": "colorquick.submenu",
          "when": "editorTextFocus",
          "group": "navigation"
        }
      ],
      "editor/context/colorquick.submenu": [
        {
          "command": "colorquick.helloWorld",
          "group": "navigation"
        }
      ]
    },
    "submenus": [
      {
        "id": "colorquick.submenu",
        "label": "ColorQuick"
      }
    ]
  },

but it dosent come up, but if i dont use a submenu and i just put the command as a menu it comes up why is it not working; enter image description here


Solution

  • The issue is within the SubMenu definition.

    While defining the "editor/context/colorquick.submenu" node, you don't need to prepend with editor/context/. The node must be your new SubMenu name instead.

    So, your package.json should look something like this:

       "menus": {
          "editor/context": [
            {
              "submenu": "colorquick.submenu",
              "when": "editorTextFocus",
              "group": "navigation"
            }
          ],
          "colorquick.submenu": [
            {
              "command": "colorquick.helloWorld",
              "group": "navigation"
            }
          ]
        },
        "submenus": [
          {
            "id": "colorquick.submenu",
            "label": "ColorQuick"
          }
        ]