Skip to content

Commit 127bab3

Browse files
author
Martin T.
committed
feat(notify): use notify during test discovery
Starting a test or listing all tests can take a while initally. The project is build and tests are found. This adds intermediate notifications to inform the user that neotest-vstest is busy instead of staying silent in this phase which can take a while on bigger projects. If the underlying notification system supports timeouts, intermediate messages are sticky and updated. Otherwise it just prints to the cmdline.
1 parent 8588c3c commit 127bab3

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

lua/neotest-vstest/init.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,16 @@ local function create_adapter()
103103
end
104104

105105
if solution_future.wait() and solution then
106+
local progress = require("neotest-vstest.progress")
107+
local sln_name = vim.fs.basename(solution)
108+
109+
progress.begin("Building " .. sln_name .. "")
106110
dotnet_utils.build_path(solution)
111+
112+
progress.update("Resolving projects in " .. sln_name .. "")
107113
dotnet_utils.get_solution_info(solution)
114+
progress.finish()
115+
108116
solution = string.gsub(solution, "/", lib.files.sep)
109117
solution_dir = string.gsub(vim.fs.dirname(solution), "/", lib.files.sep)
110118
logger.info(string.format("neotest-vstest: found solution dir %s", solution_dir))

lua/neotest-vstest/progress.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
local M = {}
2+
3+
local active = false
4+
local opts_sticky = { title = "neotest-vstest", id = "neotest-vstest-progress", timeout = false }
5+
local opts_dismiss = { title = "neotest-vstest", id = "neotest-vstest-progress" }
6+
7+
---@param msg string
8+
---@param level integer
9+
---@param opts table
10+
local function notify(msg, level, opts)
11+
vim.schedule(function()
12+
vim.notify(msg, level, opts)
13+
end)
14+
end
15+
16+
---@param msg string
17+
function M.begin(msg)
18+
if not active then
19+
active = true
20+
notify(msg, vim.log.levels.INFO, opts_sticky)
21+
end
22+
end
23+
24+
---@param msg string
25+
function M.update(msg)
26+
if active then
27+
notify(msg, vim.log.levels.INFO, opts_sticky)
28+
end
29+
end
30+
31+
function M.finish()
32+
if active then
33+
active = false
34+
notify("✓ Test discovery complete", vim.log.levels.INFO, opts_dismiss)
35+
end
36+
end
37+
38+
return M

0 commit comments

Comments
 (0)