You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow editor commands to be registered in extension code without adding to package.json #1422
The core requirement for my extensibility model is to be able to add new commands to VS Code after my extension has already loaded, without also having to add them to my package.json. This will allow my users to write new actions, analyzers, and code formatters which they could invoke using VS Code's great keybinding system.
Currently the API lets you register the ID of the command and the function to be called. If we could also get parameters for the display name and category of the command it should be enough to accomplish full dynamic command registration. As a bonus it would nice to have a parameter for registering a default key binding for the command, but it's OK if that comes later.
I realize that there's probably a reason why you'd prefer to have commands be registered in package.json rather than completely in code. My guess is that it allows the commands to be displayed before the extension is fully loaded. The dynamic commands I'd like to have wouldn't need to be displayed until the extension is fully loaded anyway, so this doesn't matter as much to me.
Thanks for considering this!
Reacted by Elena Dikareva, Fabio Spampinato, Thomas Hickman, Jens Hausdorf, Christian Brevik, Tom Rochette, L, Cosmin, Mickey Pearce, olsonpm and 22 more
I've been talking to a few people about this recently and there seems to be a real interest from users of the PowerShell extension to be able to write new VS Code commands using PowerShell. I'd like to gauge your interest in providing the capability of dynamic command registration so that I can enable this scenario.
I know that on the list of valuable things you could do post-Build, this is probably not very high. However, I think it could open the door to even more ways to extend VS Code using any language without any significant changes to the current extensibility model.
Here's a description of how it would work:
The user installs the PowerShell extension for Visual Studio Code. One day, they hear about a new PowerShell module that provides a custom formatting command for PowerShell scripts. They install this module using the PowerShell Gallery.
The next time they start Visual Studio Code, the language service scans their locally installed PowerShell modules for any that contain editor command extensions. The new script formatting extension is found and loaded. This causes a special message to be sent from the language service to the PowerShell extension in VS Code to indicate that an editor command extension was loaded.
The PowerShell extension then uses the VS Code APIs to dynamically register this new command with its ID, display name, and default key binding. If the key binding is already in use, the default key binding is ignored. The user can now see and execute the "PowerShell: My custom formatter" command in VS Code's command palette. They can also bind this command to a key combination of their choosing in keybindings.json.
When the custom command is executed, the PowerShell extension will use VS Code's APIs to gather context about the user's currently open file and the current selection or cursor position. This information is then sent with a request to the PowerShell language service to execute a custom command with the selected ID. The custom command runs its logic in PowerShell and then returns a result which contains edits to be applied to the file.
When the response is returned from the language service, the PowerShell extension will translate the desired edits to the VS Code APIs so that they're applied to the user's file buffer.
Aside from code formatting extensions, I'd also be providing general action commands (execute some task) or analysis commands (run some special linter or script checker). The standard VS Code APIs will be used for all extension capabilities.
There are two major benefits to this approach for PowerShell users:
They can write new editor commands in a language they're already comfortable with.
These same editor commands can be made available in the PowerShell ISE and any other editor where our language service (PowerShell Editor Services) is used.
Would you be willing to accept a pull request from me to enable this after the appropriate design discussion has taken place?
Yep, this is what I was going to do for now. The main 2 downsides with this approach are the reduced discoverability and inability to bind a hotkey to those commands. I'd prefer it if the extension commands could show up as top-level commands under the "PowerShell" category.
I had the idea of creating an extensions which allows you to setup commands (and bind them to hotkeys) in a more generic way. This way all the "open-in" / "open-with" / filter selected lines with shell command, ... extensions could be substituted with this generic one.
But since it is not possible to add / remove commands dynamically I did not bother implementing a prototype. I asked (#11045) whether they'd implement such functionality into vscode itself, but they declined.
Any thoughts on this? there has been multiple asks from multiple people. Please let us know if it is something that you're willing to take into the platform, or you decided to not support it.
Johannes Rieken (@jrieken)Erich Gamma (@egamma) can you please advise?
This would be useful in case of workspace commands as well, not just editor commands.
Would this be an API change you're willing to accept?
Reacted by Patrick Meinecke, Sean Corfield and Pascal Reitermann
I'm wanting to contribute to an extension for doing jscodeshift transforms on the current editor, and it would be really nice to be able to map each transform to a separate command. Then users could also assign keyboard shortcuts to each transform command.
As it stands, (and as others have mentioned) I have to use a static command that brings up a quick pick of transforms, so I can't assign a keyboard shortcut to an individual transform.
Static configuration usually leads to an awkward DSL that papers over some of the static limitations but don't fully solve the problem. (extends and env in .babelrc files, intrinsic functions in CloudFormation templates, etc.)
Reacted by L, Sune Scheuerlein-Tougaard and Sean Corfield
We closed this issue because we don't plan to address it in the foreseeable future. You can find more detailed information about our decision-making process here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.
Reacted by Leo Hanisch, Patrick Meinecke, Alexander, Georgekutty Antony, mseddon, Patrick Reader, Michael Weichert, Musa Al-hassy, Armando Andini, scott carver and 5 more
Not sure if there is any precedent for this, but it could also require explicit permission from the user for each command or batch of commands added by an extension, e.g. via a confirmation dialog.
This is a major issue blocks vscode to be a hackable editor(like emacs or vim). The editor's user (not plugin/addon author) cannot add a command to the command palette.
Thanks for making VScode! Having great traction with it for DSL design and implementation.
For extension generators such as Rascal (produces a VScode extension from a "language description") this feature would be very useful. Currently we register one LSP server that multiplexes on file extension to redirect every LSP call to the right language. Every programmable feature that is locked in package.json is therefore out of our reach. The great benefit is that we can roll experiments with new LSP servers without a second level or rebooting. That's worth a lot to our users (typically DSL engineers).
We currently have to give every new DSL-specific command a place as a "lense" instead. It would be better for our users if they can also access DSL-specific commands that are not exposed as lenses but simply in the command palette.
By the way, we have similar issues with other package.json-locked features like language-specific bracket-balancing and comment prefixes/postfixes. A programmable alternative would be great.
Activity
egamma commentedon Dec 17, 2015
Johannes Rieken (@jrieken) fyi
daviwil commentedon Dec 17, 2015
Was this meant to be closed? I couldn't find a similar issue in the backlog :)
egamma commentedon Dec 17, 2015
sorry, wrong button
daviwil commentedon Feb 12, 2016
I've been talking to a few people about this recently and there seems to be a real interest from users of the PowerShell extension to be able to write new VS Code commands using PowerShell. I'd like to gauge your interest in providing the capability of dynamic command registration so that I can enable this scenario.
I know that on the list of valuable things you could do post-Build, this is probably not very high. However, I think it could open the door to even more ways to extend VS Code using any language without any significant changes to the current extensibility model.
Here's a description of how it would work:
The user installs the PowerShell extension for Visual Studio Code. One day, they hear about a new PowerShell module that provides a custom formatting command for PowerShell scripts. They install this module using the PowerShell Gallery.
The next time they start Visual Studio Code, the language service scans their locally installed PowerShell modules for any that contain editor command extensions. The new script formatting extension is found and loaded. This causes a special message to be sent from the language service to the PowerShell extension in VS Code to indicate that an editor command extension was loaded.
The PowerShell extension then uses the VS Code APIs to dynamically register this new command with its ID, display name, and default key binding. If the key binding is already in use, the default key binding is ignored. The user can now see and execute the "PowerShell: My custom formatter" command in VS Code's command palette. They can also bind this command to a key combination of their choosing in keybindings.json.
When the custom command is executed, the PowerShell extension will use VS Code's APIs to gather context about the user's currently open file and the current selection or cursor position. This information is then sent with a request to the PowerShell language service to execute a custom command with the selected ID. The custom command runs its logic in PowerShell and then returns a result which contains edits to be applied to the file.
When the response is returned from the language service, the PowerShell extension will translate the desired edits to the VS Code APIs so that they're applied to the user's file buffer.
Aside from code formatting extensions, I'd also be providing general action commands (execute some task) or analysis commands (run some special linter or script checker). The standard VS Code APIs will be used for all extension capabilities.
There are two major benefits to this approach for PowerShell users:
Would you be willing to accept a pull request from me to enable this after the appropriate design discussion has taken place?
Thanks!
jrieken commentedon Mar 7, 2016
A workaround is to have a command that opens quick pick with a list of (dynamic) commands. Omnisharp vscode does this for project specific commands and package restore: https://github.com/OmniSharp/omnisharp-vscode/blob/master/src/features/commands.ts#L109
daviwil commentedon Mar 7, 2016
Yep, this is what I was going to do for now. The main 2 downsides with this approach are the reduced discoverability and inability to bind a hotkey to those commands. I'd prefer it if the extension commands could show up as top-level commands under the "PowerShell" category.
W4RH4WK commentedon Oct 21, 2016
I had the idea of creating an extensions which allows you to setup commands (and bind them to hotkeys) in a more generic way. This way all the "open-in" / "open-with" / filter selected lines with shell command, ... extensions could be substituted with this generic one.
But since it is not possible to add / remove commands dynamically I did not bother implementing a prototype. I asked (#11045) whether they'd implement such functionality into vscode itself, but they declined.
geddski commentedon Nov 18, 2016
I wrote an extension that could help with this. It allows you to create custom macros and bind them to hotkeys.
https://marketplace.visualstudio.com/items?itemName=geddski.macros
bcardarella commentedon Jul 1, 2017
David Wilson (@daviwil) this issue is over a year old, has there been any movement on it?
daviwil commentedon Jul 1, 2017
Brian Cardarella (@bcardarella) Not yet, but I'd love to see it get added
3 remaining items
OmarTawfik commentedon Apr 9, 2019
Any thoughts on this? there has been multiple asks from multiple people. Please let us know if it is something that you're willing to take into the platform, or you decided to not support it.
OmarTawfik commentedon Apr 29, 2019
Johannes Rieken (@jrieken) Erich Gamma (@egamma) can you please advise?
This would be useful in case of workspace commands as well, not just editor commands.
Would this be an API change you're willing to accept?
OmarTawfik commentedon May 24, 2019
Johannes Rieken (@jrieken) Erich Gamma (@egamma) can you please advise? :)
OmarTawfik commentedon May 29, 2019
Snewfie (@snewfie) is this comment intended here? Which API did you try?
SeeminglyScience commentedon May 29, 2019
Omar Tawfik (@OmarTawfik) I believe they meant to respond in SeeminglyScience/EditorServicesCommandSuite#41.
DavidGoldman commentedon Jan 10, 2020
Friendly ping, this would also be useful for source control to allow users to define their own aliases (e.g.
hg amend && hg push)jedwards1211 commentedon Jan 17, 2020
I'm wanting to contribute to an extension for doing
jscodeshifttransforms on the current editor, and it would be really nice to be able to map each transform to a separate command. Then users could also assign keyboard shortcuts to each transform command.As it stands, (and as others have mentioned) I have to use a static command that brings up a quick pick of transforms, so I can't assign a keyboard shortcut to an individual transform.
Static configuration usually leads to an awkward DSL that papers over some of the static limitations but don't fully solve the problem. (
extendsandenvin.babelrcfiles, intrinsic functions in CloudFormation templates, etc.)vscode-triage-bot commentedon Nov 3, 2020
We closed this issue because we don't plan to address it in the foreseeable future. You can find more detailed information about our decision-making process here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.
If you wonder what we are up to, please see our roadmap and issue reporting guidelines.
Thanks for your understanding and happy coding!
mrienstra commentedon Jul 15, 2023
Johannes Rieken (@jrieken), 2.7 years later, is this request still "out of scope"?
Would limiting the possibilities to mitigate abuse make it more palatable?
cybershape commentedon Jun 26, 2024
This is a major issue blocks vscode to be a hackable editor(like emacs or vim). The editor's user (not plugin/addon author) cannot add a command to the command palette.
jurgenvinju commentedon Jul 1, 2024
Thanks for making VScode! Having great traction with it for DSL design and implementation.
For extension generators such as Rascal (produces a VScode extension from a "language description") this feature would be very useful. Currently we register one LSP server that multiplexes on file extension to redirect every LSP call to the right language. Every programmable feature that is locked in package.json is therefore out of our reach. The great benefit is that we can roll experiments with new LSP servers without a second level or rebooting. That's worth a lot to our users (typically DSL engineers).
We currently have to give every new DSL-specific command a place as a "lense" instead. It would be better for our users if they can also access DSL-specific commands that are not exposed as lenses but simply in the command palette.
By the way, we have similar issues with other
package.json-locked features like language-specific bracket-balancing and comment prefixes/postfixes. A programmable alternative would be great.