Search code examples
visual-studio-codevscode-extensionsformatter

How to change the position of existing editor context menus in VSCode extension?


I have a vscode extension with custom formatter implemented using its formatting provider api. The 'format document' option appears in a certain position in the editor context menu once the provider is registered. Is it possible to change the location of this context menu option, i.e., move it up or down, specifically for my extension?


Solution

  • Yes, you can. You just have to play with groups and sorting of menus, as detailed in the Contribution Points documentation (https://code.visualstudio.com/api/references/contribution-points#Sorting-of-groups).

    For instance, if you define the group for your context menu item as "group": "navigation", it will be displayed on top of all items.

    Hope this helps