Compare commits
No commits in common. "1384eab9f2ef81733d5c17852e75ab30e7e27657" and "ea6b3e1af7d6793873284930d9e5d22500962c60" have entirely different histories.
1384eab9f2
...
ea6b3e1af7
2 changed files with 6 additions and 17 deletions
|
|
@ -173,7 +173,7 @@ fn ReturnType(comptime query_type: QueryType) type {
|
|||
|
||||
pub fn get(self: *Self, file_type: FileType, comptime query_type: QueryType) Error!ReturnType(query_type) {
|
||||
const query = try self.get_cached_query(try self.get_cache_entry(file_type, query_type));
|
||||
if (query != null) self.add_ref_locked();
|
||||
self.add_ref_locked();
|
||||
return switch (@typeInfo(ReturnType(query_type))) {
|
||||
.optional => query,
|
||||
else => query.?,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *Q
|
|||
const query = try query_cache.get(file_type, .highlights);
|
||||
errdefer query_cache.release(query, .highlights);
|
||||
const errors_query = try query_cache.get(file_type, .errors);
|
||||
errdefer query_cache.release(errors_query, .errors);
|
||||
errdefer query_cache.release(errors_query, .highlights);
|
||||
const injections = try query_cache.get(file_type, .injections);
|
||||
errdefer if (injections) |injections_| query_cache.release(injections_, .injections);
|
||||
const self = try allocator.create(Self);
|
||||
|
|
@ -85,7 +85,7 @@ pub fn destroy(self: *Self) void {
|
|||
if (self.content) |c| self.allocator.free(c);
|
||||
if (self.tree) |tree| tree.destroy();
|
||||
self.query_cache.release(self.query, .highlights);
|
||||
self.query_cache.release(self.errors_query, .errors);
|
||||
self.query_cache.release(self.errors_query, .highlights);
|
||||
if (self.injections) |injections| self.query_cache.release(injections, .injections);
|
||||
self.parser.destroy();
|
||||
self.allocator.destroy(self);
|
||||
|
|
@ -484,20 +484,9 @@ pub fn count_error_nodes(self: *const Self) usize {
|
|||
}
|
||||
|
||||
test "simple build and link test" {
|
||||
const io = std.testing.io;
|
||||
const gpa = std.testing.allocator;
|
||||
|
||||
const zig_file_type = @import("file_type.zig").get_by_name_static("zig") orelse return error.TestFailed;
|
||||
const query_cache = try QueryCache.create(io, gpa, .{});
|
||||
const query_cache = try QueryCache.create(std.testing.io, std.testing.allocator, .{});
|
||||
defer query_cache.deinit();
|
||||
const syntax = try create(zig_file_type, gpa, query_cache);
|
||||
defer syntax.destroy();
|
||||
|
||||
const content = try std.Io.Dir.readFileAlloc(.cwd(), io, "src/syntax.zig", gpa, .unlimited);
|
||||
defer gpa.free(content);
|
||||
try syntax.refresh_full(content);
|
||||
|
||||
try syntax.render({}, struct {
|
||||
fn cb(_: void, _: Range, _: []const u8, _: u32, _: usize, _: *const Node) error{Stop}!void {}
|
||||
}.cb, null);
|
||||
const syntax = try create(zig_file_type, std.testing.allocator, query_cache);
|
||||
syntax.destroy();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue