Compare commits
4 commits
1788d4dfb2
...
90695e9dc6
Author | SHA1 | Date | |
---|---|---|---|
90695e9dc6 | |||
d5d7a9bb80 | |||
bc0745bc4b | |||
34000cccbf |
2 changed files with 18 additions and 7 deletions
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue