Debian Codegraph @

gopls/doc/release/v0.19.0.md

raw symbols SCIP
1 ---
2 title: "Gopls release v0.19.0 (Jun 2025)"
3 ---
4
5 ## Configuration Changes
6
7 - The `gopls check` subcommand now accepts a `-severity` flag to set a minimum
8 severity for the diagnostics it reports. By default, the minimum severity
9 is "warning", so `gopls check` may report fewer diagnostics than before. Set
10 `-severity=hint` to reproduce the previous behavior.
11
12 ## Navigation features
13
14 ### "Implementations" supports signature types (within same package)
15
16 <!-- golang/go#56572 -->
17
18 The Implementations query reports the correspondence between abstract
19 and concrete types and their methods based on their method sets.
20 Now, it also reports the correspondence between function types,
21 dynamic function calls, and function definitions, based on their signatures.
22
23 To use it, invoke an Implementations query on the `func` token of the
24 definition of a named function, named method, or function literal.
25 Gopls reports the set of function signature types that abstract this
26 function, and the set of dynamic calls through values of such types.
27
28 Conversely, an Implementations query on the `func` token of a
29 signature type, or on the `(` paren of a dynamic function call,
30 reports the set of concrete functions that the signature abstracts
31 or that the call dispatches to.
32
33 Since a type may be both a function type and a named type with methods
34 (for example, `http.HandlerFunc`), it may participate in both kinds of
35 Implements queries (method-sets and function signatures).
36 Queries using method-sets should be invoked on the type or method name,
37 and queries using signatures should be invoked on a `func` or `(` token.
38
39 Only the local (same-package) algorithm is currently supported.
40 (https://go.dev/issue/56572 tracks the global algorithm.)
41
42 ### "Go to Implementation" reports interface-to-interface relations
43
44 <!-- golang/go#68641 -->
45
46 The "Go to Implementation" operation now reports relationships between
47 interfaces. Gopls now uses the concreteness of the query type to
48 determine whether a query is "downwards" (from an interface to the
49 types that implement it) or "upwards" (from a concrete type to the
50 interfaces to which it may be assigned). So, for example:
51
52 - `implementation(io.Reader)` subinterfaces such as `io.ReadCloser`,
53 and concrete implementations such as `*os.File`.
54
55 - `implementation(os.File)` includes only interfaces, such as
56 `io.Reader` and `io.ReadCloser`.
57
58 To request an "upwards" query starting from an interface, for example
59 to find the superinterfaces of `io.ReadCloser`, use the Type Hierarchy
60 feature described below.
61 (See https://github.com/microsoft/language-server-protocol/issues/2037.)
62
63 ### Support for Type Hierarchy
64
65 <!-- golang/go#72142 -->
66
67 Gopls now implements the three LSP methods related to the Type
68 Hierarchy viewer: `textDocument/prepareTypeHierarchy`,
69 `typeHierarchy/supertypes`, `typeHierarchy/subtypes`.
70
71 In VS Code, select "Show Type Hierarchy" from the context menu
72 to see a tree widget displaying all the supertypes or subtypes
73 of the selected named type.
74
75 <img title="Type Hierarchy: supertypes of net.Conn" src="../assets/supertypes.png" width="400">
76
77 <img title="Type Hierarchy: subtypes of io.Writer" src="../assets/subtypes.png" width="400">
78
79
80 ## Editing features
81
82 ### Completion: auto-complete package clause for new Go files
83
84 Gopls now automatically adds the appropriate `package` clause to newly created Go files,
85 so that you can immediately get started writing the interesting part.
86
87 It requires client support for `workspace/didCreateFiles`
88
89 ### New GOMODCACHE index for faster Organize Imports and unimported completions
90
91 By default, gopls now builds and maintains a persistent index of
92 packages in the module cache (GOMODCACHE). The operations of Organize
93 Imports and completion of symbols from unimported packages are an
94 order of magnitude faster.
95
96 To revert to the old behavior, set the `importsSource` option (whose
97 new default is `"gopls"`) to `"goimports"`. Users who don't want the
98 module cache used at all for imports or completions can change the
99 option to "off".
100
101 ## Analysis features
102
103 ### Most `staticcheck` analyzers are enabled by default
104
105 Slightly more than half of the analyzers in the
106 [Staticcheck](https://staticcheck.dev/docs/checks) suite are now
107 enabled by default. This subset has been chosen for precision and
108 efficiency.
109
110 Previously, Staticcheck analyzers (all of them) would be run only if
111 the experimental `staticcheck` boolean option was set to `true`. This
112 value continues to enable the complete set, and a value of `false`
113 continues to disable the complete set. Leaving the option unspecified
114 enables the preferred subset of analyzers.
115
116 Staticcheck analyzers, like all other analyzers, can be explicitly
117 enabled or disabled using the `analyzers` configuration setting; this
118 setting now takes precedence over the `staticcheck` setting, so,
119 regardless of what value of `staticcheck` you use (true/false/unset),
120 you can make adjustments to your preferred set of analyzers.
121
122 ### `recursiveiter`: "inefficient recursive iterator"
123
124 A common pitfall when writing a function that returns an iterator
125 (`iter.Seq`) for a recursive data type is to recursively call the
126 function from its own implementation, leading to a stack of nested
127 coroutines, which is inefficient.
128
129 The new `recursiveiter` analyzer detects such mistakes; see
130 [its documentation](https://golang.org/x/tools/gopls/internal/analysis/recursiveiter)
131 for details, including tips on how to define simple and efficient
132 recursive iterators.
133
134 ### `maprange`: "inefficient range over maps.Keys/Values"
135
136 The new `maprange` analyzer detects redundant calls to `maps.Keys` or
137 `maps.Values` as the operand of a range loop; maps can of course be
138 ranged over directly. See
139 [its documentation](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/maprange)
140 for details).
141
142 ## Code transformation features
143
144 ### Rename method receivers
145
146 <!-- golang/go#41892 -->
147
148 The Rename operation, when applied to the declaration of a method
149 receiver, now also attempts to rename the receivers of all other
150 methods associated with the same named type. Each other receiver that
151 cannot be fully renamed is quietly skipped.
152
153 Renaming a _use_ of a method receiver continues to affect only that
154 variable.
155
156 ```go
157 type Counter struct { x int }
158
159 Rename here to affect only this method
160 ↓
161 func (c *Counter) Inc() { c.x++ }
162 func (c *Counter) Dec() { c.x++ }
163 ↑
164 Rename here to affect all methods
165 ```
166
167 ### "Eliminate dot import" code action
168
169 <!-- golang/go#70319 -->
170
171 This code action, available on a dotted import, will offer to replace
172 the import with a regular one and qualify each use of the package
173 with its name.
174
175 ### Add/remove tags from struct fields
176
177 Gopls now provides two new code actions, available on an entire struct
178 or some of its fields, that allow you to add and remove struct tags.
179 It adds only 'json' tags with a snakecase naming format, or clears all
180 tags within the selection.
181
182 Add tags example:
183 ```go
184 type Info struct {
185 LinkTarget string -> LinkTarget string `json:"link_target"`
186 ...
187 }
188 ```
189
190 ### Inline local variable
191
192 <!-- golang/go#70085 -->
193
194 The new `refactor.inline.variable` code action replaces a reference to
195 a local variable by that variable's initializer expression. For
196 example, when applied to `s` in `println(s)`:
197
198 ```go
199 func f(x int) {
200 s := fmt.Sprintf("+%d", x)
201 println(s)
202 }
203 ```
204 it transforms the code to:
205 ```go
206 func f(x int) {
207 s := fmt.Sprintf("+%d", x)
208 println(fmt.Sprintf("+%d", x))
209 }
210 ```
211
212 Only a single reference is replaced; issue https://go.dev/issue/70085
213 tracks the feature to "inline all" uses of the variable and eliminate
214 it.
215
216
217 ## Thank you to our contributors!
218
219 [@acehinnnqru](https://github.com/acehinnnqru)
220 [@adonovan](https://github.com/adonovan)
221 [@albfan](https://github.com/albfan)
222 [@aarzilli](https://github.com/aarzilli)
223 [@ashurbekovz](https://github.com/ashurbekovz)
224 [@cuonglm](https://github.com/cuonglm)
225 [@dmitshur](https://github.com/dmitshur)
226 [@neild](https://github.com/neild)
227 [@egonelbre](https://github.com/egonelbre)
228 [@shashank](https://github.com/shashank)
229 [priyadarshi](https://github.compriyadarshi)
230 [@firelizzard18](https://github.com/firelizzard18)
231 [@gopherbot](https://github.com/gopherbot)
232 [@h9jiang](https://github.com/h9jiang)
233 [@cuishuang](https://github.com/cuishuang)
234 [@jakebailey](https://github.com/jakebailey)
235 [@jba](https://github.com/jba)
236 [@madelinekalil](https://github.com/madelinekalil)
237 [@karamaru](https://github.com/karamaru)
238 [alpha](https://github.comalpha)
239 [@danztran](https://github.com/danztran)
240 [@nsrip](https://github.com/nsrip)
241 [dd](https://github.comdd)
242 [@pjweinb](https://github.com/pjweinb)
243 [@findleyr](https://github.com/findleyr)
244 [@samthanawalla](https://github.com/samthanawalla)
245 [@seankhliao](https://github.com/seankhliao)
246 [@tklauser](https://github.com/tklauser)
247 [@vikblom](https://github.com/vikblom)
248 [@kwjw](https://github.com/kwjw)
249 [@xieyuschen](https://github.com/xieyuschen)