Vim-go: GoDef doesn't work within go-module directory while passing in Package-Scoped-Var(defined and refered in different files)

Created on 15 May 2019  路  5Comments  路  Source: fatih/vim-go

What did you do? (required: The issue will be closed when not provided)

  1. mkdir demo1;cd demo1

  2. go mod init demo1

  3. echo 'package main
    import "fmt"
    func main() {
    fmt.Println(Str)
    }' > main.go

  4. echo 'package main
    var Str = "hello world,demo1!"' > def.go

  5. vim main.go

  6. PRESS gd or CTRL+] or :GoDef on the Str identifier

What did you expect to happen?

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

What happened instead?

error msg like below
vim-go: [searching declaration] FAIL

Configuration (MUST fill this out):

vim-go version:

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

Vim version (first three lines from :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):

go version go1.12.4 linux/amd64

Go environment

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"

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 setting g:go_def_mode to 'gopls'.

All 5 comments

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 setting g:go_def_mode to '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 setting g:go_def_mode to '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??

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MattFlower picture MattFlower  路  4Comments

andrejvanderzee picture andrejvanderzee  路  3Comments

derekchiang picture derekchiang  路  3Comments

zhangjing picture zhangjing  路  3Comments

Michael-F-Ellis picture Michael-F-Ellis  路  3Comments