Skip to content

Commit 70a59b2

Browse files
adonovangopherbot
authored andcommitted
gopls/doc: respond to Hana's review of CL 583316
Also: - contributor notes on keeping docs up to date; - add "Added in v0.17" on "Extract to new file". - various other fixes and tweaks. Change-Id: I23666654a55190e99109b11cc65ca175a77de65e Reviewed-on: https://go-review.googlesource.com/c/tools/+/595835 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Alan Donovan <adonovan@google.com>
1 parent 799a471 commit 70a59b2

10 files changed

+87
-68
lines changed

gopls/doc/advanced.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To get a specific version of `gopls` (for example, to test a prerelease
99
version), run:
1010

1111
```sh
12-
GO111MODULE=on go install golang.org/x/tools/gopls@vX.Y.Z
12+
$ go install golang.org/x/tools/gopls@vX.Y.Z
1313
```
1414

1515
Where `vX.Y.Z` is the desired version.

gopls/doc/analyzers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ before you run your tests, or even before you save your files.
1515
This document describes the suite of analyzers available in gopls,
1616
which aggregates analyzers from a variety of sources:
1717

18-
- all the usual bug-finding analyzers from the `go vet` suite (e.g. `printf`; run `go tool vet help` for the complete list);
18+
- all the usual bug-finding analyzers from the `go vet` suite (e.g. `printf`; see [`go tool vet help`](https://pkg.go.dev/cmd/vet) for the complete list);
1919
- a number of analyzers with more substantial dependencies that prevent them from being used in `go vet` (e.g. `nilness`);
2020
- analyzers that augment compilation errors by suggesting quick fixes to common mistakes (e.g. `fillreturns`); and
2121
- a handful of analyzers that suggest possible style improvements (e.g. `simplifyrange`).

gopls/doc/contributing.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,17 @@ telemetry.-->
165165

166166
[issue-gopls]: https://github.com/golang/go/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3Agopls "gopls issues"
167167
[issue-wanted]: https://github.com/golang/go/issues?utf8=✓&q=is%3Aissue+is%3Aopen+label%3Agopls+label%3A"help+wanted" "help wanted"
168+
169+
## Documentation
170+
171+
Each CL that adds or changes a feature should include, in addition to
172+
a test that exercises the new behavior:
173+
174+
- a **release note** that briefly explains the change, and
175+
- **comprehensive documentation** in the [index of features](features/README.md).
176+
177+
The release note should go in the file named for the forthcoming
178+
release, for example [release/v0.16.0.md](release/v0.16.0.md). (Create
179+
the file if your feature is the first to be added after a release.)
180+
181+

gopls/doc/features/README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,35 @@ briefly mention whether each feature is supported in other popular
2121
clients, and if so, how to find it. We welcome contributions, edits,
2222
and updates from users of any editor.
2323

24+
Contributors should [update this documentation](../contributing.md#documentation)
25+
when making significant changes to existing features or when adding new ones.
26+
2427
- [Passive](passive.md): features that are always on and require no special action
25-
- [Hover](passive.md#Hover): information about the symbol under the cursor
26-
- [SignatureHelp](passive.md#SignatureHelp): type information about the enclosing function call
27-
- [DocumentHighlight](passive.md#DocumentHighlight): highlight identifiers referring to the same symbol
28-
- [InlayHint](passive.md#InlayHint): show implicit names of struct fields and parameter names
29-
- [SemanticTokens](passive.md#SemanticTokens): report syntax information used by editors to color the text
30-
- [FoldingRange](passive.md#FoldingRange): report text regions that can be "folded" (expanded/collapsed) in an editor
31-
- [DocumentLink](passive.md#DocumentLink): extracts URLs from doc comments, strings in current file so client can linkify
28+
- [Hover](passive.md#hover): information about the symbol under the cursor
29+
- [Signature Help](passive.md#signature-help): type information about the enclosing function call
30+
- [Document Highlight](passive.md#document-highlight): highlight identifiers referring to the same symbol
31+
- [Inlay Hint](passive.md#inlay-hint): show implicit names of struct fields and parameter names
32+
- [Semantic Tokens](passive.md#semantic-tokens): report syntax information used by editors to color the text
33+
- [Folding Range](passive.md#folding-range): report text regions that can be "folded" (expanded/collapsed) in an editor
34+
- [Document Link](passive.md#document-link): extracts URLs from doc comments, strings in current file so client can linkify
3235
- [Diagnostics](diagnostics.md): compile errors and static analysis findings
33-
- TODO: expand subindex
3436
- [Navigation](navigation.md): navigation of cross-references, types, and symbols
35-
- [Definition](navigation.md#Definition): go to definition of selected symbol
36-
- [TypeDefinition](navigation.md#TypeDefinition): go to definition of type of selected symbol
37-
- [References](navigation.md#References): list references to selected symbol
38-
- [Implementation](navigation.md#Implementation): show "implements" relationships of selected type
39-
- [DocumentSymbol](passive.md#DocumentSymbol): outline of symbols defined in current file
40-
- [Symbol](navigation.md#Symbol): fuzzy search for symbol by name
41-
- [SelectionRange](navigation.md#SelectionRange): select enclosing unit of syntax
42-
- [CallHierarchy](navigation.md#CallHierarchy): show outgoing/incoming calls to the current function
37+
- [Definition](navigation.md#definition): go to definition of selected symbol
38+
- [Type Definition](navigation.md#type-definition): go to definition of type of selected symbol
39+
- [References](navigation.md#references): list references to selected symbol
40+
- [Implementation](navigation.md#implementation): show "implements" relationships of selected type
41+
- [Document Symbol](passive.md#document-symbol): outline of symbols defined in current file
42+
- [Symbol](navigation.md#symbol): fuzzy search for symbol by name
43+
- [Selection Range](navigation.md#selection-range): select enclosing unit of syntax
44+
- [Call Hierarchy](navigation.md#call-hierarchy): show outgoing/incoming calls to the current function
4345
- [Completion](completion.md): context-aware completion of identifiers, statements
4446
- [Code transformation](transformation.md): fixes and refactorings
45-
- [Formatting](transformation.md#Formatting): format the source code
46-
- [Rename](transformation.md#Rename): rename a symbol or package
47-
- [Organize imports](transformation.md#OrganizeImports): organize the import declaration
48-
- [Extract](transformation.md#Extract): extract selection to a new file/function/variable
49-
- [Inline](transformation.md#Inline): inline a call to a function or method
50-
- [Miscellaneous rewrites](transformation.md#Rewrite): various Go-specific refactorings
47+
- [Formatting](transformation.md#formatting): format the source code
48+
- [Rename](transformation.md#rename): rename a symbol or package
49+
- [Organize imports](transformation.md#organize-imports): organize the import declaration
50+
- [Extract](transformation.md#extract): extract selection to a new file/function/variable
51+
- [Inline](transformation.md#inline): inline a call to a function or method
52+
- [Miscellaneous rewrites](transformation.md#miscellaneous-rewrites): various Go-specific refactorings
5153
- [Web-based queries](web.md): commands that open a browser page
5254
- [Package documentation](web.md#doc): browse documentation for current Go package
5355
- [Free symbols](web.md#freesymbols): show symbols used by a selected block of code

gopls/doc/features/diagnostics.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ diagnostics and sends them to the client using the LSP
88
notification, giving you real-time feedback that reduces the cost of
99
common mistakes.
1010

11-
Diagnostics come from two main sources: build errors and analysis findings.
11+
Diagnostics come from two main sources: compilation errors and analysis findings.
1212

13-
- **Build errors** are those that you would obtain from running `go
13+
- **Compilation errors** are those that you would obtain from running `go
1414
build`. Gopls doesn't actually run the compiler; that would be too
1515
slow. Instead it runs `go list` (when needed) to compute the
16-
metadata of the build, then processes those packages in a similar
16+
metadata of the compilation, then processes those packages in a similar
1717
manner to the compiler front-end: reading, scanning, and parsing the
1818
source files, then type-checking them. Each of these steps can
1919
produce errors that gopls will surface as a diagnostic.
@@ -54,13 +54,14 @@ Diagnostics come from two main sources: build errors and analysis findings.
5454
Diagnostics are automatically recomputed each time the source files
5555
are edited.
5656

57-
Build errors are updated immediately after each file is edited,
58-
potentially after every keystroke. This ensures rapid feedback of
59-
syntax and type errors while editing.
57+
Compilation errors in open files are updated after a very short delay
58+
(tens of milliseconds) after each file change, potentially after every keystroke.
59+
This ensures rapid feedback of syntax and type errors while editing.
60+
61+
Compilation and analysis diagnostics for the whole workspace are much
62+
more expensive to compute, so they are usually recomputed after a
63+
short idle period (around 1s) following an edit.
6064

61-
Analysis diagnostics can be more expensive to compute than type
62-
checking, so they are usually recomputed after a short idle period
63-
following an edit.
6465
The [`diagnosticsDelay`](../settings.md#diagnosticsDelay) setting determines
6566
this period.
6667
Alternatively, diagnostics may be triggered only after an edited file
@@ -78,7 +79,7 @@ ways to fix the problem by editing the code.
7879
For example, when a `return` statement has too few operands,
7980
the [`fillreturns`](../analyzers.md#fillreturns) analyzer
8081
suggests a fix that heuristically fills in the missing ones
81-
with suitable values. Applying the fix eliminates the build error.
82+
with suitable values. Applying the fix eliminates the compilation error.
8283

8384
![An analyzer diagnostic with two alternative fixes](../assets/remove-unusedparam-before.png)
8485

@@ -104,9 +105,9 @@ Settings:
104105
the base URI for Go package links in the Diagnostic.CodeDescription field.
105106

106107
Client support:
107-
- **VS Code**: Diagnostics appear as a red squiggly underline.
108+
- **VS Code**: Diagnostics appear as a squiggly underline.
108109
Hovering reveals the details, along with any suggested fixes.
109-
- **Emacs + eglot**: Diagnostics appear as a red squiggly underline.
110+
- **Emacs + eglot**: Diagnostics appear as a squiggly underline.
110111
Hovering reveals the details. Use `M-x eglot-code-action-quickfix`
111112
to apply available fixes; it will prompt if there are more than one.
112113
- **Vim + coc.nvim**: ??
@@ -118,7 +119,7 @@ dorky details and deletia:
118119
119120
- The **vet suite**, of about thirty analyzers
120121
designed to catch likely mistakes in your code.
121-
122+
122123
- **Type-error fixers**. These are gopls-specific analyzers that
123124
enrich diagnostics from the type checker by suggesting fixes for
124125
simple problems.

gopls/doc/features/navigation.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A definition query also works in these unexpected places:
1717
- On a symbol in a **[`go:linkname` directive](https://pkg.go.dev/cmd/compile)**,
1818
it returns the location of that symbol's declaration.
1919
- On a **[doc link](https://tip.golang.org/doc/comment#doclinks)**, it returns
20-
(like [`hover`](passive.md#Hover)) the location of the linked symbol.
20+
(like [`hover`](passive.md#hover)) the location of the linked symbol.
2121
- On a file name in a **[`go:embed` directive](https://pkg.go.dev/embed)**,
2222
it returns the location of the embedded file.
2323

@@ -40,7 +40,7 @@ request returns the locations of all identifiers that refers to the symbol under
4040
The references algorithm handles various parts of syntax as follows:
4141

4242
- The references to a **symbol** report all uses of that symbol.
43-
In the case of exported this may include locations in other packages.
43+
In the case of exported symbols this may include locations in other packages.
4444
- The references to a **package declaration** are all the
4545
direct imports of the package, along with all the other package
4646
declarations in the same package.
@@ -112,7 +112,7 @@ Client support:
112112
- **CLI**: `gopls implementation file.go:#offset`
113113

114114

115-
## TypeDefinition
115+
## Type Definition
116116

117117
The LSP
118118
[`textDocument/typeDefinition`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_typeDefinition)
@@ -141,17 +141,17 @@ Client support:
141141
- **Vim + coc.nvim**: ??
142142
- **CLI**: not supported
143143

144-
## DocumentSymbol
144+
## Document Symbol
145145

146146
The `textDocument/documentSymbol` LSP query reports the list of
147147
top-level declarations in this file. Clients may use this information
148148
to present an overview of the file, and an index for faster navigation.
149149

150-
Gopls responds with the newer
150+
Gopls responds with the
151151
[`DocumentSymbol`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification#documentSymbol)
152152
type if the client indicates
153153
[`hierarchicalDocumentSymbolSupport`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification#documentSymbolClientCapabilities);
154-
otherwise it returns the older
154+
otherwise it returns a
155155
[`SymbolInformation`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification#symbolInformation).
156156

157157
Client support:
@@ -182,7 +182,7 @@ It also supports the following special characters within queries:
182182
| `$` | `printf$` | exact suffix |
183183
184184
However, VS Code does its own fuzzy matching afterward, so these
185-
aren't effective in that client.
185+
aren't effective in that client; see golang/vscode-go#647.
186186
-->
187187

188188
TODO: screenshot
@@ -200,7 +200,7 @@ Client support:
200200
- **CLI**: `gopls links file.go`
201201

202202

203-
## SelectionRange
203+
## Selection Range
204204

205205
The
206206
[`textDocument/selectionRange`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification#textDocument_selectionRange)
@@ -215,7 +215,7 @@ Client support:
215215
- **Vim + coc.nvim**: ??
216216
- **CLI**: not supported
217217

218-
## CallHierarchy
218+
## Call Hierarchy
219219

220220
The LSP CallHierarchy mechanism consists of three queries that
221221
together enable clients to present a hierarchical view of a portion of

gopls/doc/features/passive.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ plus any methods promoted from embedded fields.
2727

2828
**Doc links**: A doc comment may refer to another symbol using square
2929
brackets, for example `[fmt.Printf]`. Hovering over one of these
30-
[doc links](https://tip.golang.org/doc/comment#doclinks) reveals
30+
[doc links](https://go.dev/doc/comment#doclinks) reveals
3131
information about the referenced symbol.
3232

3333
<img src='../assets/hover-doclink.png'>
@@ -71,6 +71,9 @@ Hovering over the directive shows information about the other symbol.
7171

7272
<img src='../assets/hover-linkname.png'>
7373

74+
The hover information for symbols from the standard library added
75+
after Go 1.0 states the Go release that added the symbol.
76+
7477
Settings:
7578
- The [`hoverKind`](../settings.md#hoverKind) setting controls the verbosity of documentation.
7679
- The [`linkTarget`](../settings.md#linkTarget) setting specifies
@@ -91,7 +94,7 @@ Client support:
9194
- **CLI**: `gopls definition file.go:#start-#end` includes information from a Hover query.
9295

9396

94-
## SignatureHelp
97+
## Signature Help
9598

9699
The LSP [`textDocument/signatureHelp`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_signatureHelp)
97100
query returns information about the innermost function call enclosing
@@ -105,13 +108,15 @@ function call.
105108
<img src='../assets/signature-help.png'>
106109

107110
Client support:
108-
- **VS Code**: enabled by default. Displays signature and doc comment alongside Hover information.
111+
- **VS Code**: enabled by default.
112+
Also known as "[parameter hints](https://code.visualstudio.com/api/references/vscode-api#SignatureHelpProvider)" in the [IntelliSense settings](https://code.visualstudio.com/docs/editor/intellisense#_settings).
113+
Displays signature and doc comment alongside Hover information.
109114
- **Emacs + eglot**: enabled by default. Displays signature in the echo area.
110115
- **Vim + coc.nvim**: ??
111116
- **CLI**: `gopls signature file.go:#start-#end`
112117

113118

114-
## DocumentHighlight
119+
## Document Highlight
115120

116121
The LSP [`textDocument/documentHighlight`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentHighlight)
117122
query reports a set of source ranges that should be highlighted based
@@ -140,7 +145,7 @@ Client support:
140145
- **CLI**: `gopls signature file.go:#start-#end`
141146

142147

143-
## InlayHint
148+
## Inlay Hint
144149

145150
The LSP [`textDocument/inlayHint`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint)
146151
query returns a set of annotations to be spliced into the current file
@@ -189,7 +194,7 @@ Client support:
189194
- **Vim + coc.nvim**: ??
190195
- **CLI**: not supported
191196

192-
## SemanticTokens
197+
## Semantic Tokens
193198

194199
The LSP [`textDocument/semanticTokens`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_semanticTokens)
195200
query reports information about all the tokens in the current file, or
@@ -220,7 +225,7 @@ Client Support:
220225
For internal details of gopls' implementation of semantic tokens,
221226
see [semantic tokens](../semantictokens.md).
222227

223-
## FoldingRange
228+
## Folding Range
224229

225230
The LSP [`textDocument/foldingRange`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_foldingRange)
226231
query reports the list of regions in the current file that may be
@@ -240,7 +245,7 @@ Client support:
240245
- **Vim + coc.nvim**: ??
241246
- **CLI**: `gopls folding_ranges file.go`
242247

243-
## DocumentLink
248+
## Document Link
244249

245250
The LSP [`textDocument/documentLink`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentLink)
246251
query uses heuristics to extracts URLs from doc comments and string

gopls/doc/features/transformation.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Code transformations are not a single category in the LSP:
1313
<!-- Generate, RegenerateCgo (Go); Tidy, UpgradeDependency, Vendor (go.mod) -->
1414
- most are defined as *code actions*.
1515

16-
<a id='code-actions'></a>
1716
## Code Actions
1817

1918
A **code action** is an action associated with a portion of the file.
@@ -241,10 +240,11 @@ in the latter half of this 2015 GothamGo talk:
241240
Client support:
242241
- **VS Code**: Use "[Rename symbol](https://code.visualstudio.com/docs/editor/editingevolved#_rename-symbol)" menu item (`F2`).
243242
- **Emacs + eglot**: Use `M-x eglot-rename`, or `M-x go-rename` from [go-mode](https://github.com/dominikh/go-mode.el).
243+
- **Vim + coc.nvim**: Use the `coc-rename` command.
244244
- **CLI**: `gopls rename file.go:#offset newname`
245245

246246

247-
<a id='Extract'></a>
247+
<a name='extract'></a>
248248
## Extract function/method/variable
249249

250250
The `refactor.extract` family of code actions all return commands that
@@ -296,9 +296,6 @@ The following Extract features are planned for 2024 but not yet supported:
296296

297297
- **Extract constant** is a variant of "Extract variable" to be
298298
offered when the expression is constant; see golang/go#37170.
299-
- **Extract to new file** will extract one or more top-level
300-
declarations into a new file in the same package; see golang/go#65707.
301-
<!-- TODO(adonovan): update when https://go.dev/cl/565895 lands. -->
302299
- **Extract parameter struct** will replace two or more parameters of a
303300
function by a struct type with one field per parameter; see golang/go#65552.
304301
<!-- TODO(adonovan): review and land https://go.dev/cl/563235. -->
@@ -308,9 +305,11 @@ The following Extract features are planned for 2024 but not yet supported:
308305
see golang/go#65721 and golang/go#46665.
309306

310307

311-
<a id='extract-to-new-file'></a>
308+
<a name='extract-to-new-file'></a>
312309
## Extract declarations to new file
313310

311+
(Available from gopls/v0.17.0)
312+
314313
If you select one or more top-level declarations, gopls will offer an
315314
"Extract declarations to new file" code action that moves the selected
316315
declarations into a new file whose name is based on the first declared
@@ -323,7 +322,7 @@ Import declarations are created as needed.
323322
![After: the new file is based on the first symbol name](../assets/extract-to-new-file-after.png)
324323

325324

326-
<a id='Inline'></a>
325+
<a name='inline'></a>
327326
## Inline call to function
328327

329328
For a `codeActions` request where the selection is (or is within) a
@@ -478,7 +477,6 @@ more detail. All of this is to say, it's a complex problem, and we aim
478477
for correctness first of all. We've already implemented a number of
479478
important "tidiness optimizations" and we expect more to follow.
480479

481-
<a id='Rewrite'></a>
482480
## Miscellaneous rewrites
483481

484482
This section covers a number of transformations that are accessible as
@@ -487,7 +485,6 @@ code actions of kind `refactor.rewrite`.
487485
<!-- See TODO comments in settings/codeactionkind.go about splitting
488486
up "refactor.extract" into finer grained categories. -->
489487

490-
<a id='remove-unused-parameter'></a>
491488
### Remove unused parameter
492489

493490
The [`unusedparams` analyzer](../analyzers.md#unusedparams) reports a

0 commit comments

Comments
 (0)