Skip to content

Commit e5312c3

Browse files
committed
fix: hack around glob issues in LSP rename operations (#386)
1 parent bbc0e67 commit e5312c3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lua/oil/lsp/workspace.lua

+16-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,21 @@ local function get_matching_paths(client, filters, paths)
7272
glob = glob:gsub("/", "\\")
7373
end
7474

75-
---@type nil|vim.lpeg.Pattern
76-
local glob_pattern = vim.glob and vim.glob.to_lpeg and vim.glob.to_lpeg(glob)
75+
---@type string|vim.lpeg.Pattern
76+
local glob_to_match = glob
77+
if vim.glob and vim.glob.to_lpeg then
78+
-- HACK around https://github.com/neovim/neovim/issues/28931
79+
-- find alternations and sort them by length to try to match the longest first
80+
glob = glob:gsub("{(.*)}", function(s)
81+
local pieces = vim.split(s, ",")
82+
table.sort(pieces, function(a, b)
83+
return a:len() > b:len()
84+
end)
85+
return "{" .. table.concat(pieces, ",") .. "}"
86+
end)
87+
88+
glob_to_match = vim.glob.to_lpeg(glob)
89+
end
7790
local matches = pattern.matches
7891
table.insert(match_fns, function(path)
7992
local is_dir = vim.fn.isdirectory(path) == 1
@@ -84,7 +97,7 @@ local function get_matching_paths(client, filters, paths)
8497
if ignore_case then
8598
path = path:lower()
8699
end
87-
return match_glob(glob_pattern or glob, path)
100+
return match_glob(glob_to_match, path)
88101
end)
89102
end
90103
end

0 commit comments

Comments
 (0)