-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: support module-local renaming #32877
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
Comments
Right now, rename only works within a package and its tests. We are still working on a strategy for renaming packages in a module. /cc @suzmue |
This is closely tied to issue #32869 Once find all references in the module level is supported, we should be able to global renaming. |
Why modules are so important here? Is it possible to detect project root and scan all symbols the same way |
The |
When I did |
Change https://golang.org/cl/207264 mentions this issue: |
Is this really fixed? Renames across packages in the same module still fail with the latest commit in master. The error displayed within vim-go is:
|
Yes. That error sounds like you are trying to do a rename outside of the declaring package. I believe you have to be in the package where the variable is declared to rename it. |
Renaming from the file containing the declaration works. It does not rename references outside the package declaring the identifier, but in the same module. Is this a known issue? Is there an existing issue I can follow to know when tthishat is fixed? |
This is the issue tracking renaming identifiers across packages in the same module. Renaming across multiple modules is not supported. This functionality is available at master, not |
I had the same experience just now. ❯ gopls version
golang.org/x/tools/gopls master
golang.org/x/tools/gopls@(devel)
❯ git log --oneline | head -1
774c71fc internal/lsp/cache: fix type error reporting in cgo FWIW, I'm using the latest LanguageClient-neovim on the latest neovim, not going through vscode. Within the same module:
|
Honestly, though, I don't know how to distinguish between a server problem and a client problem, so I don't know if this is on gopls. Happy to try out any other recommended debugging steps. I'll poke around for some & try another client, at least. |
Tried out ALE, which failed to rename anything, and coc.nvim, which did the same local-file-only rename. I was able to run gopls with logging, and captured the following for a rename:
... and the following for a references search on the original name:
Notice the rename only applies to the original file, when a call to find references on the original name returns a different file. I changed paths/names, so you'll have to trust me that it's all in the same module. |
@toejough is it possible to express in test code like golang/tools@4191b8c ? |
One of https://github.com/golang/tools/tree/master/internal/lsp/testdata/rename should fail if there is a bug. |
do I have to do something special to run those tests? go/src/golang.org/x/tools/gopls> go test ./test -v
...
--- SKIP: TestCommandLine/GOPATH/Renames/crosspkg_Dolphin (0.03s)
format.go:57: multi-file patch tests not supported yet
--- SKIP: TestCommandLine/GOPATH/Renames/crosspkg_Tomato (0.02s)
format.go:57: multi-file patch tests not supported yet
... |
No idea. @ianthehat should know. |
You can run the tests inside of the @toejough: I am unable to reproduce your example. In fact, I am able to rename from the function's use, not just the declaration. What is your workspace root when you open your editor? |
thanks - calling what editor/plugin/client are you using to do the rename? I'm back to using vim-go, and I still get the I'm opening vim from my module's root directory, and If I send debug output to a file at launch, I get a message like:
|
I believe that /cc @bhcleek for |
I deleted my last reply - I made it via email from the bus at the end of my work day - having gotten dinner in me now I realize it didn't really add anything. I appreciate the help on this (and gopls and vim-go in general - they are amazing tools!). I'll try vscode tomorrow with my codebase to see how that responds. |
@stamblerre you're right that vim-go currently uses |
I still get the error about the function being defined in another package, but using vscode I'm able to rename across packages successfully. I'll give vscode another try for a bit, and move over to vim-go's project for more plugin/client discussion. Thank you for the help and responsiveness! |
Is there an issue for making |
|
VS Code. Latest gopls code from master. Trying quite simple rename operation:

The text was updated successfully, but these errors were encountered: