Skip to content

Commit 18c79ca

Browse files
committed
fix(dir-filter): look for first parent project
In order to see if the directory should be scanned we need to check upward for the first project (assuming that no file can be contained within two or more projects at the same time). Furthermore Ive changed some variable names and added a log if the directory is ignored because it is determined not to be from the solution project.
1 parent dc77b30 commit 18c79ca

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

lua/neotest-vstest/init.lua

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,32 @@ local function create_adapter(config)
130130
return true
131131
end
132132

133+
---@param fullpath the path of the file to start searching from
134+
---@return returns a list of reachable projects (either parent or subfolder projects)
135+
local function projects_reachable_from(fullpath)
136+
local parent_project = vim.fs.find(function(path, _)
137+
return path:match("%.[cf]sproj$")
138+
end, {
139+
upward = true,
140+
type = "file",
141+
path = fullpath,
142+
limit = 1,
143+
})
144+
if vim.tbl_isempty(parent_project) then
145+
-- There may be subfolders containing relevant projects
146+
return vim.fs.find(function(path, _)
147+
return path:match("%.[cf]sproj$")
148+
end, {
149+
upward = false,
150+
type = "file",
151+
path = fullpath,
152+
limit = math.huge,
153+
})
154+
else
155+
return parent_project
156+
end
157+
end
158+
133159
function DotnetNeotestAdapter.filter_dir(name, rel_path, root)
134160
local dotnet_utils = require("neotest-vstest.dotnet_utils")
135161
local logger = require("neotest.logging")
@@ -143,26 +169,26 @@ local function create_adapter(config)
143169
local fullpath = vim.fs.joinpath(root, rel_path)
144170
if solution_dir then
145171
local solution_info = dotnet_utils.get_solution_info(solution)
146-
local project_files = vim.fs.find(function(path, _)
147-
return path:match("%.[cf]sproj$")
148-
end, {
149-
upward = false,
150-
type = "file",
151-
path = fullpath,
152-
limit = math.huge,
153-
})
172+
local projects = projects_reachable_from(fullpath)
154173

155174
return vim
156175
.iter(solution_info and solution_info.projects or {})
157176
:map(function(proj)
158177
return proj.proj_file
159178
end)
160-
:any(function(proj_file)
161-
for _, file in ipairs(project_files) do
162-
if vim.fs.normalize(proj_file) == vim.fs.normalize(file) then
179+
:any(function(sln_project_file)
180+
for _, project_file in ipairs(project_files) do
181+
if vim.fs.normalize(sln_project_file) == vim.fs.normalize(project_file) then
163182
return true
164183
end
165184
end
185+
logger.debug(
186+
string.format(
187+
"neotest-vstest: file '%s' is not a part of the solution '%s'",
188+
rel_path,
189+
solution_info.solution_file
190+
)
191+
)
166192
return false
167193
end)
168194
else

0 commit comments

Comments
 (0)