Debian Codegraph @

gopls/doc/release/v0.21.0.md

raw symbols SCIP
1 ---
2 title: "Gopls release v0.21.0 (Dec 2025)"
3 ---
4
5 ## Configuration changes
6
7 - The new `newGoFileHeader` option allows toggling automatic insertion of the copyright comment
8 and package declaration in a newly created Go file.
9
10 - The default value of the `codelenses` setting now includes
11 `run_govulncheck: true`, causing gopls to offer a "Run govulncheck"
12 command associated with the `module` declaration in a go.mod file.
13
14 - The experimental `vulncheck` setting now supports the enum value
15 `"Prompt"`, meaning that vulncheck can be triggered via a prompt;
16 this is now the default.
17
18 - The new, experimental `renameMovesSubpackages` setting determines
19 whether a rename package operation applies to subdirectories; see
20 below for details.
21
22 ## Navigational features:
23
24 Hover can now report information about selected subexpressions (#69058).
25 For example, selecting the region indicated below:
26
27 x[i].f()
28 ~~~~
29
30 will report information about the subexpression `x[i]`, such as its
31 type, constant value (if appropriate), and methods.
32 Previously, Hover would report only about `x`, `i`, or `f`.
33
34 This feature requires the client to supply an extra field in the
35 `textDocumentPositionParams` part of its LSP `textDocument/hover`
36 request: the standard struct has a single `position` of type
37 `Position`, but gopls can also handle a `range` field of type
38 `Range` that specifies the extent of the text selection.
39 (If supplied, it must enclose the `position`.)
40
41 The VS Code code extension already populates this field. We plan to
42 use it across various requests, and to lobby for its adoption by the
43 LSP standard.
44
45 Other features in brief:
46
47 - Definition now works for fields in doc links in comments (#75038).
48 - Hover adds navigation to doc links in hovers (golang/vscode-go#3827).
49 - Hover now reports information (size, etc) about embedded fields, not just their types (#75975).
50 - Folding Range now displays closing parens (#75229) and more ranges (#73735).
51
52 ## Analysis features
53
54 ### `reflecttypefor` analyzer
55
56 <!-- golang/go#60088 -->
57
58 The new `reflecttypefor` analyzer modernizes calls to `reflect.TypeOf`
59 to use `reflect.TypeFor` when the runtime type is known at compile
60 time. For example:
61
62 reflect.TypeOf(uint32(0))
63
64 becomes:
65
66 reflect.TypeFor[uint32]()
67
68 ### `newexpr` analyzer
69
70 <!-- golang/go#45624 -->
71
72 The `newexpr` analyzer finds declarations of and calls to functions
73 of this form:
74 ```go
75 func varOf(x int) *int { return &x }
76
77 use(varOf(123))
78 ```
79 modernizing them when appropriate to use the `new(expr)` feature of Go 1.26:
80 ```go
81 //go:fix inline
82 func varOf(x int) *int { return new(x) }
83
84 use(new(123))
85 ```
86
87 Such wrapper functions are widely used in serialization packages,
88 for instance the proto.{Int64,String,Bool} helpers used with
89 protobufs.
90
91 ### `stditerators` analyzer
92
93 <!-- golang/go#75693 -->
94
95 The `stditerators` analyzer replaces loops of this form,
96
97 for i := 0; i < x.Len(); i++ {
98 use(x.At(i))
99 }
100
101 or their "range x.Len()" equivalent, by
102
103 for elem := range x.All() {
104 use(elem)
105 }
106
107 for various types in the standard library that now offer a
108 modern iterator-based API.
109
110 ### `stringscut` analyzer
111
112 <!-- golang/go#71369 -->
113
114 The `stringscut` analyzer modernizes various patterns of use of
115 `strings.Index` such as:
116
117 i := strings.Index(s, sep)
118 if i >= 0 {
119 use(s[i:])
120 }
121
122 by a call to `strings.Cut`, introduced in Go 1.25:
123
124 before, after, ok := strings.Cut(s, sep)
125 if ok {
126 use(after)
127 }
128
129 ### `plusbuild` analyzer
130
131 <!-- golang/go#73605 -->
132
133 The `plusbuild` analyzer removes old-style `+build` build-tag comments
134 when they are redundant with the newer form:
135
136 //go:build linux
137 // +build linux
138
139 ### `errorsastype` analyzer
140
141 <!-- golang/go#75692 -->
142
143 The `errorsastype` analyzer replaces calls to `errors.As`:
144
145 var myErr *MyError
146 if errors.As(err, &myErr) { ... }
147
148 by the more modern `errors.AsType`, when the type is known statically:
149
150 if myErr, ok := errors.AsType[*MyError](err) { ... }
151
152
153 ### `unsafefuncs` analyzer
154
155 <!-- golang/go#76648 -->
156
157 The `unsafefuncs` analyzer replaces arithmetic such as:
158
159 unsafe.Pointer(uintptr(ptr) + uintptr(n))
160
161 where ptr is an unsafe.Pointer, by calls to `unsafe.Add`, added in Go 1.17.
162
163 unsafe.Add(ptr, n)
164
165 ### Miscellaneous
166
167 - The `minmax` modernizer now removes user-defined min/max functions when they are redundant.
168 - The `stringscutprefix` modernizer now handles `strings.CutSuffix` too. <!-- #75205 -->
169 - The `yield` and `nilness` analyzers handle control-flow booleans more precisely. <!-- #74136, #75924 -->
170 - The `printf` analyzer now checks calls to local anonymous printf-wrapper functions too.
171 - The `staticcheck` suite has been updated to v0.7.
172
173 ## Code transformation features
174
175 ### Generalized package renaming
176
177 <!-- #57171 #75812 -->
178
179 The Rename operation, invoked on a `package p` declaration, now
180 prompts you to edit the entire package path. This allows you to choose
181 not just a new name for the package, but a new directory anywhere
182 within the same module. For example, you can rename `example.com/foo`
183 to `example.com/internal/bar`, and the tool will move files and update
184 imports as needed.
185
186 By default, subpackages are no longer moved with the renamed package.
187 Enable the new (experimental) `renameMovesSubpackages` setting if you
188 want subpackages to move too. (In due course, we will add LSP support
189 for dialogs so that the server can query the user's intent
190 interactively.)
191
192 This feature requires client support for the LSP
193 [`textDocument/prepareRename`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_prepareRename) operation.
194
195 ### Renaming from a doc link
196
197 <!-- golang/go#42301 -->
198 The Rename operation now treats [doc links](https://tip.golang.org/doc/comment#doclinks)
199 like identifiers, so you can initiate a renaming from a doc link.
200
201 ## Model context protocol (MCP) features
202
203 The MCP server now supports the `go_rename_symbol` tool, which permits
204 an agent to rename a symbol based on its name (e.g. `fmt.Println` or
205 `bytes.Buffer.WriteString`). The tool uses the symbol index to resolve
206 the name to a declaration and then initiates a renaming.
207
208 The server also supports the `gopls.vulncheck` tool, allowing agents
209 to scan packages for security vulnerabilities.
210
211 ## Closed issues
212
213 https://github.com/golang/go/milestone/399?closed=1
214