mkdir demo1;cd demo1
go mod init demo1
echo 'package main
import "fmt"
func main() {
fmt.Println(Str)
}' > main.go
echo 'package main
var Str = "hello world,demo1!"' > def.go
vim main.go
PRESS gd or CTRL+] or :GoDef on the Str identifier
I expected that vim would jump to _def.go_ and move cursor to line 2.
I have noticed that go-module support has been released since v1.19
error msg like below
vim-go: [searching declaration] FAIL
v1.20
vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):I just followed the Install Step and installed vim-go on a clear .vimrc
:version):VIM - Vi IMproved 8.1 (2018 May 18, compiled Jun 27 2018 20:28:03)
Linux version
Included patches: 1
go version):go version go1.12.4 linux/amd64
go env Output:
GOARCH="amd64"
GOBIN=""
GOCACHE="/export/mytest/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/export/mytest/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/export/mytest/demo1/go.mod"
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-build318077938=/tmp/go-build -gno-record-gcc-switches"
Have you run :GoInstallBinaries? If it has been a while since you did, then please run :GoUpdateBinaries. Finally, if all the binaries are updated, try setting g:go_def_mode to 'gopls'.
Have you run
:GoInstallBinaries? If it has been a while since you did, then please run:GoUpdateBinaries. Finally, if all the binaries are updated, try settingg:go_def_modeto'gopls'.
Setting g:go_def_mode to 'gopls' works! thx!
But my project which was placed OUTSIDE GOPATH failed to :GoDef with an error:
vim-go: no object for ident XXX.
(I have set g:go_autodetect_gopath = 1 before)
I wonder maybe they conflict with each other??
Have you run
:GoInstallBinaries? If it has been a while since you did, then please run:GoUpdateBinaries. Finally, if all the binaries are updated, try settingg:go_def_modeto'gopls'.Setting
g:go_def_modeto'gopls'works! thx!
But my project which was placed OUTSIDE GOPATH failed to:GoDefwith an error:
vim-go: no object for ident XXX.
(I have setg:go_autodetect_gopath = 1before)
I wonder maybe they conflict with each other??
I have read the script of go#def#Jump and have an answer.
It seems to be my job to determine when and which go_def_mode to use.
I'm trying to configure my .vimrc to make it work as before.
gopls should work for module mode, too. Be sure there's a go.mod file available.
fwiw, I tried this with g:go_def_mod_mode='godef' and it works in both GOPATH mode and in module mode. It's only guru that has a problem in module mode, but that's to be expected, as guru is not away of modules.
Most helpful comment
Have you run
:GoInstallBinaries? If it has been a while since you did, then please run:GoUpdateBinaries. Finally, if all the binaries are updated, try settingg:go_def_modeto'gopls'.