summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 22:43:18 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit383b60b79146937e12c82abaaca2ce213d210b7f (patch)
tree82fe9805ab85ef72fbc38fa56569632081a8964e /build.zig
parentf2b02c455f2bcdfb905a015eefbb630a28b4b12e (diff)
downloadpardes-383b60b79146937e12c82abaaca2ce213d210b7f.tar.gz
pardes-383b60b79146937e12c82abaaca2ce213d210b7f.zip
syntax: the highlight queries are filtered by the build, not in every compile: colorQuery kept each grammar's patterns whose captures pardes colours by scanning the 29 highlights.scm byte by byte at comptime, a quarter of a full recompile of the core (and again in each of the ~15 artifacts that import it); build.zig's treeSitter now runs the same filter once over the query it reads (grammar_manifest.colorQuery, a plain function, with Syn and synFor's capture-to-class table beside it, the one copy both the build and syntax.zig read), so ts_queries' <name>_highlights is the filtered query and Spec.query_src a field read; typst's supplement is the manifest's highlights_extra, appended before the filter as before; <name>_highlights_unfiltered is the whole query, for the test that the filter keeps every colour; a package that depends on pardes gets the same through library's treeSitter, for its own grammar set; proven byte-identical before the comptime path went (29 grammars, 28,398 filtered bytes of 79,678); core-test's forced full recompile 12.7-12.9 s wall / 17.5 s CPU to 9.7-10.1 s / 14.6 s; syntax snapshots unchanged; the changelog says so
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig8
1 files changed, 6 insertions, 2 deletions
diff --git a/build.zig b/build.zig
index 0e67b61e..c7604c62 100644
--- a/build.zig
+++ b/build.zig
@@ -2101,8 +2101,12 @@ fn treeSitter(b: *std.Build, io: std.Io, target: std.Build.ResolvedTarget, c_opt
(tree_sitter_grammars == .zig and g.tier == .zig))
grammar: {
const dep = b.lazyDependency(g.dep, .{}) orelse break :grammar;
- const query = configureRead(b, io, dep.builder.root, g.query, 0x100000) catch @panic("read " ++ g.name ++ " highlights");
- ts_queries.addOption([]const u8, g.name ++ "_highlights", query);
+ const upstream = configureRead(b, io, dep.builder.root, g.query, 0x100000) catch @panic("read " ++ g.name ++ " highlights");
+ // the patterns that colour, filtered here once and not in
+ // every compile, and the whole query, the filter's test's
+ const query = std.mem.concat(b.allocator, u8, &.{ upstream, g.highlights_extra }) catch @panic("OOM");
+ ts_queries.addOption([]const u8, g.name ++ "_highlights_unfiltered", query);
+ ts_queries.addOption([]const u8, g.name ++ "_highlights", grammar_manifest.colorQuery(query, b.allocator.alloc(u8, query.len) catch @panic("OOM")));
// helix's textobject queries, vendored (vendor/queries); a
// grammar without one gets none
const objects = configureRead(b, io, b.root, "vendor/queries/" ++ g.name ++ "/textobjects.scm", 0x100000) catch "";