From efbfce341c9f546ca2a155a9316886fc1b80eace Mon Sep 17 00:00:00 2001 From: Connor Date: Mon, 23 Sep 2024 00:13:34 -0700 Subject: fix(gopls): fix nil error when go env GOMODCACHE returns nothing (#3316) --- lua/lspconfig/server_configurations/gopls.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/lspconfig/server_configurations/gopls.lua b/lua/lspconfig/server_configurations/gopls.lua index aceb38da..00df6f02 100644 --- a/lua/lspconfig/server_configurations/gopls.lua +++ b/lua/lspconfig/server_configurations/gopls.lua @@ -12,9 +12,11 @@ return { local result = 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 end - if fname:sub(1, #mod_cache) == mod_cache then + if mod_cache and fname:sub(1, #mod_cache) == mod_cache then local clients = util.get_lsp_clients { name = 'gopls' } if #clients > 0 then return clients[#clients].config.root_dir -- cgit v1.2.3-70-g09d2