summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig36
1 files changed, 20 insertions, 16 deletions
diff --git a/core/File.zig b/core/File.zig
index 0f9178ac..49d22fdc 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -60,35 +60,39 @@ pub const History = struct {
}
};
-/// Owned syntax results: a text's declarations at a revision.
+/// Owned syntax results: a text's declarations and symbols 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"} };
+ /// left (Query.ownerDecls, the Symbols source). The declarations and
+ /// symbols are made again from the text at a load (`reload`), with the
+ /// allocator that made them.
+ pub const replica = .{ .local = .{"allocator"}, .derived = .{ "declarations", "symbols" } };
allocator: ?std.mem.Allocator = null,
declarations: []syntax.ContextDeclaration = &.{},
+ symbols: []syntax.Symbol = &.{},
revision: ?u32 = null,
pub fn deinit(self: *ContextCache) void {
- if (self.allocator) |gpa| gpa.free(self.declarations);
+ if (self.allocator) |gpa| {
+ gpa.free(self.declarations);
+ gpa.free(self.symbols);
+ }
self.* = .{};
}
- /// A loaded text's (its revision the dump's): its declarations parsed
- /// again where they are of the text it has.
+ /// A loaded text's (its revision the dump's): its context parsed
+ /// again where it is 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);
+ self.replace(gpa, syntax.context(gpa, path, content) catch return, at);
}
- /// Takes ownership of declarations allocated by gpa.
- pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, declarations: []syntax.ContextDeclaration, revision: u32) void {
+ /// Takes ownership of a context allocated by gpa.
+ pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, made: syntax.Context, revision: u32) void {
self.deinit();
- self.* = .{ .allocator = gpa, .declarations = declarations, .revision = revision };
+ self.* = .{ .allocator = gpa, .declarations = made.declarations, .symbols = made.symbols, .revision = revision };
}
};
@@ -2490,8 +2494,7 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void {
pub fn refreshContext(p: *Pardes, pane: *Pane, f: *State) void {
if (!f.tree_context or !supportsContext(pane) or f.context.revision == f.revision) return;
// The file's declarations, in its lines (the layer's are none of it).
- const declarations = syntax.contextDeclarations(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return;
- f.context.replace(p.tree_sitter_gpa, declarations, f.revision);
+ f.context.replace(p.tree_sitter_gpa, syntax.context(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return, f.revision);
}
pub fn refreshHighlights(p: *Pardes) void {
@@ -3615,12 +3618,13 @@ test "context cache frees each allocation with its original allocator" {
defer std.testing.expect(second.deinit() == .ok) catch @panic("second allocator leaked");
var cache: ContextCache = .{};
defer cache.deinit();
- cache.replace(first.allocator(), try first.allocator().alloc(syntax.ContextDeclaration, 1), 1);
- cache.replace(second.allocator(), try second.allocator().alloc(syntax.ContextDeclaration, 2), 2);
+ cache.replace(first.allocator(), .{ .declarations = try first.allocator().alloc(syntax.ContextDeclaration, 1), .symbols = try first.allocator().alloc(syntax.Symbol, 1) }, 1);
+ cache.replace(second.allocator(), .{ .declarations = try second.allocator().alloc(syntax.ContextDeclaration, 2), .symbols = try second.allocator().alloc(syntax.Symbol, 2) }, 2);
try std.testing.expectEqual(@as(?u32, 2), cache.revision);
cache.deinit();
try std.testing.expect(cache.allocator == null);
try std.testing.expectEqual(@as(usize, 0), cache.declarations.len);
+ try std.testing.expectEqual(@as(usize, 0), cache.symbols.len);
}
/// The inks of row `row`'s first `n` text cells of pane `id` as `s` draws them.