diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 15:11:14 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-09-15 17:24:42 -0300 |
| commit | 7d75f5d7f1394a09c6a2cc42c2a9a60e6aef7b12 (patch) | |
| tree | b3102012a030560431a9360840e80a5e7316cb1e /src/syntax.zig | |
| parent | 40c19fd4f52d20df94c2dfa2d68102b89bd9d3f1 (diff) | |
| download | pardes-7d75f5d7f1394a09c6a2cc42c2a9a60e6aef7b12.tar.gz pardes-7d75f5d7f1394a09c6a2cc42c2a9a60e6aef7b12.zip | |
Mute result declaration context and show nesting after locations
Diffstat (limited to 'src/syntax.zig')
| -rw-r--r-- | src/syntax.zig | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/syntax.zig b/src/syntax.zig index 8209dc2c..bd6a64a0 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -690,6 +690,21 @@ pub fn highlightLocationRows(gpa: std.mem.Allocator, content: []const u8, rows: offset = @min(end + 1, content.len); } } + // Declaration context is intentionally muted by the output painter. Keep + // its source in parsing groups, then remove every syntax/style flag after + // complete-source snapshots have been applied. + if (comptime @hasField(@TypeOf(rows[0]), "declaration")) { + offset = 0; + for (rows) |row| { + if (offset >= content.len) break; + const end = std.mem.indexOfScalarPos(u8, content, offset, '\n') orelse content.len; + if (row.declaration) { + const source_start = offset + @min(row.code_start, end - offset); + @memset(styles[source_start..end], 0); + } + offset = @min(end + 1, content.len); + } + } if (!painted) { gpa.free(styles); return &.{}; @@ -1203,3 +1218,29 @@ test "syntax location context snapshots retain omitted multiline comment scope" try std.testing.expectEqual(@intFromEnum(Syn.comment), style); try std.testing.expectEqual(@intFromEnum(Syn.none), styles[0]); } + +test "syntax declaration locations clear snapshots without muting ordinary context" { + if (!enabled) return; + const gpa = std.testing.allocator; + start(gpa); + defer stop(); + const header = "pub fn run() void {"; + const content = "| \t" ++ header ++ "\n| \t const value = 42;\nfile.zig:3\t}\n"; + const snapshots = [_]u8{0xff} ** header.len; + const Row = struct { + path: []const u8 = "file.zig", + code_start: usize, + at: look.Spot, + colors: []const u8 = &.{}, + declaration: bool = false, + }; + const rows = [_]Row{ + .{ .code_start = 3, .at = .{ .line = 1 }, .colors = &snapshots, .declaration = true }, + .{ .code_start = 3, .at = .{ .line = 2 } }, + .{ .code_start = "file.zig:3\t".len, .at = .{ .line = 3 } }, + }; + const styles = try highlightLocationRows(gpa, content, &rows); + defer gpa.free(styles); + for (styles[3..][0..header.len]) |style| try std.testing.expectEqual(@as(u8, 0), style); + try std.testing.expectEqual(@intFromEnum(Syn.number), styles[std.mem.indexOf(u8, content, "42").?]); +} |
