The rename package feature appears not to be working either in the CLI nor in Emacs+eglot:
xtools$ cat a/a.go
package a
xtools$ gopls rename -diff ./a/a.go:#9 b
--- /Users/adonovan/w/xtools/a/a.go.orig
+++ /Users/adonovan/w/xtools/a/a.go
@@ -1 +1 @@
-package a
+package b
gopls: getFile: file:///Users/adonovan/w/xtools/a: read /Users/adonovan/w/xtools/a: is a directory
xtools$ echo $?
2
It is working from VS Code though.
Also, it is undocumented. I've split this out as https://github.com/golang/go/issues/69624.
Comment From: gabyhelp
Related Issues and Documentation
- x/tools/gopls: support renaming a package #41567 (closed)
- x/tools/gopls: CLI cannot rename directories #68097
- x/tools/gopls: changing package names returns an error #32149 (closed)
- x/tools/gopls: improvements to package renaming #56184 (closed)
- x/tools/gopls: rename: spurious pkgname conflict in xtest #67069 (closed)
- x/tools/gopls: incorrect metadata invalidation when changing package name #52500 (closed)
- x/tools/gopls: support renaming a test package to make it external #69107
- x/tools/gopls: support module-local renaming #32877 (closed)
- x/tools/gopls: allow renaming arbitrary package paths #57171
- x/tools/cmd/gorename: tag and delete it #69360 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: yincongcyincong
@adonovan actually, cli command use cmd.go. but it don't have unit test file. https://github.com/golang/tools/blob/31fdc78e7d731b4dd2a4938a7a1911030cbc98c4/gopls/internal/cmd/cmd.go#L534
rename unit test just run this function. https://github.com/golang/tools/blob/31fdc78e7d731b4dd2a4938a7a1911030cbc98c4/gopls/internal/test/integration/fake/editor.go#L1417
Comment From: findleyr
I think this requires more investigation. If it is failing on emacs, then the fix cannot just be in the command line.
My guess is that emacs does not support the 'rename' resource operation kind: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#resourceOperationKind
And my guess is that our CLI client does not either.
Renaming packages works on coc.nvim, but doesn't quite work correctly: I always get warnings when saving about overwriting the file on disk. That may be a client problem.
Comment From: findleyr
Ah, it looks like the command line client does purport to support rename operations, so the associated fix may be right.
We should check whether emacs supports them.
Comment From: adonovan
I've split the documentation and eglot issues out: - https://github.com/golang/go/issues/69624 - https://github.com/joaotavora/eglot/issues/1450
This issue is now just about the CLI.
Comment From: gopherbot
Change https://go.dev/cl/615375 mentions this issue: gopls: fix rename command line fail