Skip to content

Commit 56ae880

Browse files
committed
feat(lsp): locations regex_filter (closes #1209)
1 parent 93976e9 commit 56ae880

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

lua/fzf-lua/defaults.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ M.defaults.lsp = {
686686
file_icons = true and M._has_devicons,
687687
color_icons = true,
688688
git_icons = false,
689-
cwd_only = false,
690689
async_or_timeout = 5000,
691690
fzf_opts = { ["--multi"] = true },
692691
_actions = function() return M.globals.actions.files end,

lua/fzf-lua/providers/lsp.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ local function location_handler(opts, cb, _, result, ctx, _)
105105
-- here to accurately determine `jump_to_single_result` (#980)
106106
result = vim.tbl_filter(function(x)
107107
local item = vim.lsp.util.locations_to_items({ x }, encoding)[1]
108-
table.insert(items, item)
109-
if opts.cwd_only and not path.is_relative_to(item.filename, opts.cwd) then
108+
if (opts.cwd_only and not path.is_relative_to(item.filename, opts.cwd)) or
109+
(opts.regex_filter and not item.text:match(opts.regex_filter)) then
110110
return false
111111
end
112+
table.insert(items, item)
112113
return true
113114
end, result)
114115
-- Jump immediately if there is only one location
@@ -575,7 +576,7 @@ local normalize_lsp_opts = function(opts, cfg, __resume_key)
575576
-- required for relative paths presentation
576577
if not opts.cwd or #opts.cwd == 0 then
577578
opts.cwd = uv.cwd()
578-
else
579+
elseif opts.cwd_only == nil then
579580
opts.cwd_only = true
580581
end
581582

@@ -592,6 +593,7 @@ local function fzf_lsp_locations(opts, fn_contents)
592593
core.__CTX = nil
593594
return
594595
end
596+
opts = core.set_header(opts, opts.headers or { "cwd", "regex_filter" })
595597
return core.fzf_exec(opts.__contents, opts)
596598
end
597599

@@ -669,6 +671,7 @@ M.finder = function(opts)
669671
core.__CTX = nil
670672
return
671673
end
674+
opts = core.set_header(opts, opts.headers or { "cwd", "regex_filter" })
672675
opts = core.set_fzf_field_index(opts)
673676
return core.fzf_exec(contents, opts)
674677
end

0 commit comments

Comments
 (0)