Skip to content

Commit 7a8e61a

Browse files
committed
feat: util:root_pattern() search folder-first up
1 parent 699cf2c commit 7a8e61a

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

Diff for: lua/lspconfig/util.lua

+4-17
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,13 @@ function M.search_ancestors(startpath, func)
116116
end
117117
end
118118

119-
local function escape_wildcards(path)
120-
return path:gsub('([%[%]%?%*])', '\\%1')
121-
end
122-
123119
function M.root_pattern(...)
124-
local patterns = M.tbl_flatten { ... }
120+
local patterns = M.tbl_flatten({ ... })
125121
return function(startpath)
126-
startpath = M.strip_archive_subpath(startpath)
127-
for _, pattern in ipairs(patterns) do
128-
local match = M.search_ancestors(startpath, function(path)
129-
for _, p in ipairs(vim.fn.glob(table.concat({ escape_wildcards(path), pattern }, '/'), true, true)) do
130-
if vim.loop.fs_stat(p) then
131-
return path
132-
end
133-
end
134-
end)
122+
local match = vim.fs.find(patterns, { path = startpath, upward = true })[1]
135123

136-
if match ~= nil then
137-
return match
138-
end
124+
if match then
125+
return vim.fs.dirname(match)
139126
end
140127
end
141128
end

0 commit comments

Comments
 (0)