summaryrefslogtreecommitdiff
path: root/src/syntax.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax.zig')
-rw-r--r--src/syntax.zig18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/syntax.zig b/src/syntax.zig
index 0d2fa291..bbab17fa 100644
--- a/src/syntax.zig
+++ b/src/syntax.zig
@@ -1,12 +1,13 @@
//! Tree-sitter syntax highlighting: one style byte per content byte, filled by
//! running each grammar's highlights.scm query (slurped at build time into the
-//! ts_queries options module). Grammar set is tiered: `minimal` (c, cpp, zig)
-//! compiles queries at startup; `full` adds ~23 languages lazily on first use.
+//! ts_queries options module). Grammar set is tiered: `zig`; `minimal` (c, cpp,
+//! zig); and `full`, which adds ~23 languages lazily on first use.
const std = @import("std");
const config = @import("pardes_config");
const tracy = @import("tracy.zig");
pub const enabled = config.syntax_highlighting;
+const zig_grammar = config.syntax_zig_grammar;
const minimal_grammars = config.syntax_minimal_grammars;
const full_grammars = config.syntax_full_grammars;
@@ -52,10 +53,13 @@ const Spec = struct {
compiled_query: ?*ts.Query = null,
};
+var zig_specs = if (zig_grammar) [_]Spec{
+ .{ .exts = &.{ ".zig", ".zon" }, .language = tree_sitter_zig, .query_src = ts_queries.zig_highlights },
+} else [_]Spec{};
+
var minimal_specs = if (minimal_grammars) [_]Spec{
.{ .exts = &.{ ".c", ".h" }, .language = tree_sitter_c, .query_src = ts_queries.c_highlights },
.{ .exts = &.{ ".cpp", ".cc", ".cxx", ".hpp", ".hh", ".hxx" }, .language = tree_sitter_cpp, .query_src = ts_queries.cpp_highlights },
- .{ .exts = &.{ ".zig", ".zon" }, .language = tree_sitter_zig, .query_src = ts_queries.zig_highlights },
} else [_]Spec{};
var full_specs = if (full_grammars) [_]Spec{
@@ -98,6 +102,11 @@ fn ensure(spec: *Spec) !Selected {
}
fn forExt(ext: []const u8) !?Selected {
+ for (&zig_specs) |*spec| {
+ for (spec.exts) |choice| {
+ if (std.ascii.eqlIgnoreCase(ext, choice)) return try ensure(spec);
+ }
+ }
for (&minimal_specs) |*spec| {
for (spec.exts) |choice| {
if (std.ascii.eqlIgnoreCase(ext, choice)) return try ensure(spec);
@@ -111,9 +120,10 @@ fn forExt(ext: []const u8) !?Selected {
return null;
}
-/// compile the minimal-tier queries eagerly so the first .zig/.c open is fast
+/// Compile the compact-tier queries eagerly so the first source open is fast.
pub fn compileStartupQueries() void {
if (!enabled) return;
+ for (&zig_specs) |*spec| _ = ensure(spec) catch {};
for (&minimal_specs) |*spec| _ = ensure(spec) catch {};
}