From f3a9a1a9005024923f32e1acae5ecd509e9bbfd2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 15 Sep 2026 18:23:06 -0300 Subject: Show result declaration locations only on their first header line --- src/locations.zig | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/locations.zig b/src/locations.zig index 45d72c57..34d1ad14 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -5,6 +5,9 @@ const syntax = @import("syntax.zig"); const filesystem = @import("fs.zig"); pub const Config = @import("locations_config.zig").Config; +const neighbor_context: u8 = 1; +const declaration_context: u8 = 2; +const declaration_start: u8 = 4; /// Legacy marked rows and hidden locations remain recognizable without metadata. /// Visible context locations are flush left and use Row.kind instead. pub fn isContextLine(line: []const u8) bool { @@ -194,24 +197,27 @@ pub fn format(p: *pardes.Pardes, dir: []const u8, input: []const u8, anchor: ?us var context_row = lo; while (context_row <= hi) : (context_row += 1) { if (context_row == row) continue; - wanted[context_row] |= 1; + wanted[context_row] |= neighbor_context; } for (declarations) |declaration| { if (declaration.start_line > row) break; if (declaration.end_line < row) continue; match.depth += 1; var header = declaration.start_line; - while (header <= declaration.header_end_line and header < row) : (header += 1) - wanted[header] |= 2; + while (header <= declaration.header_end_line and header < row) : (header += 1) { + wanted[header] |= declaration_context; + if (header == declaration.start_line) wanted[header] |= declaration_start; + } } } for (wanted, 0..) |kind, row| { if (kind > 0) { const line = source_lines.items[row]; const offset = @intFromPtr(line.ptr) - @intFromPtr(source.ptr); - const declaration = kind & 2 != 0; + const declaration = kind & declaration_context != 0; const colors = if (!declaration and offset + line.len <= source_colors.len) source_colors[offset..][0..line.len] else &.{}; - try appendContext(arena, &pending, path, line, row, declaration, !declaration or !p.locations_config.tslocations, colors); + const hidden = !declaration or !p.locations_config.tslocations or kind & declaration_start == 0; + try appendContext(arena, &pending, path, line, row, declaration, hidden, colors); } } } -- cgit v1.3