diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 18:23:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:14 -0300 |
| commit | f3a9a1a9005024923f32e1acae5ecd509e9bbfd2 (patch) | |
| tree | 9a2ef0d4cf5eb70c90a6455a3a905f27888e5f05 /src/locations.zig | |
| parent | 0b6bd969ce9982aa7c8b31c38e64034d3d949b8e (diff) | |
| download | pardes-f3a9a1a9005024923f32e1acae5ecd509e9bbfd2.tar.gz pardes-f3a9a1a9005024923f32e1acae5ecd509e9bbfd2.zip | |
Show result declaration locations only on their first header line
Diffstat (limited to 'src/locations.zig')
| -rw-r--r-- | src/locations.zig | 16 |
1 files changed, 11 insertions, 5 deletions
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); } } } |
