From f6c804b6d6c58ca31c5ced64095c901e022f75f2 Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Thu, 11 Nov 2021 13:11:56 -0800 Subject: Revert "fix(gopls): resolve top-level go.mod as root_dir (#1399)" (#1410) This reverts commit 86abe8db3ad48271d7295b08cdbb923aa705644b. --- lua/lspconfig/gopls.lua | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'lua') diff --git a/lua/lspconfig/gopls.lua b/lua/lspconfig/gopls.lua index 90c1fde0..0126b127 100644 --- a/lua/lspconfig/gopls.lua +++ b/lua/lspconfig/gopls.lua @@ -6,32 +6,7 @@ configs.gopls = { cmd = { 'gopls' }, filetypes = { 'go', 'gomod' }, root_dir = function(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) + return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.git')(fname) end, }, docs = { -- cgit v1.2.3-70-g09d2