Skip to content

Commit f03fe9d

Browse files
committed
fix(dir-filter): properly detect upward and downwards for project files
This change updates the dir_filter to use vim.fs.relpath to detect if the file is a decendant or parent of a relevant project from the solution. This change should fix the error as well as be more performant because we do not need to scan the directory for every file checked.
1 parent 8701cbe commit f03fe9d

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lua/neotest-vstest/init.lua

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,28 +143,28 @@ 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-
})
154146

155-
return vim
147+
local is_project_reachable = vim
156148
.iter(solution_info and solution_info.projects or {})
157149
:map(function(proj)
158-
return proj.proj_file
150+
return vim.fs.dirname(proj.proj_file)
159151
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
163-
return true
164-
end
165-
end
166-
return false
152+
:any(function(project_dir)
153+
-- path should be a subdir of a solution project
154+
-- or the solution project should be a subdir of the path
155+
return vim.fs.relpath(project_dir, fullpath) ~= nil
156+
or vim.fs.relpath(fullpath, project_dir) ~= nil
167157
end)
158+
if not is_project_reachable then
159+
logger.debug(
160+
string.format(
161+
"neotest-vstest: file '%s' is not a part of the solution '%s'",
162+
rel_path,
163+
solution_info.solution_file
164+
)
165+
)
166+
end
167+
return is_project_reachable
168168
else
169169
return true
170170
end

0 commit comments

Comments
 (0)