Skip to content

Commit 1606258

Browse files
address maintainer feedback: use glidesort and virtual text for definitions
1 parent 6beccbf commit 1606258

2 files changed

Lines changed: 9 additions & 21 deletions

File tree

crates/fff-core/src/grep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ fn collect_grep_results<'a>(
11531153
// Prioritize definition matches by sorting them to the top.
11541154
// Use a stable sort to maintain relative order within each category.
11551155
if options.classify_definitions {
1156-
all_matches.sort_by_key(|m| !m.is_definition);
1156+
crate::sort_buffer::sort_by_key_with_buffer(&mut all_matches, |m| !m.is_definition);
11571157
}
11581158

11591159
// If no file had any match, we searched the entire slice.

lua/fff/grep/grep_renderer.lua

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ local function render_match_line(item, ctx)
4848
local location = string.format(':%d:%d', item.line_number or 0, (item.col or 0) + 1)
4949
local separator = ' '
5050

51-
-- Add definition indicator if this is a definition
52-
local def_indicator = ''
53-
if item.is_definition then
54-
def_indicator = ' [def]'
55-
end
56-
5751
-- vim.json.decode may return Blobs for strings with NUL bytes; coerce to string.
5852
local raw_content = item.line_content
5953
if type(raw_content) ~= 'string' then raw_content = raw_content and tostring(raw_content) or '' end
@@ -81,13 +75,12 @@ local function render_match_line(item, ctx)
8175
content = vim.fn.strcharpart(content, 0, lo) .. ''
8276
end
8377

84-
local line = indent .. location .. separator .. content .. def_indicator
78+
local line = indent .. location .. separator .. content
8579
local padding = math.max(0, ctx.win_width - vim.fn.strdisplaywidth(line) + 5)
8680

8781
item._match_indent = #indent
8882
item._content_offset = prefix_display_w -- byte offset where content starts in the line
8983
item._trimmed_content = content -- trimmed content string for treesitter parsing
90-
item._def_indicator = def_indicator
9184

9285
return line .. string.rep(' ', padding)
9386
end
@@ -202,18 +195,13 @@ local function apply_match_highlights(item, ctx, item_idx, buf, ns_id, row, line
202195
end
203196
end
204197

205-
-- 7. Definition indicator highlight
206-
if item.is_definition and item._def_indicator and #item._def_indicator > 0 then
207-
local def_start = #line_content - #item._def_indicator - (math.max(0, ctx.win_width - vim.fn.strdisplaywidth(line_content) + 5))
208-
-- Actually, it's easier to find it in the string
209-
local s, e = line_content:find(' %[def%]$')
210-
if s then
211-
pcall(vim.api.nvim_buf_set_extmark, buf, ns_id, row, s - 1, {
212-
end_col = e,
213-
hl_group = config.hl.combo_header or 'Number',
214-
priority = 250,
215-
})
216-
end
198+
-- 7. Definition indicator as virtual text
199+
if item.is_definition then
200+
pcall(vim.api.nvim_buf_set_extmark, buf, ns_id, row, 0, {
201+
virt_text = { { ' [def]', config.hl.combo_header or 'Number' } },
202+
virt_text_pos = 'eol',
203+
priority = 250,
204+
})
217205
end
218206
end
219207

0 commit comments

Comments
 (0)