Repository navigation
Closed as not planned
Labels
*out-of-scopePosted issue is not in scope of VS Codeapiapi-proposaleditor-code-actionsEditor inplace actions (Ctrl + .)feature-requestRequest for new features or functionality
Milestone
Description
Problem
For feature requests such as #52846 or any improved refactoring UX, VS Code needs to know all the code actions that are available for a language. Some information about available code actions is provided by CodeActionProviderMetadata but only if an extension has been activated and the provider has been registered
Proposal
To support this, we likely want a new contribution point that lets extensions statically tell us about the general classes of the code actions that they provide:
{
"contributions": {
"codeActions": [
{
"languages": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"actions": [
{
"kind": "refactor.extract.constant",
"title": "Extract constant",
"description": "Extract expression to a constant."
}
]
}
]
}
}Potential use cases for this info
- Show on the extension's contribution page Show contributed code actions in extensions view #84091
- IntelliSense for
codeActionsOnSave(c8d64b1) - IntelliSense for configuring refactors in the keybinding json editor Code action intellisense in the keybindings JSON editor #84033
- IntelliSense for configuring refactors in UI keybinding editor Allow viewing and editing commands with 'args' in the keybindings editor #84072
- Improving the refactor context menu in VS Code
Reacted by Rome Li, Justin, Greg, Alexander, Taras Novak, Gregor, Lemmingh, Avasam and Heejae Chang
Metadata
Metadata
Assignees
Labels
*out-of-scopePosted issue is not in scope of VS Codeapiapi-proposaleditor-code-actionsEditor inplace actions (Ctrl + .)feature-requestRequest for new features or functionality
Activity
mjbvz commentedon Oct 16, 2019
Add code actions contributon point
Code action intellisense in the keybindings JSON editor
mjbvz commentedon Nov 6, 2019
I have checked in a prototype of the static
codeActionscontribution point and have hooked up a few examples of how this information could be used by us, such as providing intellisense foreditor.codeActionsOnSaveand when configuring code action keybindings. I think that a static contribution point makes sense for use cases like these, although it means that extensions need to generate those static lists for us, see: microsoft/TypeScript#34859Johannes Rieken (@jrieken) brought up that not all extensions may be able to generate these lists ahead of time, such as those using Rosyln. For some use cases, we may also want to dynamically enabled/disable which code actions are shown to the user. If you are using an old TypeScript version for example, refactoring is not supported. An example of where code actions would be enabled/disabled would a improved
refactorcontext menu in the editorMy current thinking on static vs dynamic contribution points is that we likely want both:
The static info would document all possible code actions that may be available. Having this makes sense IMO when you are configuring keybindings. It also does not require activating extensions.
The dynamic info about what code actions are really available in the current file would be useful for the refactoring menu in the editor. The
CodeActionProviderMetadataapi already lets extensions provide this info to usmjbvz commentedon Nov 6, 2019
mjbvz commentedon Nov 6, 2019
Copying a few extension authors for feedback on contribution point and possible use cases
Danny Tuppeny (@DanTup) for Dart
Don Jayamanne (@DonJayamanne) for Python
Dustin Campbell (@DustinCampbell) for C#
Updat codeActions contribtions schema based on #82718 (comment)
mjbvz commentedon Nov 7, 2019
Based on trying this for JS/TS, I've added a
descriptionfield and changed the schema to the following:DonJayamanne commentedon Nov 7, 2019
Are these code actions context aware (visa a callback)?
I.e. can I have them show up in one file and not the other. Or one line and not the other?
mjbvz commentedon Nov 7, 2019
This proposal does not effect the existing
CodeActionProviderapi (which lets your extension control which actual code actions are shown to the user in the editor). The static contribution point proposed here aims to supports some of the use cases outlined above without needing to activate any extensions6 remaining items
akaroml commentedon Nov 8, 2019
While we do Java language support in VS Code, we always hoped there could be some way to fully expose all the capabilities. The problem with the dynamic way is that the options are contextual. So we constantly hear from the users asking for some refactoring features that are actually there. They just couldn't find them or figure out how to trigger them.
That's why I really like this idea of having this new contribution point, which introduces the static way of exposing all possible code actions. The extension's contribution will make it even better by showing all the options in one place. Power users would want to set hot keys to specific actions, and this will also be possible and convenient.
One feedback is still regarding discoverability. IntelliJ has this top menu entry to expose all refactoring options. It shows the full picture even when some options are not available at the moment. It would be great to have some equivalent in VS Code because refactoring is especially important for languages like Java, C#.

jrieken commentedon Nov 8, 2019
Yes, but applying the same logic how it is then better to "cache" them at compile time, e.g writing them upfront into package.json without knowing anything about the user or her/his settings nor being able to change that list? What I am suggesting is to cache them only between the time of deactivation and activation.
mjbvz commentedon Nov 9, 2019
In our existing keybindings UX, we let users configure keybindings for any command. Many of these commands are only actually enabled when the user has enabled a setting or switched their language run time, but that does not prevent users from setting up the keybinding.
I believe that is also the behavior we want when configure keybindings for code actions or refactors: I should always be able to configure a keybinding for
extract constantif we know some extension provides it. A static contribution point enables thatDanTup commentedon Apr 20, 2020
Matt Bierner (@mjbvz) what's the status of this? If I want my code actions to show up in the keybinding list, should I be statically contributing them in
package.jsonlike this, or just providing them viadocumentation(like #89388)? It's not clear ifdocumentationalso includes this?DanTup commentedon Apr 20, 2020
Strangely, although some code actions show up in the keybinding list, if I try to add my own based on the info above, I get this warning:
If I remove the array (?!), then it breaks the intellisense for the existing ones, because it throws an error trying to call
sliceon theactionsobject.DanTup commentedon Apr 20, 2020
(oh, ignoring the warning seems like the right thing - my code action then shows up! 🤨)
heejaechang commentedon Jul 25, 2022
Pylance team wants to expose all individuals
fix all code actionsto users so they can configure whichfix all code actionsrun on file save. currently there seems no way to add those individual action names ineditor.codeActionsOnSaveschema. and no way to providedefault valueforcode actions on savefor eachfix all code actions.I think that makes it very hard for users to discover each
fix all actionsand make default such assource.fixAll: truevery intrusive since updating extension without knowing that it just added newfix all code actioncan change users code unexpectedly. furthermore, in current design, it will be very hard to find out which extension actually did it.Please, provide a way to configure this by each
fix all code action providervs-code-engineering commentedon Dec 9, 2024
We closed this issue because we don't plan to address it in the foreseeable future. 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!