Compare commits

..

No commits in common. "5bc4bcba1552a597d1a6a1f3bf8433ba710b6a90" and "7b1fd3a97f00aba3a95cc65b95f34162347ed1ea" have entirely different histories.

3 changed files with 3 additions and 39 deletions

View file

@ -182,29 +182,11 @@ pub fn build(b: *std.Build) void {
}, },
}); });
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/syntax.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "build_options", .module = options_mod },
.{ .name = "cbor", .module = cbor_dep.module("cbor") },
.{ .name = "treez", .module = tree_sitter_dep.module("treez") },
},
}),
});
if (use_tree_sitter) { if (use_tree_sitter) {
const ts_bin_query_gen_step = b.addRunArtifact(ts_bin_query_gen); const ts_bin_query_gen_step = b.addRunArtifact(ts_bin_query_gen);
const output = ts_bin_query_gen_step.addOutputFileArg("bin_queries.cbor"); const output = ts_bin_query_gen_step.addOutputFileArg("bin_queries.cbor");
syntax_mod.addAnonymousImport("syntax_bin_queries", .{ .root_source_file = output }); syntax_mod.addAnonymousImport("syntax_bin_queries", .{ .root_source_file = output });
tests.root_module.addAnonymousImport("syntax_bin_queries", .{ .root_source_file = output });
} }
const test_run_cmd = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&test_run_cmd.step);
} }
fn ts_queryfile(b: *std.Build, dep: *std.Build.Dependency, bin_gen: *std.Build.Step.Compile, comptime sub_path: []const u8) void { fn ts_queryfile(b: *std.Build, dep: *std.Build.Dependency, bin_gen: *std.Build.Step.Compile, comptime sub_path: []const u8) void {

View file

@ -171,7 +171,7 @@ fn ReturnType(comptime query_type: QueryType) type {
pub fn get(self: *Self, file_type: FileType, comptime query_type: QueryType) Error!ReturnType(query_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)); 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))) { return switch (@typeInfo(ReturnType(query_type))) {
.optional => |_| query, .optional => |_| query,
else => query.?, else => query.?,

View file

@ -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); const query = try query_cache.get(file_type, .highlights);
errdefer query_cache.release(query, .highlights); errdefer query_cache.release(query, .highlights);
const errors_query = try query_cache.get(file_type, .errors); 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); const injections = try query_cache.get(file_type, .injections);
errdefer if (injections) |injections_| query_cache.release(injections_, .injections); errdefer if (injections) |injections_| query_cache.release(injections_, .injections);
const self = try allocator.create(Self); 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.content) |c| self.allocator.free(c);
if (self.tree) |tree| tree.destroy(); if (self.tree) |tree| tree.destroy();
self.query_cache.release(self.query, .highlights); 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); if (self.injections) |injections| self.query_cache.release(injections, .injections);
self.parser.destroy(); self.parser.destroy();
self.allocator.destroy(self); self.allocator.destroy(self);
@ -482,21 +482,3 @@ pub fn count_error_nodes(self: *const Self) usize {
}; };
return error_count; return error_count;
} }
test "simple build and link test" {
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(gpa, .{});
defer query_cache.deinit();
const syntax = try create(zig_file_type, gpa, query_cache);
defer syntax.destroy();
const content = try std.fs.cwd().readFileAlloc(gpa, "src/syntax.zig", std.math.maxInt(usize));
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);
}