Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gopls code completion doesn't work in module mode when the current working directory is at or below a module root #2263

Closed
thekvs opened this issue May 4, 2019 · 1 comment · Fixed by #2264

Comments

@thekvs
Copy link

thekvs commented May 4, 2019

What did you do?

Issue described here: microsoft/vscode-go#2490
vim-go also has it.

What did you expect to happen?

Working code completion with gopls in multi-language project.

What happened instead?

Code completion only works when I start vim session from the folder with go.mod/go.sum files.

Configuration:

  • vim-go version: 2c1a85b

  • vimrc you used to reproduce:

call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go'
call plug#end()

let g:go_bin_path=$HOME."/.local/bin"
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
  • Vim version (first three lines from :version):
VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 30 2019 09:57:35)
Included patches: 1-1239
Modified by [email protected]
  • Go version (go version): go version go1.11.5 linux/amd64

  • Go environment (go env):

GOARCH="amd64"
GOBIN=""
GOCACHE="/mnt/disk2/home/kvs/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/mnt/disk2/home/kvs/work/devel/gocode"
GOPROXY=""
GORACE=""
GOROOT="/opt/go"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
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-build929123903=/tmp/go-build -gno-record-gcc-switches"
@bhcleek
Copy link
Collaborator

bhcleek commented May 4, 2019

This is working as intended for now. When you open the first Go file, your working directory should be either within $GOPATH or in a Go module directory. You can make sure that's the case by doing cd or lcd to change to your Go module's directory before opening a Go file.

This may change in the future; I'm considering making it so that each tab in Vim can use its own gopls server and probably autodetect the module directory when in module mode.

@bhcleek bhcleek changed the title gopls code completion doesn't work in multi-language project gopls code completion doesn't work in module mode when the current working directory at or below a module root May 4, 2019
bhcleek added a commit to bhcleek/vim-go that referenced this issue May 4, 2019
Set the working directory of gopls based on the value of GOMOD. When in
GOPATH mode, the value of Vim's working directory will be used.

Fixes fatih#2263
@bhcleek bhcleek changed the title gopls code completion doesn't work in module mode when the current working directory at or below a module root gopls code completion doesn't work in module mode when the current working directory is at or below a module root May 4, 2019
bhcleek added a commit to bhcleek/vim-go that referenced this issue May 4, 2019
Set the working directory of gopls based on the value of GOMOD. When in
GOPATH mode, the value of Vim's working directory will be used.

Fixes fatih#2263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants