Skip to content
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

Run code actions on save #42092

Closed
jrieken opened this issue Jan 24, 2018 · 2 comments · Fixed by #48086
Closed

Run code actions on save #42092

jrieken opened this issue Jan 24, 2018 · 2 comments · Fixed by #48086
Assignees
Labels
api api-proposal editor-code-actions Editor inplace actions (Ctrl + .) feature-request Request for new features or functionality on-testplan
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Jan 24, 2018

Now that we have added code action kinds we could denote them to run on save. Similar to the new command a new setting could exists, e.g. editor.onSaveCodeaction: [quickfix.cleanup, etc.]

@jrieken jrieken added feature-request Request for new features or functionality editor-code-actions Editor inplace actions (Ctrl + .) labels Jan 24, 2018
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 16, 2018

A few potential designs for this feature:

editor.onSaveCodeaction User Setting

Add a user setting that lists code action kinds that should be run on save.

Pro

  • Easily customizable by user.
  • Does not require extensions to adopt any new APIs

Con

  • The setting is not very discoverable or easy to explain.
  • What should the default value be?
  • What if java want organize imports to be run on save but typescript does not? (I know you can use "[java]": { "editor.onSaveCodeaction": [...]})

Add a new CodeAction.runOnSave property

Add a runOnSave property to the CodeAction class. Use this property to determine which code actions to run on save

Pro

  • Lets extensions fully control which actions should be run on save
  • The runOnSave property could be controlled by a more explicit setting such as "typescript.organizeImports.runOnSave": true

Con

  • Requires extension adoption
  • Could lead to lots of extension specific settings such as, "typescript.organizeImports.runOnSave": true

Other open questions

  • How do we handle multiple code actions that should be run on save? These may return conflicting edits

@jrieken
Copy link
Member Author

jrieken commented Apr 17, 2018

I think I'd prefer option 1. We could help with the discoverability by adding the predefined code action kinds to the json-schema. It's also more similar to the keybindings story we have around code actions.

@mjbvz mjbvz added this to the April 2018 milestone Apr 18, 2018
mjbvz added a commit to mjbvz/vscode that referenced this issue Apr 20, 2018
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.
mjbvz added a commit that referenced this issue Apr 20, 2018
* Add editor.codeActionsOnSave

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.

* Use  object instead of array for config option

* Adding timeout

* Fix description

* Fix relative path
@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api api-proposal editor-code-actions Editor inplace actions (Ctrl + .) feature-request Request for new features or functionality on-testplan
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants