Skip to content

Commit

Permalink
feat(lsp): locations regex_filter (closes #1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed May 21, 2024
1 parent 93976e9 commit 56ae880
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 0 additions & 1 deletion lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,6 @@ M.defaults.lsp = {
file_icons = true and M._has_devicons,
color_icons = true,
git_icons = false,
cwd_only = false,
async_or_timeout = 5000,
fzf_opts = { ["--multi"] = true },
_actions = function() return M.globals.actions.files end,
Expand Down
9 changes: 6 additions & 3 deletions lua/fzf-lua/providers/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ local function location_handler(opts, cb, _, result, ctx, _)
-- here to accurately determine `jump_to_single_result` (#980)
result = vim.tbl_filter(function(x)
local item = vim.lsp.util.locations_to_items({ x }, encoding)[1]
table.insert(items, item)
if opts.cwd_only and not path.is_relative_to(item.filename, opts.cwd) then
if (opts.cwd_only and not path.is_relative_to(item.filename, opts.cwd)) or
(opts.regex_filter and not item.text:match(opts.regex_filter)) then
return false
end
table.insert(items, item)
return true
end, result)
-- Jump immediately if there is only one location
Expand Down Expand Up @@ -575,7 +576,7 @@ local normalize_lsp_opts = function(opts, cfg, __resume_key)
-- required for relative paths presentation
if not opts.cwd or #opts.cwd == 0 then
opts.cwd = uv.cwd()
else
elseif opts.cwd_only == nil then
opts.cwd_only = true
end

Expand All @@ -592,6 +593,7 @@ local function fzf_lsp_locations(opts, fn_contents)
core.__CTX = nil
return
end
opts = core.set_header(opts, opts.headers or { "cwd", "regex_filter" })
return core.fzf_exec(opts.__contents, opts)
end

Expand Down Expand Up @@ -669,6 +671,7 @@ M.finder = function(opts)
core.__CTX = nil
return
end
opts = core.set_header(opts, opts.headers or { "cwd", "regex_filter" })
opts = core.set_fzf_field_index(opts)
return core.fzf_exec(contents, opts)
end
Expand Down

0 comments on commit 56ae880

Please sign in to comment.