aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/gopls.lua27
1 files changed, 26 insertions, 1 deletions
diff --git a/lua/lspconfig/gopls.lua b/lua/lspconfig/gopls.lua
index 0126b127..90c1fde0 100644
--- a/lua/lspconfig/gopls.lua
+++ b/lua/lspconfig/gopls.lua
@@ -6,7 +6,32 @@ configs.gopls = {
cmd = { 'gopls' },
filetypes = { 'go', 'gomod' },
root_dir = function(fname)
- return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.git')(fname)
+ -- First, search for go.work
+ local primary_root = util.root_pattern 'go.work'(fname)
+ if primary_root then
+ return primary_root
+ end
+
+ -- Then, search up the filesystem for go.mod
+ local go_mod_hierarchy = {}
+ if primary_root then
+ return primary_root
+ end
+ for path in util.path.iterate_parents(fname) do
+ for _, p in ipairs(vim.fn.glob(util.path.join(path, 'go.mod'), true, true)) do
+ if util.path.exists(p) then
+ table.insert(go_mod_hierarchy, p)
+ end
+ end
+ end
+
+ -- Take the top level go.mod
+ if #go_mod_hierarchy > 0 then
+ return go_mod_hierarchy[#go_mod_hierarchy]
+ end
+
+ -- Fallback to the git root
+ return util.find_git_ancestor(fname)
end,
},
docs = {