fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
16.02k stars 1.45k forks source link

Problems with gopls #2673

Closed claucece closed 4 years ago

claucece commented 4 years ago

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

Hi!

Thanks so much for this very nice plugin!

I have it installed with vundle with my vim. Two days ago, it started to have problems. Every time I open a go file it says:

vim-go: could not determine appropriate working directory for gopls,

and the plugin does not work.

It is defined as this on my .vimrc:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

Plugin 'fatih/vim-go'

call vundle#end()

Vim version (first three lines from :version):

VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 18 2019 03:49:48)

Go version (go version):

go version go1.13.3 darwin/amd64

Go environment

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/sofiaceli/Library/Caches/go-build"
GOENV="/Users/sofiaceli/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/sofiaceli/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_x/zpgwy4lx0bd735454_ql7j640000gn/T/go-build348605961=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls version

golang.org/x/tools/gopls v0.1.7 golang.org/x/tools/gopls@v0.1.7 h1:YwKf8t9h69++qCtVmc2q6fVuetFXmmu9LKoPMYLZid4=

What can be causing it?

bhcleek commented 4 years ago

What's the output of go env GOMOD when run in one of the directories that has a Go file that you're trying to edit when you see this error?

claucece commented 4 years ago

It fails on any go directory, but here you have two examples:

/Users/sofiaceli/go/src/github.com/otrv4/ed448/go.mod /Users/sofiaceli/go/src/github.com/alxdavids/voprf-poc/go/go.mod

bhcleek commented 4 years ago

Which version of vim-go are you using? What changed on your system 2 days ago?

I don't think it should be related, but I noticed your gopls version is pretty old. You probably want to update it (e.g. :GoUpdateBinaries gopls)

claucece commented 4 years ago

Which version of vim-go are you using?

How can I check this?

What changed on your system 2 days ago?

I uninstalled some plugins defined on the .vimrc.

I don't think it should be related, but I noticed your gopls version is pretty old. You probably want to update it (e.g. :GoUpdateBinaries gopls)

I did. Still fails:

golang.org/x/tools/gopls 0.2.2 golang.org/x/tools/gopls@v0.2.2 h1:ujGisyytgY1VGcmd66wIJ9+wVAfmodXj6daHM43HRXk=

bhcleek commented 4 years ago

How can I check this?

Because your vim-go is managed with Vundle, it should be a git clone; cd into the the location where Vundle is placing vim-go and run git rev-parse HEAD.

claucece commented 4 years ago

Because your vim-go is managed with Vundle, it should be a git clone; cd into the the location where Vundle is placing vim-go and run git rev-parse HEAD.

Oh, awesome! I shows up this: 025af24e79a5efe6981b8c02c1a314217d3c73cb

bhcleek commented 4 years ago

Can you add let g:go_echo_command_info=1 and try again? I'd like to know what :messages shows after you see the error.

claucece commented 4 years ago

It shows the same vim-go: could not determine appropriate working directory for gopls @bhcleek

bhcleek commented 4 years ago

:messages should output more than that; it should show some commands that were run.

claucece commented 4 years ago

This is what it shows:

Messages maintainer: Bram Moolenaar <Bram@vim.org>
"constant_time_test.go" 146L, 4902C
vim-go: could not determine appropriate working directory for gopls
bhcleek commented 4 years ago

I'm sorry, I gave you the wrong command. Can you add let g:go_debug=['shell-commands'] to your vimrc and try again?

FWIW, this code is relatively straightforward. The error you're seeing is coming from https://github.com/fatih/vim-go/blob/master/autoload/go/lsp.vim#L310-L314. Which is calling https://github.com/fatih/vim-go/blob/master/autoload/go/util.vim#L130-L133. The -1 is only returned from go#util#ModuleRoot when go#util#ExecInDir (https://github.com/fatih/vim-go/blob/master/autoload/go/util.vim#L130-L133) can't execute the command because the directory in which the buffer is is not a directory at all (e.g. the directory path doesn't exist) or when executing the command fails (in this case go env GOMOD).

Is the directory containing your code a symlink by chance?

bhcleek commented 4 years ago

I've tried duplicating this multiple ways without success.

Can you execute :echo isdirectory(expand('%:p:h')) on your system after you see the error and report the result?

claucece commented 4 years ago

After including let g:go_debug=['shell-commands']:

Messages maintainer: Bram Moolenaar <Bram@vim.org>
"constant_time.go" 91L, 3396C
vim-go: job command: ['/Users/sofiaceli/go/bin/gopls']
vim-go: shell command: '/Users/sofiaceli/go/bin/go' 'env' 'GOMOD'
vim-go: could not determine appropriate working directory for gopls

Is the directory containing your code a symlink by chance?

Yes, I know it is straightforward. I searched for it ;) As I said before, it happens on any golang repository located anywhere. None of them are a symlink.

After executing :echo isdirectory(expand('%:p:h')), the return is 1. ;)

bhcleek commented 4 years ago

It looks like you have a go command in $GOPATH/bin that is getting used, but based on your original post, I'd expect your go binary to be from homebrew.

What does /Users/sofiaceli/go/bin/go version output?

bhcleek commented 4 years ago

closed for lack of feedback

claucece commented 4 years ago

Hi, @bhcleek , Sorry for not giving the feedback. I switched to use: https://github.com/govim/govim, as there seemed to be no way of resolving it. Working with govim works super fine. Thanks!

dv29 commented 4 years ago

I'm facing the same issue when I try to load any go file anywhere on the system.

vim-go: job command: ['/home/tyson/go/bin/gopls']
vim-go: shell command: '/usr/local/go/bin/go' 'env' 'GOMOD'
vim-go: could not determine appropriate working directory for gopls

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tyson/.cache/go-build"
GOENV="/home/tyson/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH=":/home/tyson/project/compsci:/home/tyson/project/exercism/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/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-build646092929=/tmp/go-build -gno-record-gcc-switches"
dv29 commented 4 years ago

I debugged this issue and found that GOPATH=":/home/tyson/project/compsci:/home/tyson/project/exercism/go" the first value was an empty string as it was not being cleaned up in the code GOPATH=:, as a fix make sure your first path is not empty

kaydxh commented 4 years ago

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

Hi!

Thanks so much for this very nice plugin!

I have it installed with vundle with my vim. Two days ago, it started to have problems. Every time I open a go file it says:

vim-go: could not determine appropriate working directory for gopls,

and the plugin does not work.

It is defined as this on my .vimrc:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

Plugin 'fatih/vim-go'

call vundle#end()

Vim version (first three lines from :version):

VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 18 2019 03:49:48)

Go version (go version):

go version go1.13.3 darwin/amd64

Go environment

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/sofiaceli/Library/Caches/go-build"
GOENV="/Users/sofiaceli/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/sofiaceli/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_x/zpgwy4lx0bd735454_ql7j640000gn/T/go-build348605961=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls version

golang.org/x/tools/gopls v0.1.7 golang.org/x/tools/gopls@v0.1.7 h1:YwKf8t9h69++qCtVmc2q6fVuetFXmmu9LKoPMYLZid4=

What can be causing it?

I debugged this issue and found that go binary file is a linux platform format file in GOPATH, but I work on macbook. And I replace it by mac platform binary go file. It works ok