diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 18:33:12 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:14 -0300 |
| commit | 505dedb2459e7b51cbdb0c066698c6e5596d19dd (patch) | |
| tree | 2f91a90b6889ca00817bbfa58b44af1403d1ec4b /src/locations.zig | |
| parent | 4a3c5a48224cf542429504e8728e10c802e1fd52 (diff) | |
| download | pardes-505dedb2459e7b51cbdb0c066698c6e5596d19dd.tar.gz pardes-505dedb2459e7b51cbdb0c066698c6e5596d19dd.zip | |
Bound preceding result context by its outermost tree-sitter declaration
Diffstat (limited to 'src/locations.zig')
| -rw-r--r-- | src/locations.zig | 16 |
1 files changed, 9 insertions, 7 deletions
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) { |
