Skip to content

Commit 6f18571

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

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
@@ -2740,7 +2740,7 @@ H.fs_actions_apply = function(fs_actions)
27402740
)
27412741
local filtered_delete = vim.tbl_filter(function(diff) return diff.action == 'delete' end, fs_actions)
27422742
local filtered_rename = vim.tbl_filter(
2743-
function(diff) return diff.action == 'rename' and not H.fs_is_present_path(diff.from) end,
2743+
function(diff) return diff.action == 'rename' and not H.fs_is_present_path(diff.to) end,
27442744
fs_actions
27452745
)
27462746

@@ -2796,15 +2796,16 @@ H.lsp_fs_hook = function(method, params)
27962796
local timeout = 1000
27972797
for _, client in ipairs(clients) do
27982798
local filters = client.server_capabilities.workspace.fileOperations[method].filters --[=[@as lsp.FileOperationFilter[]]=]
2799-
local matching_functions = {}
2799+
local grouped_matching_functions = {}
28002800
for _, filter in ipairs(filters) do
28012801
local ignore_case = filter.pattern.options and filter.pattern.options.ignoreCase
28022802
local glob = filter.pattern.glob
28032803
if ignore_case then glob = vim.fn.tolower(glob) end
28042804

2805+
local matching_functions = {}
28052806
table.insert(matching_functions, function(uri)
28062807
local path = vim.uri_to_fname(uri)
2807-
return vim.glob.to_lpeg(glob):match(path)
2808+
return vim.glob.to_lpeg(glob):match(path) ~= nil
28082809
end)
28092810
if filter.scheme then
28102811
table.insert(matching_functions, function(uri) return uri:find('^' .. filter.scheme .. ':') ~= nil end)
@@ -2817,18 +2818,25 @@ H.lsp_fs_hook = function(method, params)
28172818
if filter.pattern.matches == 'file' then return type == 'file' end
28182819
end)
28192820
end
2821+
table.insert(grouped_matching_functions, matching_functions)
28202822
end
28212823

28222824
local filtered_params = {
28232825
files = {},
28242826
}
28252827
for _, file in ipairs(params.files) do
28262828
local uri = file.uri or file.oldUri
2827-
local matches = true
2828-
for _, matching_function in ipairs(matching_functions) do
2829-
matches = matches and matching_function(uri)
2829+
local matches_any_filter = false
2830+
for _, matching_functions in ipairs(grouped_matching_functions) do
2831+
if not matches_any_filter then
2832+
local matches_current_filter = true
2833+
for _, matching_function in ipairs(matching_functions) do
2834+
matches_current_filter = matches_current_filter and matching_function(uri)
2835+
end
2836+
matches_any_filter = matches_any_filter or matches_current_filter
2837+
end
28302838
end
2831-
if matches then table.insert(filtered_params.files, file) end
2839+
if matches_any_filter then table.insert(filtered_params.files, file) end
28322840
end
28332841

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

0 commit comments

Comments
 (0)