summaryrefslogtreecommitdiff
path: root/core/syntax.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/syntax.zig')
-rw-r--r--core/syntax.zig39
1 files changed, 22 insertions, 17 deletions
diff --git a/core/syntax.zig b/core/syntax.zig
index a388573b..5c05300e 100644
--- a/core/syntax.zig
+++ b/core/syntax.zig
@@ -566,34 +566,39 @@ pub fn objectAt(path: []const u8, tree_ptr: *anyopaque, text: []const u8, object
/// `]f`/`[f` and kin: the next object starting after byte `at`, or the
/// previous one ending before it (helix goto_treesitter_object), from the
/// first of `.movement`, `.around`, `.inside` the query names.
-pub fn objectNext(path: []const u8, tree_ptr: *anyopaque, text: []const u8, object: Object, forward: bool, at: usize, within: ?[2]usize) ?Span {
- const q = objectQuery(path) orelse return null;
- var buf: [32]u8 = undefined;
- const capture = for ([_][]const u8{ "movement", "around", "inside" }) |kind| {
- const want = std.fmt.bufPrint(&buf, "{s}.{s}", .{ objectName(object), kind }) catch return null;
- if (captureId(q, want)) |id| break id;
- } else return null;
+pub fn objectNext(path: []const u8, tree_ptr: *anyopaque, text: []const u8, objects: []const Object, forward: bool, at: usize, within: ?[2]usize, out: []?Span) void {
+ @memset(out, null);
+ const q = objectQuery(path) orelse return;
+ // Each object's capture; one pass of the query finds them all (`]`'s
+ // three painted targets, body_layer.treeTargets).
+ var captures: [8]?u32 = @splat(null);
+ for (objects, captures[0..objects.len]) |object, *capture| {
+ var buf: [32]u8 = undefined;
+ capture.* = for ([_][]const u8{ "movement", "around", "inside" }) |kind| {
+ const want = std.fmt.bufPrint(&buf, "{s}.{s}", .{ objectName(object), kind }) catch break null;
+ if (captureId(q, want)) |id| break id;
+ } else null;
+ }
const tree: *const ts.Tree = @ptrCast(@alignCast(tree_ptr));
const cursor = ts.QueryCursor.create();
defer cursor.destroy();
// Only the objects these bytes hold (a body's rows shown): its painted
// targets (body_layer.paintTargets).
- if (within) |w| cursor.setByteRange(@intCast(w[0]), @intCast(w[1])) catch return null;
+ if (within) |w| cursor.setByteRange(@intCast(w[0]), @intCast(w[1])) catch return;
cursor.exec(q, tree.rootNode());
- var best: ?Span = null;
- while (cursor.nextMatch()) |match| {
- const s = matchSpan(q, match, capture, text) orelse continue;
+ while (cursor.nextMatch()) |match| for (captures[0..objects.len], out) |capture, *best| {
+ const s = matchSpan(q, match, capture orelse continue, text) orelse continue;
if (forward) {
if (s.from <= at) continue;
- if (best == null or s.from < best.?.from or (s.from == best.?.from and s.to > best.?.to)) best = s;
+ if (best.* == null or s.from < best.*.?.from or (s.from == best.*.?.from and s.to > best.*.?.to)) best.* = s;
} else {
if (s.to >= at) continue;
- if (best == null or s.to > best.?.to or (s.to == best.?.to and s.from < best.?.from)) best = s;
+ if (best.* == null or s.to > best.*.?.to or (s.to == best.*.?.to and s.from < best.*.?.from)) best.* = s;
}
- }
- const s = best orelse return null;
- if (s.from >= text.len or s.to >= text.len) return null;
- return s;
+ };
+ for (out) |*best| if (best.*) |s| if (s.from >= text.len or s.to >= text.len) {
+ best.* = null;
+ };
}
/// Owned source analysis. Both slices use the allocator passed to analyzeSource.