-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add editor.codeActionsOnSave #48086
Add editor.codeActionsOnSave #48086
Conversation
480042b
to
0602636
Compare
/** | ||
* Code action kinds to be run on save. | ||
*/ | ||
codeActionsOnSave?: string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be an object literal because that enables merging/overwriting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Yes an object is much nicer to work with
|
||
private async applyCodeActions(actionsToRun: CodeAction[], editor: ICodeEditor) { | ||
for (const action of actionsToRun) { | ||
await applyCodeAction(action, this._textModelService, this._fileService, this._commandService, editor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like - running them one after the other is the sane thing to do IMO
) { } | ||
|
||
async participate(editorModel: ITextFileEditorModel, env: { reason: SaveReason }): Promise<void> { | ||
if (env.reason === SaveReason.AUTO) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add timeout and make it configurable, like editor.formatOnSaveTimeout
In the format-case we only pick one provider (the last that got registered). That makes applying formatting edits simpler but there is a strong desire to change that, e.g. run them sequentially. If formatting or code actions undo/destroy the work of a pre-running operation that's tough luck. I'd make sure tho to maintain a somewhat stable order, e.g sort them by provider
I'd say off by default
Unsure, extension authors might now start to use source for everything but also fair to start like this. We should document this well, e.g. should source be used for something like 'insert missing semi-colons'? |
0602636
to
e320939
Compare
Ok, I've switched the config to an object and added a timeout, and posted answers/thoughts to many of my original questions |
Fixes microsoft#42092 Adds a way to run code actions on save using the `editor.codeActionsOnSave` setting. This setting lists code action kinds to be executed automatically when the document is saved.
e320939
to
0ae090c
Compare
Is there a way to use this setting to convert indentation to spaces automatically on save? I tried adding "editor.codeActionsOnSave": {
"editor.action.indentationToSpaces": true
} to my settings and it didn't do anything, because
|
@GammaGames Do you have an extension that contributes a |
This feature is only about code actions, not commands. The command names make this a little confusing but they are not code actions (but extensions can convert commands to code actions very easily) |
Oooh, my bad! Thank you! |
Fixes #42092
Adds a way to run code actions on save using the
editor.codeActionsOnSave
setting. This setting lists code action kinds to be executed automatically when the document is saved.TODO / Questions:
source.
code actions? (This is what it is doing currently actually) A: yes i still think this makes the most sense. We pass the entire document range when requesting these code actions. We can relax this restriction if it causes problems for extension authors