Skip to content

Commit 799a471

Browse files
adonovangopherbot
authored andcommitted
gopls/doc: document all of gopls' features
This CL enumerates and documents each LSP feature supported by gopls so that users can find out: - what the tool is capable of, - how to use it, - what settings affect the feature, and - whether their LSP client supports a given feature. We plan to provide Code Actions to open the relevant section of the manual, e.g. "Refactor > Describe refactorings..." To review the markdown, cherrypick this CL then run this command from x/tools: $ go run rsc.io/cmd/mdweb@latest -a localhost:9876 & open http://localhost:9876/gopls/doc/features/README.md The topic of completion is left for another day, as is support for go.mod files. Updates golang/go#54115 Change-Id: I8f7de7571bfe0355b3597487efbc0d7aae7a12d6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/583316 Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 2e239ad commit 799a471

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1822
-161
lines changed

gopls/README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@
33
[![PkgGoDev](https://pkg.go.dev/badge/golang.org/x/tools/gopls)](https://pkg.go.dev/golang.org/x/tools/gopls)
44

55
`gopls` (pronounced "Go please") is the official Go [language server] developed
6-
by the Go team. It provides IDE features to any [LSP]-compatible editor.
6+
by the Go team.
7+
It provides a wide variety of [IDE features](doc/features/README.md)
8+
to any [LSP]-compatible editor.
79

810
<!--TODO(rfindley): Add gifs here.-->
911

1012
You should not need to interact with `gopls` directly--it will be automatically
1113
integrated into your editor. The specific features and settings vary slightly
1214
by editor, so we recommend that you proceed to the
1315
[documentation for your editor](#editors) below.
16+
Also, the gopls documentation for each feature describes whether it is
17+
supported in each client editor.
1418

1519
## Editors
1620

1721
To get started with `gopls`, install an LSP plugin in your editor of choice.
1822

23+
TODO: ensure that each editor has a local page (and move these to doc/clients/$EDITOR.md).
24+
TODO: also, be more consistent about editor (e.g. Emacs) vs. client (e.g. eglot).
25+
1926
* [VS Code](https://github.com/golang/vscode-go/blob/master/README.md)
2027
* [Vim / Neovim](doc/vim.md)
2128
* [Emacs](doc/emacs.md)
@@ -137,8 +144,9 @@ If you are having issues with `gopls`, please follow the steps described in the
137144

138145
## Additional information
139146

140-
* [Features](doc/features.md)
147+
* [Index of features](doc/features/README.md)
141148
* [Command-line interface](doc/command-line.md)
149+
* [Configuration settings](doc/settings.md)
142150
* [Advanced topics](doc/advanced.md)
143151
* [Contributing to `gopls`](doc/contributing.md)
144152
* [Integrating `gopls` with an editor](doc/design/integrating.md)

gopls/doc/advanced.md

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Advanced topics
1+
# Gopls: Advanced topics
22

33
This documentation is for advanced `gopls` users, who may want to test
44
unreleased versions or try out special features.
@@ -54,27 +54,4 @@ Note that you must work inside the `GOROOT/src` subdirectory, as the `go`
5454
command does not recognize `go.work` files in a parent of `GOROOT/src`
5555
(https://go.dev/issue/59429).
5656

57-
## Working with generic code
58-
59-
Gopls has support for editing generic Go code. To enable this support, you need
60-
to **install gopls using Go 1.18 or later**. The easiest way to do this is by
61-
[installing Go 1.18+](https://go.dev/dl) and then using this Go version to
62-
install gopls:
63-
64-
```
65-
$ go install golang.org/x/tools/gopls@latest
66-
```
67-
68-
It is strongly recommended that you install the latest version of `gopls`, or
69-
the latest **unstable** version as [described above](#installing-unreleased-versions).
70-
71-
The `gopls` built with these instructions understands generic code. See the
72-
[generics tutorial](https://go.dev/doc/tutorial/generics) for more information
73-
on how to use generics in Go!
74-
75-
### Known issues
76-
77-
* [`staticcheck`](https://github.com/golang/tools/blob/master/gopls/doc/settings.md#staticcheck)
78-
on generic code is not supported yet.
79-
8057
[Go project]: https://go.googlesource.com/go

gopls/doc/analyzers.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Analyzers
1+
# Gopls: Analyzers
22

33
<!-- No Table of Contents: GitHub's Markdown renderer synthesizes it. -->
44

@@ -15,19 +15,20 @@ 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;
19-
- a number of analyzers with more substantial dependencies that prevent them from being used in `go vet`;
20-
- analyzers that augment compilation errors by suggesting quick fixes to common mistakes; and
21-
- a handful of analyzers that suggest possible style improvements.
18+
- all the usual bug-finding analyzers from the `go vet` suite (e.g. `printf`; run `go tool vet help` for the complete list);
19+
- a number of analyzers with more substantial dependencies that prevent them from being used in `go vet` (e.g. `nilness`);
20+
- analyzers that augment compilation errors by suggesting quick fixes to common mistakes (e.g. `fillreturns`); and
21+
- a handful of analyzers that suggest possible style improvements (e.g. `simplifyrange`).
2222

23-
More details about how to enable and disable analyzers can be found
24-
[here](settings.md#analyses).
23+
To enable or disable analyzers, use the [analyses](settings.md#analyses) setting.
2524

2625
In addition, gopls includes the [`staticcheck` suite](https://staticcheck.dev/docs/checks),
2726
though these analyzers are off by default.
2827
Use the [`staticcheck`](settings.md#staticcheck`) setting to enable them,
2928
and consult staticcheck's documentation for analyzer details.
3029

30+
<!-- When staticcheck=true, we currently use the {S SA ST QF} suites, sans {SA5009, SA5011} -->
31+
3132

3233
<!-- BEGIN Analyzers: DO NOT MANUALLY EDIT THIS SECTION -->
3334
<a id='appends'></a>
41.3 KB
Loading
51.4 KB
Loading
51.4 KB
Loading
63.5 KB
Loading
19.8 KB
Loading

gopls/doc/assets/documentlink.png

21.8 KB
Loading
37.1 KB
Loading
35 KB
Loading
27.9 KB
Loading
33.8 KB
Loading
11.8 KB
Loading
26.8 KB
Loading
30.8 KB
Loading
29.4 KB
Loading
33.6 KB
Loading
15.3 KB
Loading
46.6 KB
Loading
16.2 KB
Loading

gopls/doc/assets/foldingrange.png

46.8 KB
Loading

gopls/doc/assets/hover-basic.png

42.4 KB
Loading

gopls/doc/assets/hover-embed.png

27.9 KB
Loading

gopls/doc/assets/hover-linkname.png

24.8 KB
Loading
6.52 KB
Loading

gopls/doc/assets/invert-if-after.png

28.9 KB
Loading

gopls/doc/assets/invert-if-before.png

41.3 KB
Loading

gopls/doc/assets/outgoingcalls.png

156 KB
Loading
14.4 KB
Loading
25.8 KB
Loading

gopls/doc/assets/rename-conflict.png

64.6 KB
Loading

gopls/doc/assets/signature-help.png

63.9 KB
Loading

gopls/doc/codelenses.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Code Lenses
1+
# Gopls: Code lenses
22

33
A "code lens" is a command associated with a range of a source file.
44
The VS Code manual describes code lenses as
@@ -14,6 +14,13 @@ They can be enabled and disabled using the
1414
[`codelenses`](settings.md#codelenses) setting.
1515
Their features are subject to change.
1616

17+
Client support:
18+
- **VS Code**: Code Lenses appear as small text links above a line of source code.
19+
- **Emacs + eglot**: Not supported, but prototype exists at https://github.joaotavora/eglot/pull/71.
20+
- **Vim + coc.nvim**: ??
21+
- **CLI**: `gopls codelens`. For example, `gopls codelens -exec file.go:123 "run test"` runs the test at the specified line.
22+
23+
1724
<!-- This portion is generated by doc/generate from the ../internal/settings package. -->
1825
<!-- BEGIN Lenses: DO NOT MANUALLY EDIT THIS SECTION -->
1926
## `gc_details`: Toggle display of Go compiler optimization decisions

gopls/doc/command-line.md

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
# Command line
1+
# Gopls: Command-line interface
22

3-
**Note: The `gopls` command-line is still experimental and subject to change at any point.**
3+
The `gopls` command provides a number of subcommands that expose much
4+
of the server's functionality. However, the interface is currently
5+
**experimental** and **subject to change at any point.**
6+
It is not efficient, complete, flexible, or officially supported.
47

5-
`gopls` exposes some (but not all) features on the command-line. This can be useful for debugging `gopls` itself.
8+
Its primary use is as a debugging aid.
9+
For example, this command reports the location of references to the
10+
symbol at the specified file/line/column:
611

7-
<!--TODO(rstambler): Generate this file.-->
12+
```
13+
$ gopls references ./gopls/main.go:35:8
14+
Log: Loading packages...
15+
Info: Finished loading packages.
16+
/home/gopher/xtools/go/packages/gopackages/main.go:27:7-11
17+
/home/gopher/xtools/gopls/internal/cmd/integration_test.go:1062:7-11
18+
/home/gopher/xtools/gopls/internal/test/integration/bench/bench_test.go:59:8-12
19+
/home/gopher/xtools/gopls/internal/test/integration/regtest.go:140:8-12
20+
/home/gopher/xtools/gopls/main.go:35:7-11
21+
```
822

9-
Learn about available commands and flags by running `gopls help`.
10-
11-
Much of the functionality of `gopls` is available through a command line interface.
23+
See golang/go#63693 for a discussion of its future.
1224

13-
There are two main reasons for this. The first is that we do not want users to rely on separate command line tools when they wish to do some task outside of an editor. The second is that the CLI assists in debugging. It is easier to reproduce behavior via single command.
25+
Learn about available commands and flags by running `gopls help`.
1426

15-
It is not a goal of `gopls` to be a high performance command line tool. Its command line is intended for single file/package user interaction speeds, not bulk processing.
27+
Positions within files are specified as `file.go:line:column` triples,
28+
where the line and column start at 1, and columns are measured in
29+
bytes of the UTF-8 encoding.
30+
Alternatively, positions may be specified by the byte offset within
31+
the UTF-8 encoding of the file, starting from zero, for example
32+
`file.go:#1234`.
33+
(When working in non-ASCII files, beware that your editor may report a
34+
position's offset within its file using a different measure such as
35+
UTF-16 codes, Unicode code points, or graphemes).

0 commit comments

Comments
 (0)