summaryrefslogtreecommitdiff
path: root/src/locations.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/locations.zig')
-rw-r--r--src/locations.zig16
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) {