Skip to content

Commit

Permalink
improve dap strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsidorenco committed Dec 4, 2024
1 parent 8b3f6d7 commit 109dd72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 3 additions & 5 deletions lua/neotest-dotnet/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,15 @@ DotnetNeotestAdapter.build_spec = function(args)

local results_path = nio.fn.tempname()
local stream_path = nio.fn.tempname()
lib.files.write(results_path, "")
lib.files.write(stream_path, "")

local stream_data, stop_stream = lib.files.stream_lines(stream_path)

local strategy
if args.strategy == "dap" then
local pid_path = nio.fn.tempname()
local attached_path = nio.fn.tempname()

local pid = vstest.debug_tests(pid_path, attached_path, stream_path, results_path, ids)
local pid = vstest.debug_tests(attached_path, stream_path, results_path, ids)
--- @type Configuration
strategy = {
type = "netcoredbg",
Expand All @@ -185,7 +183,7 @@ DotnetNeotestAdapter.build_spec = function(args)
env = {
DOTNET_ENVIRONMENT = "Development",
},
processId = pid,
processId = vim.trim(pid),
before = function()
local dap = require("dap")
dap.listeners.after.configurationDone["neotest-dotnet"] = function()
Expand All @@ -199,7 +197,7 @@ DotnetNeotestAdapter.build_spec = function(args)
end

return {
command = vstest.run_tests(args.strategy == "dap", ids, stream_path, results_path),
command = vstest.run_tests(args.strategy == "dap", stream_path, results_path, ids),
context = {
result_path = results_path,
stop_stream = stop_stream,
Expand Down
9 changes: 5 additions & 4 deletions lua/neotest-dotnet/vstest_wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ end

---runs tests identified by ids.
---@param dap boolean true if normal test runner should be skipped
---@param ids string|string[]
---@param stream_path string
---@param output_path string
---@param ids string|string[]
---@return string command
function M.run_tests(dap, ids, stream_path, output_path)
function M.run_tests(dap, stream_path, output_path, ids)
if not dap then
lib.process.run({ "dotnet", "build" })

Expand All @@ -332,15 +332,16 @@ function M.run_tests(dap, ids, stream_path, output_path)
end

--- Uses the vstest console to spawn a test process for the debugger to attach to.
---@param pid_path string
---@param attached_path string
---@param stream_path string
---@param output_path string
---@param ids string|string[]
---@return string? pid
function M.debug_tests(pid_path, attached_path, stream_path, output_path, ids)
function M.debug_tests(attached_path, stream_path, output_path, ids)
lib.process.run({ "dotnet", "build" })

local pid_path = nio.fn.tempname()

local command = vim
.iter({
"debug-tests",
Expand Down

0 comments on commit 109dd72

Please sign in to comment.