:GoRename
I am using go modules with go.mod and go.sum definited;
It should rename all references of object.
It just rename the references in the same file, ignoring others references.
let g:go_fmt_command = "goimports"
let g:go_def_mode = 'godef'
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_generate_tags = 1
let g:go_rename_command = 'gopls'
cab GoCoverage GoCoverage -gcflags=all=-l
tag: v1.22 - 804c8db75f150f2f38ccb10f0b89d8bc999aab15
:version):NVIM v0.3.8
Build type: Release
LuaJIT 2.1.0-beta3
go version):go version go1.13.4 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/guilherme/.cache/go-build"
GOENV="/home/guilherme/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/guilherme/.gvm/pkgsets/go1.13.4/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/guilherme/.gvm/gos/go1.13.4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/guilherme/.gvm/gos/go1.13.4/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build593704735=/tmp/go-build -gno-record-gcc-switches"
golang.org/x/tools/gopls 0.2.2
This is a limitation of using [email protected] to rename. I believe that v0.3.0 will fix this (@stamblerre can you confirm?)
You have three choices. Your first option is to use GOPATH mode and set g:go_rename_command='gorename', then you'll see the behavior you desire. Your second option is to update to gopls v0.3.0-pre3 now by running GO111MODULE=on go get golang.org/x/tools/[email protected] to wait until gopls v0.3.0 is released and then update to vim-go master and run :GoUpdateBinaries gopls when that happens and after https://github.com/fatih/vim-go/pull/2685 is merged.
@bhcleek make sense. thank you so much for answering me!
Yep, rename will work within the scope of your workspace (instead of your package) in gopls/v0.3.0 (which is now released!).
It's awesome @stamblerre! Looking forward for it!
@bhcleek when do you intent to merge this PR?
Btw, I just test it. It works fine!! And there is no more .origin file!
Amazing!
I'll likely merge this weekend. I want to give people a few days to get vim-go v1.22 via master before diverging from the release again.
Given that GoRename _is_ working correctly within the bounds of the limitations of module mode with gopls, I'm closing this.
I don't have a reproducible test-case yet, but I wanted to highlight that I am seeing some strange behaviour with renaming that seems to be related to this issue (I have configured rename to use gopls and updated to the latest binary).
Say I have a struct X defined in package a and references in packages b and c.
If my cursor is on struct X in package a and I rename the struct, all references in that package, _including its tests_ get renamed, but _no references in packages b or c get renamed_.
If I instead hover over a reference to struct X in package b (which imports package a) and rename from there, it renames all references in package b, _and_ it renames the references and struct declaration in package a _however_ it does not rename the references in the tests of package a, nor does it change anything in package c.
Here is my (truncated) go env output from within the project:
GO111MODULE="on"
GOBIN=""
GOPATH="/Users/jean/.local/share/go"
GOROOT="/usr/local/Cellar/go/1.14.1/libexec"
GOMOD="/Users/jean/test-project/go.mod"
So I found this issue: https://github.com/golang/go/issues/32877
Which mentions running gopls rename from the workspace root. If I do that, things are working as expected:
gopls rename -w a/file.go:15:6 NewName
< lists all files in packagea a, b and c that got renamed as expected >
Is there some way we can make this work as expected with vim-go?
@bhcleek should this be reopened in light of the above comment? Invoking gopls rename manually is rough.
Most helpful comment
So I found this issue: https://github.com/golang/go/issues/32877
Which mentions running
gopls renamefrom the workspace root. If I do that, things are working as expected:Is there some way we can make this work as expected with vim-go?