While creating a session about Visual Studio Code extension development, I discovered that creating a submenu in the context menus is possible. These submenus are a great way to make the context menus less cluttered and easier to use.
When trying it out, I could not make it work easily as the docs were unclear. So I decided to write this article to help others who want to create a submenu in their Visual Studio Code context menus.
Creating the submenu
Creating a submenu starts with the package.json
file (extension manifest) at the root of your extension.
Add a submenu
property to the contributes
section:
|
|
Once you have added the submenu
, you can now register the submenu in the context menu:
|
|
The only thing left to do is to add the commands to the submenu:
|
|
The whole example looks as follows:
|
|
I hope this article helped you to create a submenu in your Visual Studio Code context menus. If you have any questions, feel free to leave a comment below.