diff options
Diffstat (limited to 'core/File.zig')
| -rw-r--r-- | core/File.zig | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/core/File.zig b/core/File.zig index 020985da..75d8049b 100644 --- a/core/File.zig +++ b/core/File.zig @@ -59,8 +59,13 @@ pub const History = struct { } }; -/// Owned syntax results. Excluded from dumps as State.context is derived. +/// Owned syntax results: a text's declarations at a revision. pub const ContextCache = struct { + /// Its revision is dumped and digested: a worker's parse is an input, + /// which a client joined since never saw, and a step reads what it + /// left (Query.ownerDecls). The declarations are made again from the + /// text at a load (`reload`), with the allocator that made them. + pub const replica = .{ .local = .{"allocator"}, .derived = .{"declarations"} }; allocator: ?std.mem.Allocator = null, declarations: []syntax.ContextDeclaration = &.{}, revision: ?u32 = null, @@ -70,6 +75,15 @@ pub const ContextCache = struct { self.* = .{}; } + /// A loaded text's (its revision the dump's): its declarations parsed + /// again where they are of the text it has. + pub fn reload(self: *ContextCache, gpa: std.mem.Allocator, path: []const u8, content: []const u8, revision: u32) void { + const at = self.revision orelse return; + if (at != revision) return; + const declarations = syntax.contextDeclarations(gpa, path, content) catch return; + self.replace(gpa, declarations, at); + } + /// Takes ownership of declarations allocated by gpa. pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, declarations: []syntax.ContextDeclaration, revision: u32) void { self.deinit(); @@ -83,7 +97,7 @@ pub const State = struct { /// from the text whenever it is wanted. // Syntax caches must not load through the dump loader's core allocator. pub const replica = .{ - .derived = .{ "cap", "line_starts", "line_cap", "highlights", "highlight_start", "syntax_dirty", "context", "node_tree", "node_tree_revision", "node_tree_edits", "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 (core/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 |
