Skip to content

Commit f57601c

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 f57601c

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

lua/neotest-vstest/init.lua

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,40 @@ local function create_adapter(config)
143143
local fullpath = vim.fs.joinpath(root, rel_path)
144144
if solution_dir then
145145
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-
})
146+
local function find_project_file(upward)
147+
return vim.fs.find(function(path, _)
148+
return path:match("%.[cf]sproj$")
149+
end, {
150+
upward = upward,
151+
type = "file",
152+
path = fullpath,
153+
limit = 1,
154+
})
155+
end
156+
local project_files = find_project_file(true)
157+
if vim.tbl_isempty(project_files) then
158+
-- The csproj file may be in a sub-folder
159+
project_files = find_project_file(false)
160+
end
154161

155162
return vim
156163
.iter(solution_info and solution_info.projects or {})
157164
:map(function(proj)
158165
return proj.proj_file
159166
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
167+
:any(function(sln_project_file)
168+
for _, project_file in ipairs(project_files) do
169+
if vim.fs.normalize(sln_project_file) == vim.fs.normalize(project_file) then
163170
return true
164171
end
165172
end
173+
logger.debug(
174+
string.format(
175+
"neotest-vstest: file '%s' is not a part of the solution '%s'",
176+
rel_path,
177+
solution_info.solution_file
178+
)
179+
)
166180
return false
167181
end)
168182
else

0 commit comments

Comments
 (0)