From c5d96bec3d5279904525292ef933a985a974b017 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 28 Sep 2026 17:13:46 -0300 Subject: Zig has textobjects: helix's query, ported to the zig grammar pardes builds pardes builds maxxnino/tree-sitter-zig, whose node names are not those of the grammar helix's query targets, so the query is ported by hand (vendor/queries/zig, its MPL header saying it is modified and how): a function is a Decl holding an FnProto and a Block with pub beside it, struct/enum/union one ContainerDecl, parameters and arguments ParamDeclList and FnCallArguments, and comments come in three kinds. That grammar's comments take their line's newline, and a node ending in a newline is now taken without it, as helix's grammars have it. The replay test gains fifteen Zig cases from the installed hx; none walks call arguments, which the reference helix counts as parameters and 25.07.1's query does not. Co-Authored-By: Claude Opus 5.5 --- src/syntax.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/syntax.zig') diff --git a/src/syntax.zig b/src/syntax.zig index 3a83800b..4494945f 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -475,7 +475,10 @@ fn matchSpan(q: *const ts.Query, match: anytype, capture: u32, text: []const u8) const s: Span = .{ .from = c.node.startByte(), .to = c.node.endByte() }; span = if (span) |old| .{ .from = @min(old.from, s.from), .to = @max(old.to, s.to) } else s; }; - const found = span orelse return null; + var found = span orelse return null; + // a node that takes its line's newline (this zig grammar's comments) + // is the line without it, as helix's grammars have it + if (found.to > found.from + 1 and found.to <= text.len and text[found.to - 1] == '\n') found.to -= 1; const steps = q.predicatesForPattern(match.pattern_index); var i: usize = 0; while (i < steps.len) { -- cgit v1.3