How are you meant to implement discover_positions
?
#385
-
I have a C/CPP file the looks like this CTEST(suite_name, test_here1)
{
ASSERT_TRUE(true);
}
CTEST(suite_name, test_here2)
{
ASSERT_TRUE(false);
} The namespace is A proper tree should look like this
I tried writing a query like this local lib = require("neotest.lib")
local M = {}
function M.discover_positions(path)
local query = [[
(function_definition
declarator: (function_declarator
declarator: (identifier)
parameters: (parameter_list
.
(parameter_declaration
type: (type_identifier) @namespace.name) @namespace.definition
(parameter_declaration
type: (type_identifier)))))
(function_definition
declarator: (function_declarator
declarator: (identifier)
parameters: (parameter_list
.
(parameter_declaration
type: (type_identifier))
(parameter_declaration
type: (type_identifier) @test.name)))) @test.definition
]]
return lib.treesitter.parse_positions(path, query, {
require_namespaces = false,
})
end
return M But it creates a flattened tree like this:
I feel like I'm missing something simple. At the moment I'm close to saying "oh forget it" and writing the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Unfortunately the treesitter library is just meant for helper methods, it's not guaranteed to work for everyone. The problem here is that it assumes a file structure where child positions are within the scope of the parent which is not going to be the case with how your tests are defined where the suite name is just an argument. The gtest adapter had similar issues and it looks like they went with the manual tree building as well, maybe take a look and see if you can re-use some of their logic? https://github.com/alfaix/neotest-gtest/blob/main/lua/neotest-gtest/parse.lua |
Beta Was this translation helpful? Give feedback.
Unfortunately the treesitter library is just meant for helper methods, it's not guaranteed to work for everyone. The problem here is that it assumes a file structure where child positions are within the scope of the parent which is not going to be the case with how your tests are defined where the suite name is just an argument.
The gtest adapter had similar issues and it looks like they went with the manual tree building as well, maybe take a look and see if you can re-use some of their logic? https://github.com/alfaix/neotest-gtest/blob/main/lua/neotest-gtest/parse.lua