Skip to content

Commit f6a2390

Browse files
committed
gopls/doc: delete commands.md
This change deletes the public documentation of gopls' command set, which is an internal implementation detail. Adventurous users can read the source of command.Interface. Also, delete the Commands portion of the JSON API, which is not used. Change-Id: Ib2e2e8fcee880805c6556ee40fcbe1891712af5a Reviewed-on: https://go-review.googlesource.com/c/tools/+/597276 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 2154cbf commit f6a2390

File tree

11 files changed

+44
-1410
lines changed

11 files changed

+44
-1410
lines changed

Diff for: gopls/doc/commands.md

-965
This file was deleted.

Diff for: gopls/doc/features/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ when making significant changes to existing features or when adding new ones.
5858
- [Template files](templates.md): files parsed by `text/template` and `html/template`
5959
- [go.mod and go.work files](modfiles.md): Go module and workspace manifests
6060
- [Command-line interface](../command-line.md): CLI for debugging and scripting (unstable)
61-
- [Non-standard commands](../commands.md): gopls-specific RPC protocol extensions (unstable)
6261

6362
You can find this page from within your editor by executing the
6463
`gopls.doc.features` [code action](transformation.md#code-actions),

Diff for: gopls/doc/features/transformation.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ formatting, simplifications), code repair (fixes), and editing support
66
(filling in struct literals and switch statements).
77

88
Code transformations are not a single category in the LSP:
9-
- a few, such as Formatting and Rename, are primary operations in the
10-
protocol;
11-
- some are [commands](../commands.md) exposed through [Code
12-
Lenses](../codelenses.md) (though none of these are transformations of Go syntax);
9+
- A few, such as Formatting and Rename, are primary operations in the
10+
protocol.
11+
- Some transformations are exposed through [Code Lenses](../codelenses.md),
12+
which return _commands_, arbitrary server
13+
operations invoked for their side effects through a
14+
[`workspace/executeCommand`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_executeCommand) request;
15+
however, no current code lenses are transformations of Go syntax.
1316
<!-- Generate, RegenerateCgo (Go); Tidy, UpgradeDependency, Vendor (go.mod) -->
14-
- most are defined as *code actions*.
17+
- Most transformations are defined as *code actions*.
1518

1619
## Code Actions
1720

@@ -27,9 +30,8 @@ A `codeAction` request delivers the menu, so to speak, but it does
2730
not order the meal. Once the user chooses an action, one of two things happens.
2831
In trivial cases, the action itself contains an edit that the
2932
client can directly apply to the file.
30-
But in most cases, the action contains a [command](../commands.md)
31-
to be sent back to the server for its side effects,
32-
just as with the command associated with a Code Lens.
33+
But in most cases the action contains a command,
34+
similar to the command associated with a code lens.
3335
This allows the work of computing the patch to be done lazily, only
3436
when actually needed. (Most aren't.)
3537
The server may then compute the edit and send the client a

Diff for: gopls/doc/features/web.md

+17-18
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ your source code has been modified but not saved.
4949
like your editor to raise its window when handling this event.)
5050

5151
<a name='doc'></a>
52-
## View package documentation
52+
## Browse package documentation
5353

5454
In any Go source file, a code action request returns a command to
55-
"View package documentation". This command opens a browser window
55+
"Browse package documentation". This command opens a browser window
5656
showing the documentation for the current Go package, presented using
5757
a similar design to https://pkg.go.dev.
5858

@@ -61,21 +61,21 @@ internal ones that may be unpublished externally. Reloading the page
6161
updates the documentation to reflect your changes. It is not necessary
6262
to save modified Go source files.
6363

64-
<img title="View package documentation" src="../assets/browse-pkg-doc.png" width='80%'>
64+
<img title="Browse package documentation" src="../assets/browse-pkg-doc.png" width='80%'>
6565

6666
Clicking on the link for a package-level symbol or method, which in
6767
`pkg.go.dev` would ordinarily take you to a source-code viewer such as
6868
GitHub or Google Code Search, causes your editor to navigate to the
6969
relevant source file and line.
7070

7171
Client support:
72-
- **VS Code**: Use the "Source Action... > View package documentation" menu.
72+
- **VS Code**: Use the "Source Action... > Browse documentation for package P" menu.
7373
- **Emacs + eglot**: Use `M-x go-browse-doc` in [go-mode](https://github.com/dominikh/go-mode.el).
7474
- **Vim + coc.nvim**: ??
7575

7676

7777
<a name='freesymbols'></a>
78-
## View free symbols
78+
## Browse free symbols
7979

8080
When studying code, either to understand it or to evaluate a different
8181
organization or factoring, it is common to need to know what the
@@ -84,14 +84,14 @@ considering extracting it into its own function and want to know what
8484
parameters it would take, or just to understand how one piece of a long
8585
function relates to the preceding pieces.
8686

87-
If you select a chunk of code, and apply the "[View free
88-
symbols](../commands.md#gopls.free_symbols)" command, your editor will
87+
If you select a chunk of code, and invoke the "Browse free symbols"
88+
[code action](transformation.md#code-actions), your editor will
8989
open a browser displaying a report on the free symbols of the
9090
selection. A symbol is "free" if it is referenced from within the
9191
selection but defined outside of it. In essence, these are the inputs
9292
to the selected chunk.
9393

94-
<img title="View free symbols" src="../assets/browse-free-symbols.png" width='80%'>
94+
<img title="Browse free symbols" src="../assets/browse-free-symbols.png" width='80%'>
9595

9696
The report classifies the symbols into imported, local, and
9797
package-level symbols. The imported symbols are grouped by package,
@@ -102,23 +102,22 @@ editor to navigate to its declaration.
102102
TODO: explain dotted paths.
103103

104104
Client support:
105-
- **VS Code**: Use the "Source Action... > View free symbols" menu.
105+
- **VS Code**: Use the "Source Action... > Browse free symbols" menu.
106106
- **Emacs + eglot**: Use `M-x go-browse-freesymbols` in [go-mode](https://github.com/dominikh/go-mode.el).
107107
- **Vim + coc.nvim**: ??
108108

109109

110110
<a name='assembly'></a>
111-
## View assembly
111+
## Browsse assembly
112112

113113
When you're optimizing the performance of your code or investigating
114114
an unexpected crash, it may sometimes be helpful to inspect the
115115
assembly code produced by the compiler for a given Go function.
116116

117-
If you position the cursor or selection within a function f, a code
118-
action will offer the "[View assembly for
119-
f](../commands.md#gopls.assembly)" command. This opens a web-based
120-
listing of the assembly for the function, plus any functions nested
121-
within it.
117+
If you position the cursor or selection within a function f,
118+
gopls offers the "Browse assembly for f" [code action](transformation.md#code-actions).
119+
This opens a web-based listing of the assembly for the function, plus
120+
any functions nested within it.
122121

123122
Each time you edit your source and reload the page, the current
124123
package is recompiled and the listing is updated. It is not necessary
@@ -134,19 +133,19 @@ Each instruction is displayed with a link that causes your editor to
134133
navigate to the source line responsible for the instruction, according
135134
to the debug information.
136135

137-
<img title="View assembly" src="../assets/browse-assembly.png" width="80%">
136+
<img title="Browse assembly" src="../assets/browse-assembly.png" width="80%">
138137

139138
The example above shows the arm64 assembly listing of
140139
[`time.NewTimer`](https://pkg.go.dev/time#NewTimer).
141140
Observe that the indicated instruction links to a source location
142141
inside a different function, `syncTimer`, because the compiler
143142
inlined the call from `NewTimer` to `syncTimer`.
144143

145-
Viewing assembly is not yet supported for generic functions, package
144+
Browsing assembly is not yet supported for generic functions, package
146145
initializers (`func init`), or functions in test packages.
147146
(Contributions welcome!)
148147

149148
Client support:
150-
- **VS Code**: Use the "Source Action... > View GOARCH assembly for f" menu.
149+
- **VS Code**: Use the "Source Action... > Browse GOARCH assembly for f" menu.
151150
- **Emacs + eglot**: Use `M-x go-browse-assembly` in [go-mode](https://github.com/dominikh/go-mode.el).
152151
- **Vim + coc.nvim**: ??

Diff for: gopls/doc/generate/generate.go

-102
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// The generate command updates the following files of documentation:
66
//
77
// gopls/doc/settings.md -- from linking gopls/internal/settings.DefaultOptions
8-
// gopls/doc/commands.md -- from loading gopls/internal/protocol/command
98
// gopls/doc/analyzers.md -- from linking gopls/internal/settings.DefaultAnalyzers
109
// gopls/doc/inlayHints.md -- from loading gopls/internal/settings.InlayHint
1110
// gopls/internal/doc/api.json -- all of the above in a single value, for 'gopls api-json'
@@ -41,7 +40,6 @@ import (
4140
"golang.org/x/tools/gopls/internal/doc"
4241
"golang.org/x/tools/gopls/internal/golang"
4342
"golang.org/x/tools/gopls/internal/mod"
44-
"golang.org/x/tools/gopls/internal/protocol/command/commandmeta"
4543
"golang.org/x/tools/gopls/internal/settings"
4644
"golang.org/x/tools/gopls/internal/util/maps"
4745
"golang.org/x/tools/gopls/internal/util/safetoken"
@@ -88,7 +86,6 @@ func doMain(write bool) (bool, error) {
8886
{"internal/doc/api.json", rewriteAPI},
8987
{"doc/settings.md", rewriteSettings},
9088
{"doc/codelenses.md", rewriteCodeLenses},
91-
{"doc/commands.md", rewriteCommands},
9289
{"doc/analyzers.md", rewriteAnalyzers},
9390
{"doc/inlayHints.md", rewriteInlayHints},
9491
} {
@@ -150,10 +147,6 @@ func loadAPI() (*doc.API, error) {
150147
Analyzers: loadAnalyzers(settings.DefaultAnalyzers), // no staticcheck analyzers
151148
}
152149

153-
api.Commands, err = loadCommands()
154-
if err != nil {
155-
return nil, err
156-
}
157150
api.Lenses, err = loadLenses(settingsPkg, defaults.Codelenses)
158151
if err != nil {
159152
return nil, err
@@ -441,84 +434,6 @@ func valueDoc(name, value, doc string) string {
441434
return fmt.Sprintf("`%s`: %s", value, doc)
442435
}
443436

444-
func loadCommands() ([]*doc.Command, error) {
445-
var commands []*doc.Command
446-
447-
cmds, err := commandmeta.Load()
448-
if err != nil {
449-
return nil, err
450-
}
451-
// Parse the objects it contains.
452-
for _, cmd := range cmds {
453-
cmdjson := &doc.Command{
454-
Command: cmd.Name,
455-
Title: cmd.Title,
456-
Doc: cmd.Doc,
457-
ArgDoc: argsDoc(cmd.Args),
458-
}
459-
if cmd.Result != nil {
460-
cmdjson.ResultDoc = typeDoc(cmd.Result, 0)
461-
}
462-
commands = append(commands, cmdjson)
463-
}
464-
return commands, nil
465-
}
466-
467-
func argsDoc(args []*commandmeta.Field) string {
468-
var b strings.Builder
469-
for i, arg := range args {
470-
b.WriteString(typeDoc(arg, 0))
471-
if i != len(args)-1 {
472-
b.WriteString(",\n")
473-
}
474-
}
475-
return b.String()
476-
}
477-
478-
func typeDoc(arg *commandmeta.Field, level int) string {
479-
// Max level to expand struct fields.
480-
const maxLevel = 3
481-
if len(arg.Fields) > 0 {
482-
if level < maxLevel {
483-
return arg.FieldMod + structDoc(arg.Fields, level)
484-
}
485-
return "{ ... }"
486-
}
487-
under := arg.Type.Underlying()
488-
switch u := under.(type) {
489-
case *types.Slice:
490-
return fmt.Sprintf("[]%s", u.Elem().Underlying().String())
491-
}
492-
// TODO(adonovan): use (*types.Package).Name qualifier.
493-
return types.TypeString(under, nil)
494-
}
495-
496-
// TODO(adonovan): this format is strange; it's not Go, nor JSON, nor LSP. Rethink.
497-
func structDoc(fields []*commandmeta.Field, level int) string {
498-
var b strings.Builder
499-
b.WriteString("{\n")
500-
indent := strings.Repeat("\t", level)
501-
for _, fld := range fields {
502-
if fld.Doc != "" && level == 0 {
503-
doclines := strings.Split(fld.Doc, "\n")
504-
for _, line := range doclines {
505-
text := ""
506-
if line != "" {
507-
text = " " + line
508-
}
509-
fmt.Fprintf(&b, "%s\t//%s\n", indent, text)
510-
}
511-
}
512-
tag := strings.Split(fld.JSONTag, ",")[0]
513-
if tag == "" {
514-
tag = fld.Name
515-
}
516-
fmt.Fprintf(&b, "%s\t%q: %s,\n", indent, tag, typeDoc(fld, level+1))
517-
}
518-
fmt.Fprintf(&b, "%s}", indent)
519-
return b.String()
520-
}
521-
522437
// loadLenses combines the syntactic comments from the settings
523438
// package with the default values from settings.DefaultOptions(), and
524439
// returns a list of Code Lens descriptors.
@@ -828,23 +743,6 @@ func rewriteCodeLenses(prevContent []byte, api *doc.API) ([]byte, error) {
828743
return replaceSection(prevContent, "Lenses", buf.Bytes())
829744
}
830745

831-
func rewriteCommands(prevContent []byte, api *doc.API) ([]byte, error) {
832-
var buf bytes.Buffer
833-
for _, command := range api.Commands {
834-
// Emit HTML anchor as GitHub markdown doesn't support
835-
// "# Heading {#anchor}" syntax.
836-
fmt.Fprintf(&buf, "<a id='%s'></a>\n", command.Command)
837-
fmt.Fprintf(&buf, "## `%s`: **%s**\n\n%v\n\n", command.Command, command.Title, command.Doc)
838-
if command.ArgDoc != "" {
839-
fmt.Fprintf(&buf, "Args:\n\n```\n%s\n```\n\n", command.ArgDoc)
840-
}
841-
if command.ResultDoc != "" {
842-
fmt.Fprintf(&buf, "Result:\n\n```\n%s\n```\n\n", command.ResultDoc)
843-
}
844-
}
845-
return replaceSection(prevContent, "Commands", buf.Bytes())
846-
}
847-
848746
func rewriteAnalyzers(prevContent []byte, api *doc.API) ([]byte, error) {
849747
var buf bytes.Buffer
850748
for _, analyzer := range api.Analyzers {

Diff for: gopls/internal/cmd/execute.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ The execute command sends an LSP ExecuteCommand request to gopls,
3535
with a set of optional JSON argument values.
3636
Some commands return a result, also JSON.
3737
38-
Available commands are documented at:
39-
40-
https://github.com/golang/tools/blob/master/gopls/doc/commands.md
41-
42-
This interface is experimental and commands may change or disappear without notice.
38+
Gopls' command set is defined by the command.Interface type; see
39+
https://pkg.go.dev/golang.org/x/tools/gopls/internal/protocol/command#Interface.
40+
It is not a stable interface: commands may change or disappear without notice.
4341
4442
Examples:
4543

Diff for: gopls/internal/cmd/usage/execute.hlp

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ The execute command sends an LSP ExecuteCommand request to gopls,
77
with a set of optional JSON argument values.
88
Some commands return a result, also JSON.
99

10-
Available commands are documented at:
11-
12-
https://github.com/golang/tools/blob/master/gopls/doc/commands.md
13-
14-
This interface is experimental and commands may change or disappear without notice.
10+
Gopls' command set is defined by the command.Interface type; see
11+
https://pkg.go.dev/golang.org/x/tools/gopls/internal/protocol/command#Interface.
12+
It is not a stable interface: commands may change or disappear without notice.
1513

1614
Examples:
1715

Diff for: gopls/internal/doc/api.go

-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ var JSON string
2121
// TODO(adonovan): document these data types.
2222
type API struct {
2323
Options map[string][]*Option
24-
Commands []*Command
2524
Lenses []*Lens
2625
Analyzers []*Analyzer
2726
Hints []*Hint
@@ -54,14 +53,6 @@ type EnumValue struct {
5453
Doc string // doc comment; always starts with `Value`
5554
}
5655

57-
type Command struct {
58-
Command string // e.g. "gopls.run_tests"
59-
Title string
60-
Doc string
61-
ArgDoc string
62-
ResultDoc string
63-
}
64-
6556
type Lens struct {
6657
FileType string // e.g. "Go", "go.mod"
6758
Lens string

0 commit comments

Comments
 (0)