Skip to content

Commit 8fea987

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 8fea987

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

lua/neotest-vstest/init.lua

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

133+
---@param fullpath string the path of the file to start searching from
134+
---@param stop_at string the parent directory to stop searching at
135+
---@return string[] a list of reachable projects (either parent or subfolder projects)
136+
local function projects_reachable_from(fullpath, stop_at)
137+
local parent_project = vim.fs.find(function(path, _)
138+
return path:match("%.[cf]sproj$")
139+
end, {
140+
upward = true,
141+
type = "file",
142+
stop = stop_at,
143+
path = fullpath,
144+
limit = 1,
145+
})
146+
if vim.tbl_isempty(parent_project) then
147+
-- There may be subfolders containing relevant projects
148+
return vim.fs.find(function(path, _)
149+
return path:match("%.[cf]sproj$")
150+
end, {
151+
upward = false,
152+
type = "file",
153+
path = fullpath,
154+
limit = math.huge,
155+
})
156+
else
157+
return parent_project
158+
end
159+
end
160+
133161
function DotnetNeotestAdapter.filter_dir(name, rel_path, root)
134162
local dotnet_utils = require("neotest-vstest.dotnet_utils")
135163
local logger = require("neotest.logging")
@@ -143,26 +171,26 @@ local function create_adapter(config)
143171
local fullpath = vim.fs.joinpath(root, rel_path)
144172
if solution_dir then
145173
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-
})
174+
local projects = projects_reachable_from(fullpath, root)
154175

155176
return vim
156177
.iter(solution_info and solution_info.projects or {})
157178
:map(function(proj)
158179
return proj.proj_file
159180
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
181+
:any(function(sln_project_file)
182+
for _, project_file in ipairs(project_files) do
183+
if vim.fs.normalize(sln_project_file) == vim.fs.normalize(projects) then
163184
return true
164185
end
165186
end
187+
logger.debug(
188+
string.format(
189+
"neotest-vstest: file '%s' is not a part of the solution '%s'",
190+
rel_path,
191+
solution_info.solution_file
192+
)
193+
)
166194
return false
167195
end)
168196
else

0 commit comments

Comments
 (0)