Cannot get Treesitter to detect Zig tests #294
Answered
by
lawrence-laz
lawrence-laz
asked this question in
Q&A
-
Hi, I am trying to write an adapter for Zig and currently have a very basic setup but can't seem to get treesitter parser to detect tests in a file. const std = @import("std");
const testing = std.testing;
pub fn main() !void {
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
try stdout.print("Run `zig build test` to run the tests.\n", .{});
try bw.flush(); // don't forget to flush!
}
test "my test" {
const foo = 2 + 2;
try testing.expectEqual(4, foo);
}
test "my other test" {
const foo = 2 + 2;
try testing.expectEqual(4, foo);
} Parsing script: local async = require("neotest.async")
local lib = require("neotest.lib")
local ts = lib.treesitter
async.run(function()
local parse_queries = [[
;;query
(TestDecl)
]]
local tree = ts.parse_positions("main.zig", parse_queries)
vim.print(tree:to_list())
end) Output:
Looking at the range it seems like the whole file is selected and only one entry is returned, while there are two test declarations. Am I doing something wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
lawrence-laz
Sep 26, 2023
Replies: 1 comment
-
Turns out I was missing capture groups: local async = require("neotest.async")
local lib = require("neotest.lib")
local ts = lib.treesitter
async.run(function()
local parse_queries = [[
;;query
(TestDecl
(STRINGLITERALSINGLE) @test.name
) @test.definition
]]
local tree = ts.parse_positions("main.zig", parse_queries)
vim.print(tree:to_list())
end) now returns:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lawrence-laz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out I was missing capture groups:
now returns: