Compare commits

...

4 commits

Author SHA1 Message Date
90695e9dc6
fix: destroy QueryCache.CacheEntry objects on clean-up 2025-03-19 15:32:40 +01:00
d5d7a9bb80
Merge flow-syntax commit 'bc0745bc4b' 2025-03-19 15:26:57 +01:00
bc0745bc4b Squashed 'src/syntax/' changes from d5c1cd2a..80ceadcf
80ceadcf fix IB in cache
2d29a6ba feat: allow parallel loading of tree-sitter query cache entries
ea00711e feat: add caching of tree-sitter query objects
149a7fc5 fix: do not parse tree-sitter queries twice
788000af Merge commit '77a69410b8' into zig-0.14
0efed0ee Merge branch 'master' into zig-0.14
31f174d6 Merge branch 'master' into zig-0.14
a9d8d26f Merge branch 'master' into zig-0.14

git-subtree-dir: src/syntax
git-subtree-split: 80ceadcff90b431378c23ea6c01b9b7c8b7c7ca5
2025-03-19 15:24:46 +01:00
34000cccbf
fix: remove arbitrary limit to command buffer size 2025-03-18 21:41:19 +01:00
2 changed files with 18 additions and 7 deletions

View file

@ -13,10 +13,14 @@ pub const Context = struct {
args: tp.message = .{},
pub fn fmt(value: anytype) Context {
return .{ .args = tp.message.fmtbuf(&context_buffer, value) catch @panic("command.Context.fmt failed") };
context_buffer.clearRetainingCapacity();
cbor.writeValue(context_buffer.writer(), value) catch @panic("command.Context.fmt failed");
return .{ .args = .{ .buf = context_buffer.items } };
}
};
threadlocal var context_buffer: [tp.max_message_size]u8 = undefined;
const context_buffer_allocator = std.heap.c_allocator;
threadlocal var context_buffer: std.ArrayList(u8) = std.ArrayList(u8).init(context_buffer_allocator);
pub const fmt = Context.fmt;
const Vtable = struct {

View file

@ -13,8 +13,8 @@ const Query = treez.Query;
allocator: std.mem.Allocator,
mutex: ?std.Thread.Mutex,
highlights: std.StringHashMapUnmanaged(CacheEntry) = .{},
injections: std.StringHashMapUnmanaged(CacheEntry) = .{},
highlights: std.StringHashMapUnmanaged(*CacheEntry) = .{},
injections: std.StringHashMapUnmanaged(*CacheEntry) = .{},
ref_count: usize = 1,
const CacheEntry = struct {
@ -75,11 +75,13 @@ fn release_ref_unlocked_and_maybe_destroy(self: *Self) void {
while (iter_highlights.next()) |p| {
self.allocator.free(p.key_ptr.*);
if (p.value_ptr.*.query) |q| q.destroy();
self.allocator.destroy(p.value_ptr.*);
}
var iter_injections = self.injections.iterator();
while (iter_injections.next()) |p| {
self.allocator.free(p.key_ptr.*);
if (p.value_ptr.*.query) |q| q.destroy();
self.allocator.destroy(p.value_ptr.*);
}
self.highlights.deinit(self.allocator);
self.injections.deinit(self.allocator);
@ -95,21 +97,26 @@ fn get_cache_entry(self: *Self, file_type: *const FileType, comptime query_type:
.injections => &self.injections,
};
return if (hash.getPtr(file_type.name)) |entry| entry else blk: {
return if (hash.get(file_type.name)) |entry| entry else blk: {
const entry_ = try hash.getOrPut(self.allocator, try self.allocator.dupe(u8, file_type.name));
entry_.value_ptr.* = .{
const q = try self.allocator.create(CacheEntry);
q.* = .{
.query = null,
.mutex = if (self.mutex) |_| .{} else null,
.file_type = file_type,
.query_type = query_type,
};
break :blk entry_.value_ptr;
entry_.value_ptr.* = q;
break :blk q;
};
}
fn get_cached_query(_: *Self, entry: *CacheEntry) QueryParseError!?*Query {
if (entry.mutex) |*mtx| mtx.lock();
defer if (entry.mutex) |*mtx| mtx.unlock();
return if (entry.query) |query| query else blk: {
const lang = entry.file_type.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{entry.file_type.name});
entry.query = try Query.create(lang, switch (entry.query_type) {