Skip to content

Commit

Permalink
feat(lsp_live_workspace_symbols): better match highlights (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Feb 6, 2024
1 parent ba16437 commit 30d63fe
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lua/fzf-lua/providers/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,14 @@ local function symbol_handler(opts, cb, _, result, _, _)
if opts.fn_reload and type(opts.query) == "string" and #opts.query > 0 then
-- highlight exact matches with `live_workspace_symbols` (#1028)
local sym, text = entry.text:match("^(.+%])(.*)$")
entry.text = sym .. text:gsub(utils.lua_regex_escape(opts.query),
utils.ansi_codes.red(opts.query))
local pattern = "[" .. utils.lua_regex_escape(
opts.query:gsub("%a", function(x)
return string.upper(x) .. string.lower(x)
end)
) .. "]+"
entry.text = sym .. text:gsub(pattern, function(x)
return utils.ansi_codes.red(x)
end)
end
if M._sym2style then
local kind = entry.text:match("%[(.-)%]")
Expand All @@ -218,7 +224,12 @@ local function symbol_handler(opts, cb, _, result, _, _)
entry = make_entry.file(entry, opts)
if entry then
local align = 48 + mbicon_align + utils.ansi_escseq_len(symbol)
entry = string.format("%-" .. align .. "s%s%s", symbol, utils.nbsp, entry)
-- TODO: string.format %-{n}s fails with align > ~100?
-- entry = string.format("%-" .. align .. "s%s%s", symbol, utils.nbsp, entry)
if align > #symbol then
symbol = symbol .. string.rep(" ", align - #symbol)
end
entry = symbol .. utils.nbsp .. entry
cb(opts._fmt and opts._fmt.to and opts._fmt.to(entry, opts) or entry)
end
end
Expand Down

0 comments on commit 30d63fe

Please sign in to comment.