Skip to content

Commit fb6f4c4

Browse files
phanenibhagwan
authored andcommitted
fix(rg): respect opts.rg_glob; --iglob can handle directory
ripgrep behavior * `rg foo a/ b/a.c --iglob a.lua`: b/a.c is excluded * `rg foo a/ b/ --iglob a.lua`: b/a.c isn't excluded
1 parent bdf2273 commit fb6f4c4

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lua/fzf-lua/make_entry.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ local glob_filter = function(paths, globs)
246246
-- matchers = vim.tbl_map(vim.F.nil_wrap(vim.glob.to_lpeg), globs)
247247
if #matchers == 0 then return paths end
248248
return vim.tbl_filter(function(p)
249-
return vim.iter(matchers):all(function(m) return m:match_str(p) end)
249+
local stat = vim.uv.fs_stat(p) -- "--iglob" can filter directory correctly
250+
return (stat and stat.type == "directory") or
251+
vim.iter(matchers):all(function(m) return m:match_str(p) end)
250252
end, paths)
251253
end
252254

@@ -343,7 +345,7 @@ M.get_grep_cmd = function(opts, search_query, no_esc)
343345
for i, p in ipairs(search_paths) do
344346
search_paths[i] = path.relative_to(path.normalize(p), utils.cwd())
345347
end
346-
search_paths = glob_filter(search_paths, globs)
348+
search_paths = opts.rg_glob and glob_filter(search_paths, globs) or search_paths
347349
search_path = table.concat(vim.tbl_map(libuv.shellescape, search_paths), " ")
348350
if is_grep then
349351
-- grep requires adding `-r` to command as paths can be either file or directory

0 commit comments

Comments
 (0)