summaryrefslogtreecommitdiff
path: root/src/File.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/File.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/File.zig')
-rw-r--r--src/File.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/File.zig b/src/File.zig
index 90711c9a..05e5271c 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -64,7 +64,7 @@ pub const State = struct {
/// What the replay digest leaves out (src/walk.zig): what is made again
/// from the text whenever it is wanted.
pub const replica = .{
- .derived = .{ "cap", "line_starts", "line_cap", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_history", "tables" },
+ .derived = .{ "cap", "line_starts", "line_cap", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_tree_edits", "node_history", "tables" },
// Big texts, dumped and sent by their hash (src/walk.zig). The
// text is written in place by `replace`, but never while a join
// sends it (memory.zig `pin`): then an edit puts a new buffer in
@@ -143,6 +143,10 @@ pub const State = struct {
/// one: `syntax.parseTree`'s, opaque here.
node_tree: ?*anyopaque = null,
node_tree_revision: u32 = 0,
+ /// The revision the tree's edits reach (`syntax.editTree`, told by
+ /// `edit` below): at `revision`, the next parse reuses it; else, a
+ /// revision it was not told of (a twin's edit, a reload), a parse anew.
+ node_tree_edits: u32 = 0,
/// helix's object_selections: what Alt-o grew from, for Alt-i to go back
/// to; gpa-owned ranges and the primary's index.
node_history: std.ArrayList(NodeStep) = .empty,
@@ -686,6 +690,13 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
f.saved_hash = std.hash.Wyhash.hash(0, f.content);
f.saved_len = f.content.len;
}
+ // The kept tree follows the edit (normal.fileTree parses with it), but
+ // not while a rollback copy holds it: an edit in place would change the
+ // copy's tree under it, so that one is left as it is and parsed anew.
+ if (f.node_tree) |tree| if (syntax.held_trees == null and f.node_tree_edits == f.revision) {
+ syntax.editTree(tree, f.content[0..off], f.content[off..][0..len], bytes);
+ f.node_tree_edits = f.revision +% 1;
+ };
var undo_gone = false;
if (fresh) |new| {
const old = textRoom(f);