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

Support code-action-on-save for triggering formatting #327

Closed
rchl opened this issue Dec 3, 2020 · 1 comment · Fixed by #625
Closed

Support code-action-on-save for triggering formatting #327

rchl opened this issue Dec 3, 2020 · 1 comment · Fixed by #625
Assignees
Labels
Milestone

Comments

@rchl
Copy link

rchl commented Dec 3, 2020

Current Version

0.10.0

Use-cases

Being able to format the document using the "code-action-on-save" editor feature. That feature is not really part of the spec. More an editor feature that is currently implemented by VSCode, LSP for Sublime Text, and probably others.

It works by user defining a setting like this one in the editor:

  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.organizeImports": true
  },

and the client requesting and applying such code actions from the server before saving.

Introducing a code action like source.format.terraform would allow to granularly enable "format-on-save" for that particular server rather than having to globally enable format-on-save (that utilizes formatting provider).

Attempted Solutions

It's currently possible to enable format-on-save in various editors by using its built-in format-on-save functionality that utilizes the server's documentFormattingProvider capabilities. The problem with that approach is that enabling that feature enables it for all servers and the user when running multiple servers, doesn't always want to enable it for all of them.

Proposal

Related LSP methods

The feature would utilize Code Action Request. The client makes a code action request with context.only set to source.format.terraform (for example), receives it back from the server and applies before saving the file. The code action could return a command to run (requires extra round trip) or ideally provide the edits directly.

The server capability codeActionProvider.codeActionKinds is also relevant and should be set by the server to include the source.format.terraform code action. That makes the code action available for both code-action-on-save and some context menus that editors might expose for the document.

References

@rchl rchl added the enhancement New feature or request label Dec 3, 2020
jpogran added a commit that referenced this issue Aug 18, 2021
This adds a code action to format a file based on the `editor.codeActionsOnSave` setting. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 18, 2021
This adds a code action to format a file based on the `editor.codeActionsOnSave` setting. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 18, 2021
This adds a code action to format a file based on the `editor.codeActionsOnSave` setting. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 19, 2021
This adds a code action to format a file based on the `editor.codeActionsOnSave` setting. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 19, 2021
This adds a code action to format a file based on the `editor.codeActionsOnSave` setting. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 19, 2021
This adds a code action to format a file based on the `editor.codeActionsOnSave` setting. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 20, 2021
This enables in the language server to perform one or more code actions on a range of text or a full document.

This adds a code action to format a file based on the `editor.codeActionsOnSave` setting or when a request has `source.formatAll` or `source.formatAll.terraform-ls`. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 23, 2021
This enables in the language server to perform one or more code actions on a range of text or a full document.

This adds a code action to format a file based on the `editor.codeActionsOnSave` setting or when a request has `source.formatAll` or `source.formatAll.terraform-ls`. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 23, 2021
This enables in the language server to perform one or more code actions on a range of text or a full document.

This adds a code action to format a file based on the `editor.codeActionsOnSave` setting or when a request has `source.formatAll` or `source.formatAll.terraform-ls`. This can either be a global setting or one specific to the terraform language.
jpogran added a commit that referenced this issue Aug 23, 2021
This enables in the language server to perform one or more code actions on a range of text or a full document.

This adds a code action to format a file based on the `editor.codeActionsOnSave` setting or when a request has `source.formatAll` or `source.formatAll.terraform-ls`. This can either be a global setting or one specific to the terraform language.
@radeksimko radeksimko added this to the v0.21.0 milestone Aug 23, 2021
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants