summaryrefslogtreecommitdiff
path: root/core/syntax.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 05:52:41 -0300
committerGabriel Schneider <[email protected]>2026-11-25 05:52:41 -0300
commit18043e845b39ac63dfe4416787e5cf6476ce8434 (patch)
tree0b28a690a5c671046b30498188e1567c164ccc88 /core/syntax.zig
parentc22b57e13fec318ff4df96fb07b096ea53e31122 (diff)
downloadpardes-18043e845b39ac63dfe4416787e5cf6476ce8434.tar.gz
pardes-18043e845b39ac63dfe4416787e5cf6476ce8434.zip
syntax, body_layer, panes, normal, root, Names, Pick: `]`'s painted targets in one query pass, kept while nothing moves, and Find's first key sorting only the rows it shows (walk UI P3 item 4, POLISH 19, F's and D's reports): (a) body_layer.targetLine ran the grammar's textobject query three times a frame while `]` or `[` showed (syntax.objectNext once each for function, comment, test); NOW syntax.objectNext finds any number of objects in one pass of the query (`objects`, `out`; the motion's one-object call in normal.zig unchanged in effect) and body_layer.treeTargets asks it once for the three, keeping the lines on the pane (Pane.targets, derived: never digested or dumped) while the text's revision, the caret's byte, the lines shown and the way stay, so a frame that paints them again asks nothing; paintTargets' drawing is untouched; (b) Names.rescore sorted every hit at every call (std.sort.pdq over 50,000 paths for a first key); NOW the best `reach` hits (`max_rows`, 200: what a query pane lists; a picker's cursor gone past them sorts further, Names.reachTo from Pick.key, and C-q's keep sorts its 2,000) are kept as a heap of the best so far and sorted, the rest after them in no order (O(n log k)); (c) the picker's preview read is left on the loop: measured, a 2,000-line file's tick and frame is 2.36M instructions, 285-531 us, under a twentieth of a 60 Hz frame (a read from a slow mount would still block it: not moved, said in the report); MEASURED (pardes-perf ReleaseFast tui, the same tree before and after this change): `]` painted, tick + frame, longest 11,066,602 instr (802 us) -> 4,677,637 (368 us, the frame that asks; the cached ones about the at-rest frame's 0.89M); pick key + frame (50,000 paths, first key) 58,751,637 (4,383 us) -> 41,394,164 (2,416 us, the rest is the scorer's); pick Down + frame 1,358,803 -> 1,356,960; pick preview tick + frame 2,357,436 -> 2,365,116; TESTS: core/Names.zig "Names keeps its best `reach` hits first in a full sort's order, the rest after them, and sorts further as a cursor goes past them"; the painted targets' and the motions' own tests unchanged; root.zig names Pane.targets among the kept-out fields; core-test 1064/1234 (170 skipped), behaviour-test 280/280
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
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.