| 1 |
list or execute code actions |
| 2 |
|
| 3 |
Usage: |
| 4 |
gopls [flags] codeaction [codeaction-flags] filename[:line[:col]] |
| 5 |
|
| 6 |
|
| 7 |
The codeaction command lists or executes code actions for the |
| 8 |
specified file or range of a file. Each code action contains |
| 9 |
either an edit to be directly applied to the file, or a command |
| 10 |
to be executed by the server, which may have an effect such as: |
| 11 |
- requesting that the client apply an edit; |
| 12 |
- changing the state of the server; or |
| 13 |
- requesting that the client open a document. |
| 14 |
|
| 15 |
The -kind and -title flags filter the list of actions. |
| 16 |
|
| 17 |
The -kind flag specifies a comma-separated list of LSP CodeAction kinds. |
| 18 |
Only actions of these kinds will be requested from the server. |
| 19 |
Valid kinds include: |
| 20 |
|
| 21 |
gopls.doc.features |
| 22 |
quickfix |
| 23 |
refactor |
| 24 |
refactor.extract |
| 25 |
refactor.extract.constant |
| 26 |
refactor.extract.function |
| 27 |
refactor.extract.method |
| 28 |
refactor.extract.toNewFile |
| 29 |
refactor.extract.variable |
| 30 |
refactor.inline |
| 31 |
refactor.inline.call |
| 32 |
refactor.rewrite |
| 33 |
refactor.rewrite.changeQuote |
| 34 |
refactor.rewrite.fillStruct |
| 35 |
refactor.rewrite.fillSwitch |
| 36 |
refactor.rewrite.invertIf |
| 37 |
refactor.rewrite.joinLines |
| 38 |
refactor.rewrite.removeUnusedParam |
| 39 |
refactor.rewrite.splitLines |
| 40 |
source |
| 41 |
source.assembly |
| 42 |
source.doc |
| 43 |
source.fixAll |
| 44 |
source.freesymbols |
| 45 |
source.organizeImports |
| 46 |
source.test |
| 47 |
|
| 48 |
Kinds are hierarchical, so "refactor" includes "refactor.inline". |
| 49 |
(Note: actions of kind "source.test" are not returned unless explicitly |
| 50 |
requested.) |
| 51 |
|
| 52 |
The -title flag specifies a regular expression that must match the |
| 53 |
action's title. (Ideally kinds would be specific enough that this |
| 54 |
isn't necessary; we really need to subdivide refactor.rewrite; see |
| 55 |
gopls/internal/settings/codeactionkind.go.) |
| 56 |
|
| 57 |
The -exec flag causes the first matching code action to be executed. |
| 58 |
Without the flag, the matching actions are merely listed. |
| 59 |
|
| 60 |
It is not currently possible to execute more than one action, |
| 61 |
as that requires a way to detect and resolve conflicts. |
| 62 |
TODO(adonovan): support it when golang/go#67049 is resolved. |
| 63 |
|
| 64 |
If executing an action causes the server to send a patch to the |
| 65 |
client, the usual -write, -preserve, -diff, and -list flags govern how |
| 66 |
the client deals with the patch. |
| 67 |
|
| 68 |
Example: execute the first "quick fix" in the specified file and show the diff: |
| 69 |
|
| 70 |
$ gopls codeaction -kind=quickfix -exec -diff ./gopls/main.go |
| 71 |
|
| 72 |
codeaction-flags: |
| 73 |
-d,-diff |
| 74 |
display diffs instead of edited file content |
| 75 |
-exec |
| 76 |
execute the first matching code action |
| 77 |
-kind=string |
| 78 |
comma-separated list of code action kinds to filter |
| 79 |
-l,-list |
| 80 |
display names of edited files |
| 81 |
-preserve |
| 82 |
with -write, make copies of original files |
| 83 |
-title=string |
| 84 |
regular expression to match title |
| 85 |
-w,-write |
| 86 |
write edited content to source files |