fix: handle empty LSP glob patterns (#702)
* fix: handle empty LSP glob patterns * fix: use non-greedy pattern matching * lint: fix shadowed variable --------- Co-authored-by: Steven Arcangeli <506791+stevearc@users.noreply.github.com>
This commit is contained in:
parent
634049414b
commit
963c8d2c55
1 changed files with 18 additions and 9 deletions
|
|
@ -76,17 +76,26 @@ local function get_matching_paths(client, filters, paths)
|
||||||
---@type string|vim.lpeg.Pattern
|
---@type string|vim.lpeg.Pattern
|
||||||
local glob_to_match = glob
|
local glob_to_match = glob
|
||||||
if vim.glob and vim.glob.to_lpeg then
|
if vim.glob and vim.glob.to_lpeg then
|
||||||
-- HACK around https://github.com/neovim/neovim/issues/28931
|
glob = glob:gsub("{(.-)}", function(s)
|
||||||
-- find alternations and sort them by length to try to match the longest first
|
local patterns = vim.split(s, ",")
|
||||||
if vim.fn.has("nvim-0.11") == 0 then
|
local filtered = {}
|
||||||
glob = glob:gsub("{(.*)}", function(s)
|
for _, pat in ipairs(patterns) do
|
||||||
local pieces = vim.split(s, ",")
|
if pat ~= "" then
|
||||||
table.sort(pieces, function(a, b)
|
table.insert(filtered, pat)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #filtered == 0 then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
-- HACK around https://github.com/neovim/neovim/issues/28931
|
||||||
|
-- find alternations and sort them by length to try to match the longest first
|
||||||
|
if vim.fn.has("nvim-0.11") == 0 then
|
||||||
|
table.sort(filtered, function(a, b)
|
||||||
return a:len() > b:len()
|
return a:len() > b:len()
|
||||||
end)
|
end)
|
||||||
return "{" .. table.concat(pieces, ",") .. "}"
|
end
|
||||||
end)
|
return "{" .. table.concat(filtered, ",") .. "}"
|
||||||
end
|
end)
|
||||||
|
|
||||||
glob_to_match = vim.glob.to_lpeg(glob)
|
glob_to_match = vim.glob.to_lpeg(glob)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue