From 505dedb2459e7b51cbdb0c066698c6e5596d19dd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 15 Sep 2026 18:33:12 -0300 Subject: Bound preceding result context by its outermost tree-sitter declaration --- src/locations.zig | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/locations.zig b/src/locations.zig index 34d1ad14..0f580e34 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -192,16 +192,11 @@ pub fn format(p: *pardes.Pardes, dir: []const u8, input: []const u8, anchor: ?us for (pending.items[group_start..]) |*match| { const row = match.at.line -| 1; if (row >= count) continue; - const lo = row -| p.locations_config.context; - const hi = @min(count -| 1, row +| p.locations_config.context); - var context_row = lo; - while (context_row <= hi) : (context_row += 1) { - if (context_row == row) continue; - wanted[context_row] |= neighbor_context; - } + var enclosing_start: ?usize = null; for (declarations) |declaration| { if (declaration.start_line > row) break; if (declaration.end_line < row) continue; + enclosing_start = @min(enclosing_start orelse declaration.start_line, declaration.start_line); match.depth += 1; var header = declaration.start_line; while (header <= declaration.header_end_line and header < row) : (header += 1) { @@ -209,6 +204,13 @@ pub fn format(p: *pardes.Pardes, dir: []const u8, input: []const u8, anchor: ?us if (header == declaration.start_line) wanted[header] |= declaration_start; } } + const lo = @max(row -| p.locations_config.context, enclosing_start orelse 0); + const hi = @min(count -| 1, row +| p.locations_config.context); + var context_row = lo; + while (context_row <= hi) : (context_row += 1) { + if (context_row == row) continue; + wanted[context_row] |= neighbor_context; + } } for (wanted, 0..) |kind, row| { if (kind > 0) { -- cgit v1.3