Repository navigation
x/tools/gopls: "Create function" generates a parameter list that does not parse #81810
Description
gopls version
golang.org/x/tools/gopls v0.23.0 (h1:Dn6mf9WXu9iLnTftDDMb9wV0c6Se7PjzEMqP0LEe08Y=), built with go1.27.1.
v0.23.0 is still the newest gopls release (checked 2026-09-28); reproduces on it again in 3 of 3 runs.
Same result with gopls v0.20.0.
go env
GOARCH=arm64
GOOS=darwin
GOVERSION=go1.27.1
GOFLAGS=-modcacherw
GOTOOLCHAIN=local(macOS 27 on Apple silicon; path variables left out.)
What did you do?
I drive gopls over LSP from a small script. junegunn/fzf at b1be3a8be1b833ce5b92fbbac11637643d60a046, src/pattern_test.go. I misspelled buildPattern as buildPttern on line 163 (1-based):
func TestCacheKey(t *testing.T) {
test := func(extended bool, patStr string, expected string, cacheable bool) {
pat := buildPttern(true, algo.FuzzyMatchV2, extended, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune(patStr))gopls reports undefined: buildPttern (UndeclaredName) and offers "Create function buildPttern". I applied it. It inserts this after TestCacheKey (new line 183):
func buildPttern(true1 bool, result, *[]int func(caseSensitive bool, normalize bool, forward bool, input *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (algo.Result, *[]int), extended bool, CaseSmart Case, false1, true2, false2, true3 bool, range []Range, delimiter Delimiter, r []rune) any {
panic("unimplemented")
}What did you see happen?
The file no longer parses (before the typo go vet ./src and gofmt -e pass; after the typo only the undefined error is reported):
$ gofmt -e src/pattern_test.go
src/pattern_test.go:183:38: missing parameter name
src/pattern_test.go:183:45: missing ',' in parameter list
src/pattern_test.go:183:64: expected ')', found bool
src/pattern_test.go:183:187: expected ';', found ','
src/pattern_test.go:183:189: expected declaration, found extended
src/pattern_test.go:257:2: expected declaration, found runtime
src/pattern_test.go:264:2: expected declaration, found runtime
src/pattern_test.go:283:3: expected declaration, found 'for'
$ go vet ./src
src/pattern_test.go:183:45: missing ',' in parameter list
gopls itself reports missing parameter name at 183:38 right after the edit. Two parts of the generated signature are not valid Go:
- the parameter for the argument
algo.FuzzyMatchV2(a function) is written asresult, *[]int func(...) (algo.Result, *[]int); - the parameter for
[]Range{}is namedrange, which is a keyword.
Same in 3 of 3 runs.
What did you expect to see?
A declaration that parses, for example a name like fn for the function-typed parameter and a non-keyword name such as ranges for the []Range one.
The any result type is a separate matter (see #77272, closed as a duplicate); this report is only about the parameter list.
Editor and settings
No editor; a script over stdio (gopls serve). Settings returned for workspace/configuration: {"semanticTokens": true, "hints": {"assignVariableTypes": true, "compositeLiteralFields": true, "compositeLiteralTypes": true, "constantValues": true, "functionTypeParameters": true, "parameterNames": true, "rangeVariableTypes": true}}.
Logs
LSP trace
F stands for the URI of src/pattern_test.go; positions are 0-based.
--> textDocument/didChange {"textDocument":{"uri":F,"version":2},"contentChanges":[{"range":{"start":{"line":162,"character":9},"end":{"line":162,"character":21}},"text":"buildPttern"}]}
<-- textDocument/publishDiagnostics {"uri":F,"version":2,"diagnostics":[{"range":{"start":{"line":162,"character":9},"end":{"line":162,"character":20}},"severity":1,"code":"UndeclaredName","source":"compiler","message":"undefined: buildPttern"}]}
--> textDocument/codeAction {"textDocument":{"uri":F},"range":{"start":{"line":162,"character":9},"end":{"line":162,"character":20}},"context":{"diagnostics":[(the diagnostic above)],"only":["quickfix"],"triggerKind":1}}
<-- [{"title":"Create function buildPttern","kind":"quickfix","data":{"title":"Create function buildPttern","command":"gopls.apply_fix",
"arguments":[{"Fix":"create_undeclared","Location":{"uri":F,"range":{"start":{"line":162,"character":9},"end":{"line":162,"character":20}}},"ResolveEdits":true}]}}]
--> codeAction/resolve (that action)
<-- {"title":"Create function buildPttern","kind":"quickfix","edit":{"documentChanges":[{"textDocument":{"version":2,"uri":F},"edits":[
{"range":{"start":{"line":180,"character":1},"end":{"line":180,"character":1}},
"newText":"\n\nfunc buildPttern(true1 bool, result, *[]int func(caseSensitive bool, normalize bool, forward bool, input *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (algo.Result, *[]int), extended bool, CaseSmart Case, false1, true2, false2, true3 bool, range []Range, delimiter Delimiter, r []rune) any {\n\tpanic(\"unimplemented\")\n}"}]}]}}
--> textDocument/didChange (the edit above, version 3)
<-- textDocument/publishDiagnostics {"uri":F,"version":3,"diagnostics":[{"range":{"start":{"line":182,"character":37},"end":{"line":182,"character":37}},"severity":1,"source":"syntax","message":"missing parameter name"}]}
Activity
gabyhelp commentedon Sep 28, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
gopherbot commentedon Oct 1, 2026
Change https://go.dev/cl/843125 mentions this issue:
gopls/internal/test/marker: add test for invalid "Create function" paramsh9jiang commentedon Oct 1, 2026
I just created a CL for including the failing cases and I think this issue can be fixed by open source contributor as it is not that complicated.
+Help Wanted.
Tiancheng-Xu commentedon Oct 2, 2026
I’d like to work on this issue. I’ll fix generation of function-typed and keyword-named parameters, add focused gopls regression coverage, and run the relevant tests.
gopls/internal/golang: generate valid names for new function parameters
gopherbot commentedon Oct 2, 2026
Change https://go.dev/cl/843605 mentions this issue:
gopls/internal/golang: generate valid names for new function parametersh9jiang commentedon Oct 2, 2026
Look like some one already has a CL for that... @Tiancheng-Xu do you want to take #81808?
You will need to make a comment in that issue so I can assign it to you.
gopherbot commentedon Oct 5, 2026
Change https://go.dev/cl/845405 mentions this issue:
gopls/internal/golang: replace assignment with declarationgopherbot commentedon Oct 11, 2026
Change https://go.dev/cl/848505 mentions this issue:
gopls/internal/golang: emit parseable Create function parameter listsgopls/internal/golang: generate valid names for new function parameters
gopls/internal/golang: derive valid param names from argument types
gopherbot commentedon Oct 15, 2026
Change https://go.dev/cl/849685 mentions this issue:
gopls/internal/test/marker: simplify undeclared test function namegopls/internal/test/marker: simplify undeclared test function names
gopls/internal/golang: derive valid param names from argument types