Skip to content

Commit 7a20eb6

Browse files
committed
fixup! feat(files): make file system actions LSP aware
Fix: join and checks within a single filter with AND and all the filters for a given server with OR
1 parent e8490cd commit 7a20eb6

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

lua/mini/files.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,7 +2731,7 @@ H.fs_actions_apply = function(fs_actions)
27312731
)
27322732
local filtered_delete = vim.tbl_filter(function(diff) return diff.action == 'delete' end, fs_actions)
27332733
local filtered_rename = vim.tbl_filter(
2734-
function(diff) return diff.action == 'rename' and not H.fs_is_present_path(diff.from) end,
2734+
function(diff) return diff.action == 'rename' and not H.fs_is_present_path(diff.to) end,
27352735
fs_actions
27362736
)
27372737

@@ -2787,15 +2787,16 @@ H.lsp_fs_hook = function(method, params)
27872787
local timeout = 1000
27882788
for _, client in ipairs(clients) do
27892789
local filters = client.server_capabilities.workspace.fileOperations[method].filters --[=[@as lsp.FileOperationFilter[]]=]
2790-
local matching_functions = {}
2790+
local grouped_matching_functions = {}
27912791
for _, filter in ipairs(filters) do
27922792
local ignore_case = filter.pattern.options and filter.pattern.options.ignoreCase
27932793
local glob = filter.pattern.glob
27942794
if ignore_case then glob = vim.fn.tolower(glob) end
27952795

2796+
local matching_functions = {}
27962797
table.insert(matching_functions, function(uri)
27972798
local path = vim.uri_to_fname(uri)
2798-
return vim.glob.to_lpeg(glob):match(path)
2799+
return vim.glob.to_lpeg(glob):match(path) ~= nil
27992800
end)
28002801
if filter.scheme then
28012802
table.insert(matching_functions, function(uri) return uri:find('^' .. filter.scheme .. ':') ~= nil end)
@@ -2808,18 +2809,25 @@ H.lsp_fs_hook = function(method, params)
28082809
if filter.pattern.matches == 'file' then return type == 'file' end
28092810
end)
28102811
end
2812+
table.insert(grouped_matching_functions, matching_functions)
28112813
end
28122814

28132815
local filtered_params = {
28142816
files = {},
28152817
}
28162818
for _, file in ipairs(params.files) do
28172819
local uri = file.uri or file.oldUri
2818-
local matches = true
2819-
for _, matching_function in ipairs(matching_functions) do
2820-
matches = matches and matching_function(uri)
2820+
local matches_any_filter = false
2821+
for _, matching_functions in ipairs(grouped_matching_functions) do
2822+
if not matches_any_filter then
2823+
local matches_current_filter = true
2824+
for _, matching_function in ipairs(matching_functions) do
2825+
matches_current_filter = matches_current_filter and matching_function(uri)
2826+
end
2827+
matches_any_filter = matches_any_filter or matches_current_filter
2828+
end
28212829
end
2822-
if matches then table.insert(filtered_params.files, file) end
2830+
if matches_any_filter then table.insert(filtered_params.files, file) end
28232831
end
28242832

28252833
if method:sub(1, 3) == 'did' then

0 commit comments

Comments
 (0)