summaryrefslogtreecommitdiff
path: root/src/normal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 03:35:02 -0300
committerGabriel Schneider <[email protected]>2026-11-10 04:08:16 -0300
commitc40b95b8f938e01b7e8846bae53f16b0c1cd5654 (patch)
tree2d9c0ad034bcbb1ed1b1a27a94c79715bee40331 /src/normal.zig
parentc0ed5f823a37fb1b9b2300f53b23263bfc97a108 (diff)
downloadpardes-c40b95b8f938e01b7e8846bae53f16b0c1cd5654.tar.gz
pardes-c40b95b8f938e01b7e8846bae53f16b0c1cd5654.zip
syntax: a file's kept tree is told each edit (File.edit, ts_tree_edit) and the next parse starts from it, so a new line's indent in a 9k-line Zig file costs the 0.2 ms of what the edit touched, not the 47 ms of a parse anew (3.5 ms → 0.5 ms for 400 lines); not while a rollback copy holds the tree, which an edit in place would change under the copy: that one is left as it was and parsed anew, as is one whose revision moved without it (a twin's edit), by node_tree_edits, the revision its edits reach
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/normal.zig')
-rw-r--r--src/normal.zig6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/normal.zig b/src/normal.zig
index fc6da633..e95a5798 100644
--- a/src/normal.zig
+++ b/src/normal.zig
@@ -207,9 +207,11 @@ pub fn appendSearchLiteral(out: *std.ArrayList(u8), arena: std.mem.Allocator, te
/// kept until the next: never made again for a key that changed nothing.
pub fn fileTree(p: *Pardes, f: *panes.File.State) ?*anyopaque {
if (f.node_tree == null or f.node_tree_revision != f.revision) {
- if (f.node_tree) |old| syntax.freeTree(old);
- f.node_tree = syntax.parseTree(f.path, f.content);
+ const old = f.node_tree;
+ f.node_tree = syntax.parseTree(f.path, f.content, if (f.node_tree_edits == f.revision) old else null);
+ if (old) |o| syntax.freeTree(o);
f.node_tree_revision = f.revision;
+ f.node_tree_edits = f.revision;
for (f.node_history.items) |step| p.gpa.free(step.ranges);
f.node_history.clearRetainingCapacity();
}