Debian Codegraph @

gopls/doc/release/v0.17.0.md

raw symbols SCIP
1 ---
2 title: "Gopls release v0.17.0 (Sep 2024)"
3 ---
4
5 <!-- TODO: update this instruction once v0.17.0 is released
6
7 Also, tweak the img URLs when publishing to GitHub Releases.
8 -->
9
10 ```
11 go install golang.org/x/tools/[email protected]
12 ```
13
14 ## New support policies
15
16 With this release, we are narrowing our official support window to align with
17 the [Go support policy](https://go.dev/doc/devel/release#policy). This will
18 reduce the considerable costs to us of testing against older Go versions,
19 allowing us to spend more time fixing bugs and adding features that benefit the
20 majority of gopls users who run recent versions of Go.
21
22 This narrowing is occurring in two dimensions: **build compatibility** refers to
23 the versions of the Go toolchain that can be used to build gopls, and **go
24 command compatibility** refers to the versions of the `go` command that can be
25 used by gopls to list information about packages and modules in your workspace.
26
27 ### Build compatibility: the most recent major Go version
28
29 As described in the [v0.16.0 release
30 notes](https://github.com/golang/tools/releases/tag/gopls%2Fv0.16.0), building the
31 latest version of gopls will now require the latest major version of the Go
32 toolchain. Therefore this release ([email protected]) must be built with Go 1.23.0
33 or later. Thanks to [automatic toolchain
34 upgrades](https://go.dev/blog/toolchain), if your system Go version is at least
35 Go 1.21.0 and you have `GOTOOLCHAIN=auto` set (the default), the `go` command
36 will automatically download the new Go toolchain as needed, similar to
37 upgrading a module dependency.
38
39 ### Go command compatibility: the 2 most recent major Go versions
40
41 The [email protected] releases will be the final versions of gopls to nominally
42 support integrating with more than the 2 most recent Go releases. In the past,
43 we implied "best effort" support for up to 4 versions, though in practice we
44 did not have resources to fix bugs that were present only with older Go
45 versions. With [email protected], we narrowed this best effort support to 3
46 versions, primarily because users need at least Go 1.21 to benefit from
47 automatic toolchain upgrades (see above).
48
49 Starting with [email protected], we will officially support integrating with only
50 the 2 most recent major versions of the `go` command. This is consistent with
51 the Go support policy. See [issue 69321](/issue/69321) (or [this
52 comment](https://github.com/golang/go/issues/69321#issuecomment-2344996677)
53 specifically) for details.
54
55 We won't prevent gopls from being used with older Go versions (just as we
56 don't disallow integration with arbitrary
57 [`go/packages`](https://pkg.go.dev/golang.org/x/tools/go/packages) drivers),
58 but we won't run integration tests against older Go versions, and won't fix
59 bugs that are only present when used with old Go versions.
60
61 ## Configuration Changes
62
63 - The `fieldalignment` analyzer, previously disabled by default, has
64 been removed: it is redundant with the hover size/offset information
65 displayed by v0.16.0 and its diagnostics were confusing.
66 - The `undeclaredname` analyzer has been replaced with an ordinary code action.
67 - The kind (identifiers) of all of gopls' code actions have changed
68 to use more specific hierarchical names. For example, "Inline call"
69 has changed from `refactor.inline` to `refactor.inline.call`.
70 This allows clients to request particular code actions more precisely.
71 The user manual now includes the identifier in the documentation for each code action.
72 - The experimental `allowImplicitNetworkAccess` setting is removed, following
73 its deprecation in [email protected]. See golang/go#66861 for details.
74
75 ## New features
76
77 ### Refactoring
78
79 This release contains a number of new features related to refactoring.
80 Additionally, it fixes [many
81 bugs](https://github.com/golang/go/issues?q=is%3Aissue+milestone%3Agopls%2Fv0.17.0+label%3ARefactoring+is%3Aclosed)
82 in existing refactoring operations, primarily related to **extract**, and **inline**.
83
84 These improvements move us toward a longer term goal of offering a more robust
85 and complete set of refactoring tools. We still have [much to
86 do](https://github.com/golang/go/issues?q=is%3Aissue+label%3Agopls+label%3ARefactoring+is%3Aopen+),
87 and this effort will continue into 2025.
88
89 #### Move parameter refactorings
90
91 Gopls now offers code actions to move function and method parameters left or
92 right in the function signature, updating all callers.
93
94 Unfortunately, there is no native LSP operation that provides a good user
95 interface for arbitrary "change signature" refactoring. We plan to build such
96 an interface within VS Code. In the short term, we have made it possible to
97 express more complicated parameter transformations by invoking 'rename' on the
98 'func' keyword. This user interface is a temporary stop-gap until a better
99 mechanism is available for LSP commands that enable client-side dialogs.
100
101 #### Extract declarations to new file
102
103 Gopls now offers another code action,
104 "Extract declarations to new file" (`refactor.extract.toNewFile`),
105 which moves selected code sections to a newly created file within the
106 same package. The created filename is chosen as the first {function, type,
107 const, var} name encountered. In addition, import declarations are added or
108 removed as needed.
109
110 The user can invoke this code action by selecting a function name, the keywords
111 `func`, `const`, `var`, `type`, or by placing the caret on them without selecting,
112 or by selecting a whole declaration or multiple declarations.
113
114 In order to avoid ambiguity and surprise about what to extract, some kinds
115 of partial selection of a declaration cannot invoke this code action.
116
117 #### Extract constant
118
119 When the selection is a constant expression, gopls now offers "Extract
120 constant" instead of "Extract variable", and generates a `const`
121 declaration instead of a local variable.
122
123 Also, extraction of a constant or variable now works at top-level,
124 outside of any function.
125
126 #### Generate missing method from function call
127
128 When you attempt to call a method on a type that lacks that method, the
129 compiler will report an error like “type T has no field or method f”. Gopls now
130 offers a new code action, “Declare missing method of T.f”, where T is the
131 concrete type and f is the undefined method. The stub method's signature is
132 inferred from the context of the call.
133
134 #### Generate a test for a function or method
135
136 If the selected chunk of code is part of a function or method declaration F,
137 gopls will offer the "Add test for F" code action, which adds a new test for the
138 selected function in the corresponding `_test.go` file. The generated test takes
139 into account its signature, including input parameters and results.
140
141 Since this feature is implemented by the server (gopls), it is compatible with
142 all LSP-compliant editors. VS Code users may continue to use the client-side
143 `Go: Generate Unit Tests For file/function/package` command, which runs the
144 [gotests](https://github.com/cweill/gotests) tool.
145
146 ### Initial support for pull diagnostics
147
148 When initialized with the option `"pullDiagnostics": true`, gopls will advertise support for the
149 `textDocument.diagnostic`
150 [client capability](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics),
151 which allows editors to request diagnostics directly from gopls using a
152 `textDocument/diagnostic` request, rather than wait for a
153 `textDocument/publishDiagnostics` notification. This feature is off by default
154 until the feature set of pull diagnostics is comparable to push diagnostics.
155
156 ### Hover improvements
157
158 The `textDocument/hover` response has slightly tweaked markdown rendering, and
159 includes the following additional information:
160
161 - Hovering over a standard library symbol now displays information about the
162 first Go release containing the symbol. For example, hovering over
163 `errors.As` shows "Added in go1.13".
164 - Hovering over the package name in a package declaration includes additional
165 package metadata.
166
167 ### Semantic token modifiers of top-level constructor of types
168
169 The semantic tokens response now includes additional modifiers for the top-level
170 constructor of the type of each symbol:
171 `interface`, `struct`, `signature`, `pointer`, `array`, `map`, `slice`, `chan`, `string`, `number`, `bool`, and `invalid`.
172 Editors may use this for syntax coloring.
173
174 ### SignatureHelp for ident and values.
175
176 Now, function signature help can be used on any identifier with a function
177 signature, not just within the parentheses of a function being called.
178
179 ### Jump to assembly definition
180
181 A Definition query on a reference to a function jumps to the
182 function's Go `func` declaration. If the function is implemented in C
183 or assembly, the function has no body. Executing a second Definition
184 query (while already at the Go declaration) will navigate you to the
185 assembly implementation.
186
187 ### `yield` analyzer
188
189 The new `yield` analyzer detects mistakes using the `yield` function
190 in a Go 1.23 iterator, such as failure to check its boolean result and
191 break out of a loop.
192
193 ### `waitgroup` analyzer
194
195 The new `waitgroup` analyzer detects calls to the `Add` method of
196 `sync.WaitGroup` that are (mistakenly) made within the new goroutine,
197 causing `Add` to race with `Wait`.
198 (This check is equivalent to
199 [staticcheck's SA2000](https://staticcheck.dev/docs/checks#SA2000),
200 but is enabled by default.)