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

Fix Code Action Resolution #680

Merged
merged 10 commits into from
Oct 28, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Radek Simko <[email protected]>
jpogran and radeksimko authored Oct 27, 2021
commit a53027b72d84bd6021caec568f6ddc0baca8d51c
16 changes: 4 additions & 12 deletions docs/code-actions.md
Original file line number Diff line number Diff line change
@@ -4,15 +4,7 @@ The Terraform Language Server implements a set of Code Actions which perform dif

## Available Actions

### User Code Actions

There are currently no Code Actions that can be invoked by the user yet.

### Automatic Code Actions

Automatic Code Actions happen when certain events are trigged, for example saving a document.

#### `source.formatAll.terraform`
### `source.formatAll.terraform`

The server will format a given document according to Terraform formatting conventions.

@@ -68,19 +60,19 @@ Alternatively, you can include all terraform related Code Actions inside the lan

A Code Action is an action that changes content in the active editor. Each Code Action is grouped into kinds that have a `command` and/or a series of `edits`. They are triggered either by the user or through events.

### Code Action Events
### Triggers

A `Code Action` can have either an `invoke` trigger or an `automatic` [CodeActionTriggerKind](https://code.visualstudio.com/api/references/vscode-api#CodeActionTriggerKind).

`Invoked` actions come from the `lightbulb` UI inside the editor, and are chosen by the user. From the User POV, it appears that the user can choose which action is invoked from the UI and *then* it is invoked. This is not true. When the `lightbulb` UI is invoked, the LS receives a request for all supported code actions it can perform. The LS then performs all actions it can perform, then returns the `edits` or `commands` each action would perform. Then, when the user selects the action from the lightbulb UI, the client applies the `edits` or executes the `command` requested.

`Automatic` actions come from events like the `editor.codeActionsOnSave` setting. These usually do not give much choice to the user, they are either on or off, as they cannot accept user input. For example, formatting a document or removing simple style errors don't prompt for user action before or during execution.

### Code Action Types
### Kinds

Each `Code Action` has a [`CodeActionKind`](https://code.visualstudio.com/api/references/vscode-api#CodeActionKind). `Code Action Kinds` are a hierarchical list of identifiers separated by `.`. For example in `refactor.extract.function`: `refactor` is the trunk, `extract` is the branch, and `function` is the leaf. The branches and leaves are the point of intended customization, you add new branches and/or leaves for each type of function you perform. In this example, a new code action that operated on variables would be called `refactor.extract.variable`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly the kind of missing docs I wish there were in LSP! 😄


### Custom Code Action Types
#### Custom Kinds

Adding new roots or branches of the hierarchy is not emphasized or really encouraged. In most cases they are meant to be concepts that can be applied generically, not specifically to a certain language. For example, extracting a value to a variable is something common to most languages. You do not need a `refactor.extract.golang.variable` to extract a variable in Go, it still makes sense to use `refactor.extract.variable` whether in Go or in PowerShell.