forked from hashicorp/terraform-ls
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Code Action Resolution (hashicorp#680)
* Fix Code Action Resolution This fixes several parts of the code action handler workflow. - Remove `source` as it is a base type and not a specific action we can use. - Remove `source.fixAll` because the action implies fixing errors, but terraform fmt only formats code style. - Remove `source.formatAll` to allow fine grained selection of actions. - Rename `source.formatAll.terraform-ls` to `source.formatAll.terraform` to follow existing Code Action conventions. - Correctly set the code action value in the returned `lsp.CodeAction` response to the one chosen by the user. - Exit early so as to not format a document without an explicit request. When additional code actions are added, we can modify this to return a merged list of actions to apply. - Documents Code Actions, their kinds, and general workflow Co-authored-by: Radek Simko <radek.simko@gmail.com>
- Loading branch information
1 parent
36e5387
commit 48fadde
Showing
6 changed files
with
324 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Code Actions | ||
|
||
The Terraform Language Server implements a set of Code Actions which perform different actions on the current document. These commands are typically code fixes to either refactor code, fix problems or to beautify/refactor code. | ||
|
||
## Available Actions | ||
|
||
### `source.formatAll.terraform` | ||
|
||
The server will format a given document according to Terraform formatting conventions. | ||
|
||
|
||
## Usage | ||
|
||
### VS Code | ||
|
||
To enable the format code action globally, set `source.formatAll.terraform` to *true* for the `editor.codeActionsOnSave` setting and set `editor.formatOnSave` to *false*. | ||
|
||
```json | ||
"editor.formatOnSave": false, | ||
"editor.codeActionsOnSave": { | ||
"source.formatAll.terraform": true | ||
}, | ||
"[terraform]": { | ||
"editor.defaultFormatter": "hashicorp.terraform", | ||
} | ||
``` | ||
|
||
> *Important:* Disable `editor.formatOnSave` if you are using `source.formatAll.terraform` in `editor.codeActionsOnSave`. The `source.formatAll.terraform` code action is is meant to be used instead of `editor.formatOnSave`, as it provides a [guarantee of order of execution](https://github.com/microsoft/vscode-docs/blob/71643d75d942e2c32cfd781c2b5322521775fb4a/release-notes/v1_44.md#explicit-ordering-for-editorcodeactionsonsave) based on the list provided. If you have both settings enabled, then your document will be formatted twice. | ||
If you would like `editor.formatOnSave` to be *true* for other extensions but *false* for the Terraform extension, you can configure your settings as follows: | ||
|
||
```json | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { | ||
"source.formatAll.terraform": true | ||
}, | ||
"[terraform]": { | ||
"editor.defaultFormatter": "hashicorp.terraform", | ||
"editor.formatOnSave": false, | ||
}, | ||
``` | ||
|
||
Alternatively, you can include all terraform related Code Actions inside the language specific setting if you prefer: | ||
|
||
```json | ||
"editor.formatOnSave": true, | ||
"[terraform]": { | ||
"editor.defaultFormatter": "hashicorp.terraform", | ||
"editor.formatOnSave": false, | ||
"editor.codeActionsOnSave": { | ||
"source.formatAll.terraform": true | ||
}, | ||
}, | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.