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

(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