Update nvim config to 0.11.1 standards.
This commit is contained in:
parent
fe23a8c0df
commit
ae1489527c
16 changed files with 45 additions and 88 deletions
51
nvim/lsp/gopls.lua
Normal file
51
nvim/lsp/gopls.lua
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
local mod_cache = nil
|
||||
|
||||
return {
|
||||
cmd = { "gopls" },
|
||||
filetypes = { "go", "gomod", "gowork", "gotmpl" },
|
||||
settings = {
|
||||
gopls = {
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
},
|
||||
staticcheck = true,
|
||||
lintTool = "golangci-lint",
|
||||
},
|
||||
},
|
||||
root_dir = function(callback)
|
||||
local path = vim.fn.expand("%:p")
|
||||
if not path or path == "" then
|
||||
callback(nil)
|
||||
return
|
||||
end
|
||||
|
||||
-- Asynchronously fetch GOMODCACHE if not already set
|
||||
if not mod_cache then
|
||||
vim.system({ "go", "env", "GOMODCACHE" }, { text = true }, function(result)
|
||||
if result and result.code == 0 and result.stdout then
|
||||
mod_cache = vim.trim(result.stdout)
|
||||
else
|
||||
vim.notify("[gopls] Unable to fetch GOMODCACHE", vim.log.levels.WARN)
|
||||
mod_cache = nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Check if the file is in the module cache
|
||||
if mod_cache and path:sub(1, #mod_cache) == mod_cache then
|
||||
local clients = vim.lsp.get_clients({ name = "gopls" })
|
||||
if #clients > 0 then
|
||||
callback(clients[#clients].config.root_dir)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Fallback: Find project root markers
|
||||
local go_mod_root = vim.fs.find({ "go.work", "go.mod", ".git" }, { upward = true, path = path })[1]
|
||||
if go_mod_root then
|
||||
callback(vim.fs.dirname(go_mod_root))
|
||||
else
|
||||
callback(nil)
|
||||
end
|
||||
end,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue