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

[vim-go] could not determine the appropriate directory for gopls #3065

Closed
AugustusKwan opened this issue Oct 23, 2020 · 7 comments · Fixed by #3078
Closed

[vim-go] could not determine the appropriate directory for gopls #3065

AugustusKwan opened this issue Oct 23, 2020 · 7 comments · Fixed by #3078

Comments

@AugustusKwan
Copy link

Issue Description

When I try to open/edit a .go file, neovim has the error message '[vim-go] could not determine the appropriate directory for gopls'.
No Go completion message to select.Sometime it hangs for a while for loading something.

Configuration (MUST fill this out):

vim-go version:

Neovim 0.4.4

init.vim you used to reproduce:

vimrc
"Golang
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries','for':['go','vim-plug'],'tag':'*' }

let g:go_fmt_command = "goimports" " 格式化将默认的 gofmt 替换
let g:go_autodetect_gopath = 1
let g:go_list_type = "quickfix"

let g:go_version_warning = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_methods = 1
let g:go_highlight_generate_tags = 1

let g:godef_split=2

let g:go_def_mode='gopls'
let g:go_info_mode='gopls'

Vim version (first three lines from :version):

Neovim v0.4.4

Go version (go version):

Go 1.14.2

Go environment

Windows10 1909

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 24, 2020

Does this happen for you any go file that you try to open, or only some?

Are you using the linux subsystem?

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 24, 2020

Can you run go env GOMOD from the directory that contains the go file that you're trying to open and let me know what the output is?

@ghost
Copy link

ghost commented Oct 31, 2020

I get the same error. At some point vim-go adds the module directory to GOPATH: /home/xxx/your-module:/gopath and then tries to get the value of GOMOD by calling go env GOMOD, which responds $GOPATH/go.mod exists but should not. After that vim-go says: could not determine appropriate working directory for gopls.

@ghost
Copy link

ghost commented Oct 31, 2020

After some investigation, the culprit seems to be this line in my .vimrc:

let g:go_autodetect_gopath = 1

I commented it, and the error disappeared.

Perhaps vim-go shouldn't add a directory to GOPATH if the directory contains a go.mod file.

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 31, 2020

Do you have a src directory in your module?

bhcleek added a commit to bhcleek/vim-go that referenced this issue Oct 31, 2020
bhcleek added a commit to bhcleek/vim-go that referenced this issue Oct 31, 2020
bhcleek added a commit to bhcleek/vim-go that referenced this issue Oct 31, 2020
@ghost
Copy link

ghost commented Nov 1, 2020

Yes, I happen to have a src directory in my module.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 1, 2020

👍 if you're not using gb, godep, or similar, then you don't need g:go_autodetect_gopath to be set. I've added #3076 to address the underlying issue, but we should probably just remove g:go_autodetect_gopath support fully now that modules is out and well supported by the Go toolchain, because Go modules and vendoring obviate the need for tools like gb and godep and those tools were archived long ago.

bhcleek added a commit to bhcleek/vim-go that referenced this issue Nov 1, 2020
Remove support for g:go_autodetect_gopath; it was only necessary for
tools like gb and godep. Both of those were long ago archived and
there's no need for them now with Go modules and vendoring.

Fixes fatih#3065
bhcleek added a commit to bhcleek/vim-go that referenced this issue Nov 1, 2020
Remove support for g:go_autodetect_gopath; it was only necessary for
tools like gb and godep. Both of those were long ago archived and
there's no need for them now with Go modules and vendoring.

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