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: refactor function fails #44813

Closed
hyangah opened this issue Mar 5, 2021 · 1 comment
Closed

x/tools/gopls: refactor function fails #44813

hyangah opened this issue Mar 5, 2021 · 1 comment
Labels
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

@hyangah
Copy link
Contributor

hyangah commented Mar 5, 2021

go1.16
gopls 0.6.6

Example:

package main

import "fmt"

func main() {

	x := []rune{} // line 7
	s := "HELLO"
	for _, c := range s {
		x = append(x, c)
	} // line 11

	fmt.Printf("%x\n", x)
}

Select from line 7 to line 11 and see gopls return a code action.
Select the code action and see the refactoring request fail.

[Error - 11:39:14 AM] Request workspace/executeCommand failed.
  Message: parent nil
  Code: 0 
[Error - 11:39:14 AM] 2021/03/05 11:39:14 command error: parent nil

If test in vscode, there is another issue involved but that's independent.

GOPLS log [Trace - 11:38:48.832 AM] Sending request 'initialize - (0)'. Params: {"processId":35545,"clientInfo":{"name":"vscode","version":"1.53.2"},"rootPath":"/Users/hakim/testrefactor","rootUri":"file:///Users/hakim/testrefactor","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":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]},"tagSupport":{"valueSet":[1]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true,"semanticTokens":{"refreshSupport":true}},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"codeDescriptionSupport":true,"dataSupport":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]}},"completionItemKind":{"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]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":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]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]},"labelSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true,"prepareSupportDefaultBehavior":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","member","macro","keyword","modifier","comment","string","number","regexp","operator"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"formats":["relative"],"requests":{"range":true,"full":{"delta":true}}}},"window":{"workDoneProgress":true}},"initializationOptions":{"build.expandWorkspaceToModule":true,"build.experimentalWorkspaceModule":false,"build.directoryFilters":["-internal/lsp/testdata"]},"trace":"off","workspaceFolders":[{"uri":"file:///Users/hakim/testrefactor","name":"testrefactor"}]}

[Trace - 11:38:48.834 AM] Received response 'initialize - (0)' in 2ms.
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":{"prepareProvider":true},"foldingRangeProvider":true,"executeCommandProvider":{"commands":["gopls.add_dependency","gopls.add_import","gopls.apply_fix","gopls.check_upgrades","gopls.gc_details","gopls.generate","gopls.generate_gopls_mod","gopls.go_get_package","gopls.list_known_packages","gopls.regenerate_cgo","gopls.remove_dependency","gopls.run_tests","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor"]},"callHierarchyProvider":true},"serverInfo":{"name":"gopls","version":"{"path":"golang.org/x/tools/gopls","version":"v0.6.6","sum":"h1:GmCsAKZMEb1BD1BTWnQrMyx4FmNThlEsmuFiJbLBXio=","deps":[{"path":"github.com/BurntSushi/toml","version":"v0.3.1","sum":"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ="},{"path":"github.com/google/go-cmp","version":"v0.5.4","sum":"h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M="},{"path":"github.com/sergi/go-diff","version":"v1.1.0","sum":"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0="},{"path":"golang.org/x/mod","version":"v0.4.1","sum":"h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY="},{"path":"golang.org/x/sync","version":"v0.0.0-20201020160332-67f06af15bc9","sum":"h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck="},{"path":"golang.org/x/sys","version":"v0.0.0-20210124154548-22da62e12c0c","sum":"h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk="},{"path":"golang.org/x/tools","version":"v0.1.1-0.20210222172741-77e031214674","sum":"h1:XzEjy9Ks1MwmcJOarbxTnL/AqHtzsRfRzAwfDhII2lE="},{"path":"golang.org/x/xerrors","version":"v0.0.0-20200804184101-5ec99f83aff1","sum":"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE="},{"path":"honnef.co/go/tools","version":"v0.1.1","sum":"h1:EVDuO03OCZwpV2t/tLLxPmPiomagMoBOgfPt0FM+4IY="},{"path":"mvdan.cc/gofumpt","version":"v0.1.0","sum":"h1:hsVv+Y9UsZ/mFZTxJZuHVI6shSQCtzZ11h1JEFPAZLw="},{"path":"mvdan.cc/xurls/v2","version":"v2.2.0","sum":"h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A="}]}"}}

[Trace - 11:38:48.860 AM] Sending notification 'initialized'.
Params: {}

[Trace - 11:38:48.861 AM] Received request 'window/workDoneProgress/create - (1)'.
Params: {"token":"5577006791947779410"}

[Trace - 11:38:48.861 AM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go","languageId":"go","version":1,"text":"package main\n\nimport "fmt"\n\nfunc main() {\n\n\tx := []rune{}\n\ts := "HELLO"\n\tfor _, c := range s {\n\t\tx = append(x, c)\n\t}\n\n\tfmt.Printf("%x\n", x)\n}\n"}}

[Trace - 11:38:48.882 AM] Sending response 'window/workDoneProgress/create - (1)' in 21ms.
Result:

[Trace - 11:38:48.883 AM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"begin","title":"Setting up workspace","message":"Loading packages..."}}

[Trace - 11:38:48.883 AM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///Users/hakim/testrefactor","section":"gopls"}]}

[Trace - 11:38:48.993 AM] Sending request 'textDocument/documentLink - (1)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"}}

[Trace - 11:38:48.995 AM] Sending request 'textDocument/documentSymbol - (2)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"}}

[Trace - 11:38:49.117 AM] Sending response 'workspace/configuration - (2)' in 234ms.
Result: [{"build.expandWorkspaceToModule":true,"build.experimentalWorkspaceModule":false,"build.directoryFilters":["-internal/lsp/testdata"]}]

[Trace - 11:38:49.118 AM] Sending request 'textDocument/foldingRange - (3)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"}}

[Trace - 11:38:49.119 AM] Sending request 'textDocument/codeLens - (4)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"}}

[Trace - 11:38:49.151 AM] Sending notification '$/cancelRequest'.
Params: {"id":4}

[Trace - 11:38:49.345 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/03/05 11:38:49 go env for /Users/hakim/testrefactor\n(root /Users/hakim/testrefactor)\n(go version go version go1.16 darwin/amd64)\n(valid build configuration = true)\n(build flags: [])\nGO111MODULE=\nGOCACHE=/Users/hakim/Library/Caches/go-build\nGOMOD=/Users/hakim/testrefactor/go.mod\nGONOSUMDB=\nGOINSECURE=\nGOMODCACHE=/Users/hakim/go/pkg/mod\nGOSUMDB=sum.golang.org\nGOFLAGS=\nGONOPROXY=\nGOPATH=/Users/hakim/go\nGOPRIVATE=\nGOPROXY=https://proxy.golang.org,direct\nGOROOT=/usr/local/go\n\n"}

[Info - 11:38:49 AM] 2021/03/05 11:38:49 go env for /Users/hakim/testrefactor
(root /Users/hakim/testrefactor)
(go version go version go1.16 darwin/amd64)
(valid build configuration = true)
(build flags: [])
GO111MODULE=
GOCACHE=/Users/hakim/Library/Caches/go-build
GOMOD=/Users/hakim/testrefactor/go.mod
GONOSUMDB=
GOINSECURE=
GOMODCACHE=/Users/hakim/go/pkg/mod
GOSUMDB=sum.golang.org
GOFLAGS=
GONOPROXY=
GOPATH=/Users/hakim/go
GOPRIVATE=
GOPROXY=https://proxy.golang.org,direct
GOROOT=/usr/local/go

[Trace - 11:38:49.450 AM] Sending request 'textDocument/codeLens - (5)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"}}

[Trace - 11:38:49.658 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2021/03/05 11:38:49 go/packages.Load\n\tsnapshot=0\n\tdirectory=/Users/hakim/testrefactor\n\tquery=[builtin w/...]\n\tpackages=2\n"}

[Info - 11:38:49 AM] 2021/03/05 11:38:49 go/packages.Load
snapshot=0
directory=/Users/hakim/testrefactor
query=[builtin w/...]
packages=2

[Trace - 11:38:49.707 AM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"end","message":"Finished loading packages."}}

[Trace - 11:38:49.775 AM] Received request 'client/registerCapability - (3)'.
Params: {"registrations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.{go,mod,sum}","kind":7}]}}]}

[Trace - 11:38:49.785 AM] Sending response 'client/registerCapability - (3)' in 9ms.
Result:

[Trace - 11:38:49.789 AM] Received request 'client/registerCapability - (4)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"}]}

[Trace - 11:38:49.791 AM] Sending response 'client/registerCapability - (4)' in 1ms.
Result:

[Trace - 11:38:49.915 AM] Received response 'textDocument/documentLink - (1)' in 922ms.
Result: [{"range":{"start":{"line":2,"character":8},"end":{"line":2,"character":11}},"target":"https://pkg.go.dev/fmt?utm_source=gopls"}]

[Trace - 11:38:49.917 AM] Received response 'textDocument/documentSymbol - (2)' in 922ms.
Result: [{"name":"main","detail":"()","kind":12,"range":{"start":{"line":4,"character":0},"end":{"line":13,"character":1}},"selectionRange":{"start":{"line":4,"character":5},"end":{"line":4,"character":9}}}]

[Trace - 11:38:49.917 AM] Received response 'textDocument/foldingRange - (3)' in 799ms.
Result: [{"startLine":4,"startCharacter":13,"endLine":12,"endCharacter":22},{"startLine":8,"startCharacter":22,"endLine":9,"endCharacter":18}]

[Error - Received] 11:38:49.918 AM #4 JSON RPC cancelled

[Trace - 11:38:49.918 AM] Received response 'textDocument/codeLens - (5)' in 467ms.
Result: null

[Trace - 11:38:56.941 AM] Sending request 'textDocument/hover - (6)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"},"position":{"line":6,"character":0}}

[Trace - 11:38:56.942 AM] Received response 'textDocument/hover - (6)' in 0ms.
Result: null

[Trace - 11:38:57.297 AM] Sending request 'textDocument/hover - (7)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"},"position":{"line":6,"character":0}}

[Trace - 11:38:57.298 AM] Received response 'textDocument/hover - (7)' in 0ms.
Result: null

[Trace - 11:38:57.418 AM] Sending request 'textDocument/documentHighlight - (8)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"},"position":{"line":6,"character":1}}

[Trace - 11:38:57.419 AM] Received response 'textDocument/documentHighlight - (8)' in 1ms.
Result: [{"range":{"start":{"line":12,"character":20},"end":{"line":12,"character":21}},"kind":1},{"range":{"start":{"line":6,"character":1},"end":{"line":6,"character":2}},"kind":1},{"range":{"start":{"line":9,"character":2},"end":{"line":9,"character":3}},"kind":1},{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":14}},"kind":1}]

[Trace - 11:38:58.036 AM] Sending request 'textDocument/codeLens - (9)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"}}

[Trace - 11:38:58.037 AM] Received response 'textDocument/codeLens - (9)' in 0ms.
Result: null

[Trace - 11:38:58.448 AM] Sending request 'textDocument/codeAction - (10)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/testrefactor/main.go"},"range":{"start":{"line":6,"character":1},"end":{"line":10,"character":2}},"context":{"diagnostics":[]}}

[Trace - 11:38:58.449 AM] Received response 'textDocument/codeAction - (10)' in 1ms.
Result: [{"title":"Extract to function","kind":"refactor.extract","edit":{},"command":{"title":"Extract to function","command":"gopls.apply_fix","arguments":[{"Fix":"extract_function","URI":"file:///Users/hakim/testrefactor/main.go","Range":{"start":{"line":6,"character":1},"end":{"line":10,"character":2}}}]}}]

[Trace - 11:39:14.739 AM] Sending request 'workspace/executeCommand - (11)'.
Params: {"command":"gopls.apply_fix","arguments":[{"Fix":"extract_function","URI":"file:///Users/hakim/testrefactor/main.go","Range":{"start":{"line":6,"character":1},"end":{"line":10,"character":2}}}]}

[Error - Received] 11:39:14.740 AM #11 parent nil

[Trace - 11:39:14.741 AM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2021/03/05 11:39:14 command error: parent nil\n"}

[Error - 11:39:14 AM] Request workspace/executeCommand failed.
Message: parent nil
Code: 0
[Error - 11:39:14 AM] 2021/03/05 11:39:14 command error: parent nil

@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 Mar 5, 2021
@gopherbot gopherbot added this to the Unreleased milestone Mar 5, 2021
ShoshinNikita added a commit to ShoshinNikita/tools that referenced this issue Mar 29, 2021
…ction

The blank identifier is always a local variable. It can't be
a function parameter or a return value.

Fixes golang/go#44813
@gopherbot
Copy link

Change https://golang.org/cl/305429 mentions this issue: internal/lsp/source: skip blank identifiers during the function extraction

@golang golang locked and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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
Development

Successfully merging a pull request may close this issue.

3 participants