Skip to content

Commit 3a98276

Browse files
authored
feat: replace fast_parse (#42)
* feat: replace fast_parse * fix: directory filtering (#43)
1 parent 796e71f commit 3a98276

File tree

4 files changed

+37
-41
lines changed

4 files changed

+37
-41
lines changed

lua/neotest-vstest/init.lua

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ local function create_adapter(config)
105105
local dotnet_utils = require("neotest-vstest.dotnet_utils")
106106
local client_discovery = require("neotest-vstest.client")
107107

108+
logger.trace("neotest-vstest: checking if file is test file: " .. file_path)
109+
108110
local isDotnetFile = (vim.endswith(file_path, ".csproj") or vim.endswith(file_path, ".fsproj"))
109111
or (vim.endswith(file_path, ".cs") or vim.endswith(file_path, ".fs"))
110112

@@ -127,50 +129,42 @@ local function create_adapter(config)
127129

128130
function DotnetNeotestAdapter.filter_dir(name, rel_path, root)
129131
local dotnet_utils = require("neotest-vstest.dotnet_utils")
132+
local logger = require("neotest.logging")
133+
logger.trace("neotest-vstest: filtering dir", name, rel_path, root)
130134

131135
if name == "bin" or name == "obj" then
132136
return false
133137
end
134138

135-
local project_dir
136-
137139
-- Filter out directories that are not part of the solution (if there is a solution)
138140
local fullpath = vim.fs.joinpath(root, rel_path)
139141
if solution_dir then
140-
project_dir = vim.fs.root(fullpath, function(path, _)
142+
local solution_info = dotnet_utils.get_solution_info(solution)
143+
local project_files = vim.fs.find(function(path, _)
141144
return path:match("%.[cf]sproj$")
142-
end)
143-
else
144-
for dir in vim.fs.parents(fullpath) do
145-
for filename in vim.fs.dir(dir) do
146-
if filename:match("%.[cf]sproj$") then
147-
project_dir = dir
148-
break
145+
end, {
146+
upward = false,
147+
type = "file",
148+
path = fullpath,
149+
limit = math.huge,
150+
})
151+
152+
return vim
153+
.iter(solution_info and solution_info.projects or {})
154+
:map(function(proj)
155+
return proj.proj_file
156+
end)
157+
:any(function(proj_file)
158+
for _, file in ipairs(project_files) do
159+
if vim.fs.normalize(proj_file) == vim.fs.normalize(file) then
160+
return true
161+
end
149162
end
150-
end
151-
if vim.fs.normalize(dir) == vim.fs.normalize(root) then
152-
break
153-
end
154-
end
155-
end
156-
157-
-- We cannot determine if the file is a test file without a project directory.
158-
-- Keep searching the child by not filtering it out
159-
if not project_dir then
163+
return false
164+
end)
165+
else
160166
return true
161167
end
162-
163-
local solution_info = dotnet_utils.get_solution_info(solution)
164-
165-
local found = vim.iter(solution_info and solution_info.projects or {}):any(function(project)
166-
return vim.fs.normalize(project.proj_dir) == vim.fs.normalize(project_dir)
167-
end)
168-
169-
if solution_info and not found then
170-
return false
171-
end
172-
173-
return true
174168
end
175169

176170
local function get_match_type(captured_nodes)
@@ -403,7 +397,7 @@ local function create_adapter(config)
403397
local lang_tree =
404398
vim.treesitter.get_string_parser(content, filetype, { injections = { [filetype] = "" } })
405399

406-
local root = lib.treesitter.fast_parse(lang_tree):root()
400+
local root = lang_tree:parse(false)[1]:root()
407401

408402
local query = lib.treesitter.normalise_query(
409403
filetype,

lua/neotest-vstest/mtp/client.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function M.discovery_tests(dll_path)
150150
local tests = {}
151151

152152
local on_update = function(err, result, ctx)
153-
if result.changes then
153+
if result.changes and result.changes ~= vim.NIL then
154154
for _, test in ipairs(result.changes) do
155155
tests[#tests + 1] = test.node
156156
end
@@ -225,7 +225,7 @@ function M.run_tests(dll_path, nodes)
225225
local output_stream = nio.control.queue()
226226

227227
local on_update = function(_, result)
228-
if result.changes then
228+
if result.changes and result.changes ~= vim.NIL then
229229
nio.run(function()
230230
for _, test in ipairs(result.changes) do
231231
local test_result = run_results[test.node.uid]
@@ -307,10 +307,12 @@ function M.debug_tests(dll_path, nodes)
307307
local done_event = nio.control.event()
308308

309309
local on_update = function(_, result)
310-
for _, test in ipairs(result.changes) do
311-
local test_result = parseTestResult(test)
312-
if test_result then
313-
run_results[test.node.uid] = test_result
310+
if result.changes and result.changes ~= vim.NIL then
311+
for _, test in ipairs(result.changes) do
312+
local test_result = parseTestResult(test)
313+
if test_result then
314+
run_results[test.node.uid] = test_result
315+
end
314316
end
315317
end
316318
end

spec/root_detection_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe("Test root detection", function()
22
-- increase nio.test timeout
3-
vim.env.PLENARY_TEST_TIMEOUT = 20000
3+
vim.env.PLENARY_TEST_TIMEOUT = 80000
44
-- add test_discovery script and treesitter parsers installed with luarocks
55
vim.opt.runtimepath:append(vim.fn.getcwd())
66
vim.opt.runtimepath:append(vim.fn.expand("~/.luarocks/lib/lua/5.1/"))

spec/test_detection_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe("Test test detection", function()
22
-- increase nio.test timeout
3-
vim.env.PLENARY_TEST_TIMEOUT = 40000
3+
vim.env.PLENARY_TEST_TIMEOUT = 80000
44
-- add test_discovery script and treesitter parsers installed with luarocks
55
vim.opt.runtimepath:append(vim.fn.getcwd())
66
vim.opt.runtimepath:append(vim.fn.expand("~/.luarocks/lib/lua/5.1/"))

0 commit comments

Comments
 (0)