Skip to content

Commit 2fbb821

Browse files
authored
fix: terminate MTP process on shutdown (#59)
* fix: terminate MTP process on shutdown * fix: terminate vstest process on shutdown
1 parent c6ded25 commit 2fbb821

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lua/neotest-vstest/mtp/client.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ end
9898
---@return nio.control.Future<vim.lsp.Client> client_future, integer mtp_process_pid
9999
function M.create_client(dll_path, on_update, on_log, mtp_env)
100100
local server_future, mtp_process = start_server(dll_path, mtp_env)
101+
102+
nio.scheduler()
103+
local cleanup_autocmd_id = vim.api.nvim_create_autocmd("QuitPre", {
104+
group = vim.api.nvim_create_augroup("neotest_vstest_mtp_shutdown", { clear = false }),
105+
desc = "Shutdown dotnet MTP client process on Neovim exit",
106+
callback = function()
107+
mtp_process:kill(vim.uv.constants.SIGKILL)
108+
end,
109+
})
110+
101111
local client_future = nio.control.future()
102112

103113
nio.run(function()
@@ -112,6 +122,7 @@ function M.create_client(dll_path, on_update, on_log, mtp_env)
112122
)
113123
server:shutdown()
114124
mtp_process:kill(vim.uv.constants.SIGKILL)
125+
vim.api.nvim_del_autocmd(cleanup_autocmd_id)
115126
end,
116127
before_init = function(params)
117128
params.processId = vim.fn.getpid()

lua/neotest-vstest/vstest/cli_wrapper.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ local function get_vstest_path()
1212
args = { "--info" },
1313
})
1414

15+
logger.debug(
16+
"neotest-vstest: starting process to detect dotnet sdk path " .. tostring(process.pid)
17+
)
18+
1519
local default_sdk_path
1620
if vim.fn.has("win32") then
1721
default_sdk_path = "C:/Program Files/dotnet/sdk/"
@@ -104,14 +108,24 @@ function M.create_test_runner(project)
104108
logger.warn(obj.stderr)
105109
end)
106110

111+
nio.scheduler()
112+
local cleanup_autocmd_id = vim.api.nvim_create_autocmd("QuitPre", {
113+
group = vim.api.nvim_create_augroup("neotest_vstest_server_shutdown", { clear = false }),
114+
desc = "Shutdown dotnet VSTest client process on Neovim exit",
115+
callback = function()
116+
process:kill(vim.uv.constants.SIGKILL)
117+
end,
118+
})
119+
107120
logger.info(string.format("neotest-vstest: spawned vstest process with pid: %s", process.pid))
108121

109122
return {
110123
execute = function(content)
111124
process:write(content .. "\n")
112125
end,
113126
stop = function()
114-
process:kill(9)
127+
process:kill(vim.uv.constants.SIGKILL)
128+
vim.api.nvim_del_autocmd(cleanup_autocmd_id)
115129
end,
116130
}
117131
end

0 commit comments

Comments
 (0)