Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: rename fails to update doc comment for local variable of function type #42134

Closed
bcmills opened this issue Oct 22, 2020 · 1 comment
Labels
FeatureRequest FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Oct 22, 2020

What version are you using?

$ go version
go version devel +491fe1b95 Wed Oct 21 07:36:08 2020 +0000 linux/amd64

$ go version -m $(which gopls)
/usr/local/google/home/bcmills/bin/gopls: devel +186f0220d0 Mon Oct 5 11:12:24 2020 -0400
        path    golang.org/x/tools/gopls
        mod     golang.org/x/tools/gopls        v0.5.1  h1:AF3Uh7HF08SZpKFfgJO6zfF3bbxyDXWqdkK4kMXiQ1o=
        dep     github.com/BurntSushi/toml      v0.3.1  h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
        dep     github.com/google/go-cmp        v0.5.1  h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
        dep     github.com/sergi/go-diff        v1.1.0  h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
        dep     golang.org/x/mod        v0.3.0  h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
        dep     golang.org/x/sync       v0.0.0-20200625203802-6e8e738ad208      h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
        dep     golang.org/x/tools      v0.0.0-20200930165741-f1523d29dbb9      h1:1R38tQp22dcHpTKJPjgVa16FhlDy/kHEaCM/ndi/FIc=
        dep     golang.org/x/xerrors    v0.0.0-20200804184101-5ec99f83aff1      h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
        dep     honnef.co/go/tools      v0.0.1-2020.1.5 h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k=
        dep     mvdan.cc/gofumpt        v0.0.0-20200802201014-ab5a8192947d      h1:t8TAw9WgTLghti7RYkpPmqk4JtQ3+wcP5GgZqgWeWLQ=
        dep     mvdan.cc/xurls/v2       v2.2.0  h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

What did you do?

$ cat > example.go
package example

func F() {
	// f computes things.
	f := func() {}

	f()
}

$ emacs example.go
  • Move the cursor to the start of f := (at example.go:5:2).

  • M-x eglot-rename and enter a new name (g).

What did you expect to see?

Since the initial comment for local function f follows the Go convention for function documentation, the comment should be updated to remain consistent with that documentation: // g computes things.

What did you see instead?

The variable declaration and call site are updated, but the comment is not.

[Trace - 22:08:49.202 PM] Sending request 'initialize - (1)'.
Params: {"processId":471498,"rootPath":"/tmp/tmp.34b4txjdJE/example.com/","rootUri":"file:///tmp/tmp.34b4txjdJE/example.com/","initializationOptions":null,"capabilities":{"workspace":{"applyEdit":true,"executeCommand":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":false},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":false},"configuration":true},"textDocument":{"synchronization":{"dynamicRegistration":false,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":false,"completionItem":{"snippetSupport":true},"contextSupport":true},"hover":{"dynamicRegistration":false,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":false,"signatureInformation":{"parameterInformation":{"labelOffsetSupport":true}}},"references":{"dynamicRegistration":false},"definition":{"dynamicRegistration":false},"declaration":{"dynamicRegistration":false},"implementation":{"dynamicRegistration":false},"typeDefinition":{"dynamicRegistration":false},"documentSymbol":{"dynamicRegistration":false,"hierarchicalDocumentSymbolSupport":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"documentHighlight":{"dynamicRegistration":false},"codeAction":{"dynamicRegistration":false,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"formatting":{"dynamicRegistration":false},"rangeFormatting":{"dynamicRegistration":false},"rename":{"dynamicRegistration":false},"publishDiagnostics":{"relatedInformation":false}},"experimental":null}}


[Trace - 22:08:49.204 PM] Received response 'initialize - (1)' in 1ms.
Result: {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."]},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor.extract","refactor.rewrite","source.fixAll","source.organizeImports"]},"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["generate","fill_struct","regenerate_cgo","test","tidy","undeclared_name","upgrade_dependency","vendor","extract_variable","extract_function","gc_details","generate_gopls_mod"]},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"Build info\n----------\ngolang.org/x/tools/gopls v0.5.1\n    golang.org/x/tools/gopls@v0.5.1 h1:AF3Uh7HF08SZpKFfgJO6zfF3bbxyDXWqdkK4kMXiQ1o=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/google/go-cmp@v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=\n    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n    golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=\n    golang.org/x/sync@v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=\n    golang.org/x/tools@v0.0.0-20200930165741-f1523d29dbb9 h1:1R38tQp22dcHpTKJPjgVa16FhlDy/kHEaCM/ndi/FIc=\n    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\n    honnef.co/go/tools@v0.0.1-2020.1.5 h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k=\n    mvdan.cc/gofumpt@v0.0.0-20200802201014-ab5a8192947d h1:t8TAw9WgTLghti7RYkpPmqk4JtQ3+wcP5GgZqgWeWLQ=\n    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\n"}}


[Trace - 22:08:49.205 PM] Sending notification 'initialized'.
Params: {}


[Trace - 22:08:49.206 PM] Received notification 'window/showMessage'.
Params: {"type":4,"message":"Loading packages..."}


[Trace - 22:08:49.206 PM] Received request 'workspace/configuration - (1)'.
Params: {"items":[{"scopeUri":"file:///tmp/tmp.34b4txjdJE/example.com/","section":"gopls"},{"scopeUri":"file:///tmp/tmp.34b4txjdJE/example.com/","section":"gopls-example.com"}]}


[Trace - 22:08:49.207 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go","version":0,"languageId":"go","text":"package example\n\nfunc F() {\n\t// f computes things.\n\tf := func() {}\n\n\tf()\n}\n"}}


[Trace - 22:08:49.207 PM] Sending notification 'workspace/didChangeConfiguration'.
Params: {"settings":{"gopls":{"staticcheck":true,"matcher":"CaseSensitive"}}}


[Trace - 22:08:49.208 PM] Sending request 'textDocument/documentSymbol - (2)'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go"}}


[Trace - 22:08:49.217 PM] Sending response 'workspace/configuration - (1)' in 11ms.
Result: [{"staticcheck":true,"matcher":"CaseSensitive"},null]


[Trace - 22:08:49.254 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/10/21 22:08:49 go env for /tmp/tmp.34b4txjdJE/example.com/\n(root /tmp/tmp.34b4txjdJE/example.com)\n(go version go version devel +491fe1b95 Wed Oct 21 07:36:08 2020 +0000 linux/amd64\n)\n(valid build configuration = true)\n(build flags: [])\nGOPRIVATE=\nGO111MODULE=auto\nGOCACHE=/usr/local/google/home/bcmills/.cache/go-build\nGOPATH=/tmp/tmp.34b4txjdJE/_gopath\nGOPROXY=https://proxy.golang.org,direct\nGOSUMDB=sum.golang.org\nGOFLAGS=\nGOINSECURE=\nGOROOT=/usr/local/google/home/bcmills/sdk/gotip\nGONOPROXY=\nGONOSUMDB=\nGOMOD=/tmp/tmp.34b4txjdJE/example.com/go.mod\nGOMODCACHE=/tmp/tmp.34b4txjdJE/_gopath/pkg/mod\n\n"}


[Trace - 22:08:49.254 PM] Received request 'client/registerCapability - (2)'.
Params: {"registrations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.{go,mod,sum}","kind":7},{"globPattern":"/tmp/tmp.34b4txjdJE/example.com/**/*.{go,mod,sum}","kind":7}]}}]}


[Trace - 22:08:49.255 PM] Sending response 'client/registerCapability - (2)' in 1ms.
Result: 


[Trace - 22:08:49.343 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/10/21 22:08:49 go/packages.Load\n\tsnapshot=0\n\tdirectory=/tmp/tmp.34b4txjdJE/example.com\n\tquery=[./... builtin]\n\tpackages=2\n"}


[Trace - 22:08:49.343 PM] Received notification 'window/showMessage'.
Params: {"type":3,"message":"Finished loading packages."}


[Trace - 22:08:49.344 PM] Received request 'workspace/configuration - (3)'.
Params: {"items":[{"scopeUri":"file:///tmp/tmp.34b4txjdJE/example.com/","section":"gopls"},{"scopeUri":"file:///tmp/tmp.34b4txjdJE/example.com/","section":"gopls-example.com"}]}


[Trace - 22:08:49.363 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go","diagnostics":[{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":15}},"severity":2,"source":"ST1000","message":"at least one file in a package should have a package comment"}]}


[Trace - 22:08:49.366 PM] Sending response 'workspace/configuration - (3)' in 22ms.
Result: [{"staticcheck":true,"matcher":"CaseSensitive"},null]


[Trace - 22:08:49.367 PM] Received response 'textDocument/documentSymbol - (2)' in 158ms.
Result: [{"name":"F","detail":"()","kind":12,"range":{"start":{"line":2,"character":0},"end":{"line":7,"character":1}},"selectionRange":{"start":{"line":2,"character":5},"end":{"line":2,"character":6}}}]


[Trace - 22:08:51.295 PM] Sending request 'textDocument/signatureHelp - (3)'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go"},"position":{"line":4,"character":1}}


[Trace - 22:08:51.296 PM] Received response 'textDocument/signatureHelp - (3)' in 0ms.
Result: null


[Trace - 22:08:51.296 PM] Sending request 'textDocument/hover - (4)'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go"},"position":{"line":4,"character":1}}


[Trace - 22:08:51.296 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/10/21 22:08:51 no signature help: cannot find an enclosing function\n\tposition={4 1}\n"}


[Trace - 22:08:51.297 PM] Received response 'textDocument/hover - (4)' in 0ms.
Result: {"contents":{"kind":"markdown","value":"```go\nvar f func()\n```"},"range":{"start":{"line":4,"character":1},"end":{"line":4,"character":2}}}


[Trace - 22:08:51.297 PM] Sending request 'textDocument/documentHighlight - (5)'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go"},"position":{"line":4,"character":1}}


[Trace - 22:08:51.298 PM] Received response 'textDocument/documentHighlight - (5)' in 0ms.
Result: [{"range":{"start":{"line":4,"character":1},"end":{"line":4,"character":2}},"kind":1},{"range":{"start":{"line":6,"character":1},"end":{"line":6,"character":2}},"kind":1}]


[Trace - 22:09:29.887 PM] Sending request 'textDocument/rename - (6)'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go"},"position":{"line":4,"character":1},"newName":"g"}


[Trace - 22:09:29.888 PM] Received response 'textDocument/rename - (6)' in 0ms.
Result: {"documentChanges":[{"textDocument":{"version":0,"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go"},"edits":[{"range":{"start":{"line":4,"character":1},"end":{"line":4,"character":2}},"newText":"g"},{"range":{"start":{"line":6,"character":1},"end":{"line":6,"character":2}},"newText":"g"}]}]}


[Trace - 22:09:34.399 PM] Sending notification 'textDocument/didChange'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.34b4txjdJE/example.com/example.go","version":2},"contentChanges":[{"range":{"start":{"line":6,"character":1},"end":{"line":6,"character":2}},"rangeLength":1,"text":"g"},{"range":{"start":{"line":4,"character":1},"end":{"line":4,"character":2}},"rangeLength":1,"text":"g"}]}


@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Oct 22, 2020
@gopherbot gopherbot added this to the Unreleased milestone Oct 22, 2020
ShoshinNikita added a commit to ShoshinNikita/tools that referenced this issue Jun 11, 2021
…ble declarations

*ast.AssignStmt doesn't have an associated comment group. So, we should
try to find and return a comment just before the identifier.

Fixes golang/go#42134
@gopherbot
Copy link

Change https://golang.org/cl/327229 mentions this issue: internal/lsp/source: fix comment update during rename for short variable declarations

@golang golang locked and limited conversation to collaborators Jul 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
3 participants