-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
#2673 Breaks gopls #2733
Comments
output of |
|
problem is why there does not get this value ..although we can add a nil check but it should be have a value. looks like only happen in windows |
In here: nvim-lspconfig/lua/lspconfig/server_configurations/gopls.lua Lines 11 to 14 in 654dd9e
It looks like local result = util.async_run_command 'go env GOMODCACHE'
if result and result[1] then
mod_cache = vim.trim(result[1])
else
mod_cache = vim.fn.system 'go env GOMODCACHE'
end I don't think it make sense to have a code path where mod_cache is nil anyway |
|
Sorry, I'm not sure what you are trying to say. |
fallback to sync will cause an performance issue . could you try the cmd like i comment on above ? |
Did not work :(. I did some more testing and this only happens when launching from msys2 environment, so some environment variable might be interfering. Does not happen when launching from cmd or using neovim qt. |
If it helps at all, I'm having the same problem with WSL2 using Ubuntu 22.04.2 LTS. go env GOMODCACHE
/home/gilad/go/pkg/mod |
I was using Window Terminal with Git Bash, and I was getting the same error. If I keep using Windows Terminal but use PowerShell instead of Bash, the error goes away. |
go package from snap has the same issue |
I'm having the same problem since updating to nvim v0.9.x, I temp fixed by setting the value of
In another station, which runs nvim v0.8.1, works fine, with the latest lspconfig update. I dont want to update |
Had same issue with |
Hey! Is there some outcome here? This is still open and even with the most recent changes and |
For anyone having this issue, you can overwrite the root_dir in your config: local util = require'lspconfig.util'
require'lspconfig'.gopls.setup {
-- ...some other setups
root_dir = function(fname)
-- see: https://github.com/neovim/nvim-lspconfig/issues/804
local mod_cache = vim.trim(vim.fn.system 'go env GOMODCACHE')
if fname:sub(1, #mod_cache) == mod_cache then
local clients = vim.lsp.get_active_clients { name = 'gopls' }
if #clients > 0 then
return clients[#clients].config.root_dir
end
end
return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.git')(fname)
end,
} or if you're still having issues: require'lspconfig'.gopls.setup {
-- ...some other setups
root_dir = function(fname)
return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.git')(fname)
end,
} |
For those who are experiencing the same issue, you can fix the error by manually providing the config with the proper value set for the variable go env GOMODCACHE
# for me result is:
# /root/go/pkg/mod Now, provide the configuration for -- loading module to provide config for a server following steps from guide here
-- https://github.com/neovim/nvim-lspconfig/blob/ede4114e1fd41acb121c70a27e1b026ac68c42d6/doc/lspconfig.txt#L326
local configs = require 'lspconfig.configs'
-- copy paste from
-- https://github.com/neovim/nvim-lspconfig/blob/ede4114e1fd41acb121c70a27e1b026ac68c42d6/lua/lspconfig/server_configurations/gopls.lua
local util = require 'lspconfig.util'
local async = require 'lspconfig.async'
-- -> the following line fixes it - mod_cache initially set to value that you've got from `go env GOMODCACHE` command
local mod_cache = '/root/go/pkg/mod'
-- setting the config for gopls, the contents below is also copy-paste from
-- https://github.com/neovim/nvim-lspconfig/blob/ede4114e1fd41acb121c70a27e1b026ac68c42d6/lua/lspconfig/server_configurations/gopls.lua
configs.gopls = {
default_config = {
cmd = { 'gopls' },
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
root_dir = function(fname)
-- see: https://github.com/neovim/nvim-lspconfig/issues/804
if not mod_cache then
local result = async.run_command 'go env GOMODCACHE'
if result and result[1] then
mod_cache = vim.trim(result[1])
end
end
if fname:sub(1, #mod_cache) == mod_cache then
local clients = vim.lsp.get_active_clients { name = 'gopls' }
if #clients > 0 then
return clients[#clients].config.root_dir
end
end
return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.git')(fname)
end,
single_file_support = true,
},
docs = {
description = [[
https://github.com/golang/tools/tree/master/gopls
Google's lsp server for golang.
]],
default_config = {
root_dir = [[root_pattern("go.work", "go.mod", ".git")]],
},
},
} |
svitiashchuk Thanks a lot! That worked indeed. Had this issue on windows 11 , even though on macOS there was no such issue |
~/.local/share/nvim/site/pack/packer/start/nvim-lspconfig/lua/lspconfig/server_configurations/gopls.lua just wanted to add this here, (linux). I had trouble finding the file location. (I use packer as my package manager. like others have the same setup on another machine. no issues. but when I booted this machine up it gave me this issue. thanks @svitiashchuk ! |
I'm having this issue too and have tried all the solutions here to no avail. This is only happening on nvim on windows. on my nvim on fedora and ubuntu i don't have this issue |
The issue was due to GOMODCACHE and is present in the gopls lsp: neovim/nvim-lspconfig#2733
@EJammy Thanks alot for providing the override snippet. Even though i dont understand all of it, it solved the issue. |
For the record, this is happening to me on an Ubuntu machine ( |
Happened for me also on Ubuntu 22.04 Noticed that go commands were not printing anything when redirected to file, this file was empty:
The issue was gone after removing go/gopls installed through ubuntu ( Possibly caused by https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1849753 - the symptoms are the same as in duplicate of this bug -- https://bugs.launchpad.net/snapd/+bug/1921110 |
Go language server failing due to not finding go modules dir. Add `root_dir` property to the setup function in Mason. References: neovim/nvim-lspconfig#2733 (comment)
So... is this still an issue? #2733 was a "partial" fix. |
Yeah, I just hit this, an updated nvim-lspconfig let gopls run but it wasn't fully working. I took hauserx's hint from above and reinstalled go without snap and everything worked perfectly, even on the older nvim-lspconfig. |
Description
mod_cache
does not seem to be set correctly with the performance improvement usingasync_run_command
. Introduced in 9a2cc56 (#2673). Reverting the changes fix this.Neovim version
NVIM v0.8.3
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compiled by runneradmin@fv-az171-224
Features: -acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM\sysinit.vim"
fall-back for $VIM: "C:/Program Files (x86)/nvim/share/nvim"
Run :checkhealth for more info
Nvim-lspconfig version
No response
Operating system and version
Windows 10
Affected language servers
gopls
Steps to reproduce
go mod init example/hello
nvim hello.go
Actual behavior
Expected behavior
No response
Minimal config
LSP log
The text was updated successfully, but these errors were encountered: