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 things declared in other package fails #36743

Closed
leitzler opened this issue Jan 24, 2020 · 3 comments
Closed

x/tools/gopls: rename things declared in other package fails #36743

leitzler opened this issue Jan 24, 2020 · 3 comments
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

@leitzler
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.13.5 darwin/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20200124144541-e0a7ba33caea
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.1.8-0.20200124144541-e0a7ba33caea

Does this issue reproduce with the latest release?

Yes

What did you do?

Tried to rename a const declared in another package. Consider the following structure:

-- go.mod --
module foo

go 1.13
-- main.go --
package main

import "foo/bar"

func main() {
	_ = bar.Abc
}
-- bar/bar.go --
package bar

const Abc = 1

Moving the cursor to Abc in main.go and rename it to Xyz will produce the following error (full log below):

[Error - 17:01:27.179 PM] Received #2 rename failed because "Abc" is declared in a different package (foo/bar)

What did you expect to see?

The const renamed to Xyz in both files (as it is if I initiate the rename from the declaration in bar/bar.go).

What did you see instead?

Full log:

[Trace - 17:01:14.776 PM] Sending request 'initialize - (1)'.
Params: {"processId":0,"clientInfo":{"name":""},"rootUri":"file:///private/var/folders/xm/ls208xd174v95pgd20rn_qbh0000gn/T/tmp.Re0MKR8F","capabilities":{"Workspace":{"workspaceEdit":{},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{},"symbol":{"symbolKind":{}},"executeCommand":{},"configuration":true},"textDocument":{"synchronization":{},"completion":{"completionItem":{"tagSupport":{"valueSet":null}},"completionItemKind":{}},"hover":{"contentFormat":["plaintext"]},"signatureHelp":{"signatureInformation":{"parameterInformation":{}}},"declaration":{},"definition":{},"typeDefinition":{},"implementation":{},"references":{},"documentHighlight":{},"documentSymbol":{"symbolKind":{}},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":null}}},"codeLens":{},"documentLink":{},"colorProvider":{},"formatting":{},"rangeFormatting":{},"onTypeFormatting":{},"rename":{},"foldingRange":{},"selectionRange":{},"publishDiagnostics":{"tagSupport":{"valueSet":null}}}},"initializationOptions":{"incrementalSync":true,"noDocsOnHover":true},"workspaceFolders":null}

[Trace - 17:01:14.777 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":true,"codeLensProvider":{},"documentLinkProvider":{},"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["tidy"]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":""}}

[Trace - 17:01:14.779 PM] Sending notification 'initialized'.
Params: {}

[Trace - 17:01:14.779 PM] Received request 'client/registerCapability - (1)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"}]}

[Trace - 17:01:14.779 PM] Sending response 'client/registerCapability - (1)' took 0ms.
Result: {}

[Trace - 17:01:14.983 PM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///private/var/folders/xm/ls208xd174v95pgd20rn_qbh0000gn/T/tmp.Re0MKR8F","section":"gopls"},{"scopeUri":"file:///private/var/folders/xm/ls208xd174v95pgd20rn_qbh0000gn/T/tmp.Re0MKR8F","section":"gopls-tmp.Re0MKR8F"}]}

[Trace - 17:01:14.983 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/01/24 17:01:14 Build info\n----------\ngolang.org/x/tools/gopls master\n golang.org/x/tools/gopls@v0.1.8-0.20200124144541-e0a7ba33caea h1:OnJGpjPAB/28lzlrzuQqV0fpgIVfOHjU/xbnUrSgjD0=\n github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=\n golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=\n golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=\n golang.org/x/tools@v0.0.0-20200124144541-e0a7ba33caea h1:NswqrEQouRszUa56DK5nlUNefj11O3oP36+XSl32fPU=\n golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=\n honnef.co/go/tools@v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=\n mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=\n\nGo info\n-------\ngo version go1.13.5 darwin/amd64\n\nGO111MODULE=""\nGOARCH="amd64"\nGOBIN=""\nGOCACHE="/Users/pontus/Library/Caches/go-build"\nGOENV="/Users/pontus/Library/Application Support/go/env"\nGOEXE=""\nGOFLAGS=""\nGOHOSTARCH="amd64"\nGOHOSTOS="darwin"\nGONOPROXY=""\nGONOSUMDB=""\nGOOS="darwin"\nGOPATH="/Users/pontus/go"\nGOPRIVATE=""\nGOPROXY="https://proxy.golang.org,direct\"\nGOROOT=\"/usr/local/go\"\nGOSUMDB=\"sum.golang.org\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/go/pkg/tool/darwin_amd64\"\nGCCGO=\"gccgo\"\nAR=\"ar\"\nCC=\"clang\"\nCXX=\"clang++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"/var/folders/xm/ls208xd174v95pgd20rn_qbh0000gn/T/tmp.Re0MKR8F/go.mod\"\nCGO_CFLAGS=\"-g -O2"\nCGO_CPPFLAGS=""\nCGO_CXXFLAGS="-g -O2"\nCGO_FFLAGS="-g -O2"\nCGO_LDFLAGS="-g -O2"\nPKG_CONFIG="pkg-config"\nGOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xm/ls208xd174v95pgd20rn_qbh0000gn/T/go-build414268253=/tmp/go-build -gno-record-gcc-switches -fno-common"\n"}

[Trace - 17:01:14.983 PM] Sending response 'workspace/configuration - (2)' took 0ms.
Result: [{"hoverKind":"FullDocumentation","staticcheck":false},null]

[Trace - 17:01:15.011 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///private/var/folders/xm/ls208xd174v95pgd20rn_qbh0000gn/T/tmp.Re0MKR8F/main.go","languageId":"go","version":1,"text":"package main\n\nimport "foo/bar"\n\nfunc main() {\n\t_ = bar.Abc\n}\n"}}

[Trace - 17:01:15.269 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/01/24 17:01:15 go/packages.Load\n\tsnapshot = 0\n\tquery = [./... builtin]\n\tpackages = 3"}

[Trace - 17:01:27.179 PM] Sending request 'textDocument/rename - (2)'.
Params: {"textDocument":{"uri":"file:///private/var/folders/xm/ls208xd174v95pgd20rn_qbh0000gn/T/tmp.Re0MKR8F/main.go"},"position":{"line":5,"character":10},"newName":"Xyz"}

[Error - 17:01:27.179 PM] Received #2 rename failed because "Abc" is declared in a different package (foo/bar)

@gopherbot gopherbot added this to the Unreleased milestone Jan 24, 2020
@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 Jan 24, 2020
@stamblerre stamblerre changed the title x/tools/gopls: Can't rename things declared in other package x/tools/gopls: rename symbols declared in other packages Jan 24, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Jan 24, 2020
@leitzler leitzler changed the title x/tools/gopls: rename symbols declared in other packages x/tools/gopls: rename things declared in other package fails Jan 24, 2020
@muirdm
Copy link

muirdm commented Jan 25, 2020

There is an explicit check disallowing this. I wasn't sure why it was disallowed, but I preserved it when changing things. It may have been just because it didn't used to work, but it should work now (if we remove the check).

@stamblerre
Copy link
Contributor

Ah, I think that check must be left over from when references and renames only worked within a single package. I'll mail a CL to remove it.

@gopherbot
Copy link

Change https://golang.org/cl/216306 mentions this issue: internal/lsp: permit renaming symbols declared in other packages

@stamblerre stamblerre modified the milestones: gopls/v1.0.0, gopls/v0.4.0 Jul 22, 2020
@golang golang locked and limited conversation to collaborators Jul 22, 2021
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

No branches or pull requests

4 participants