@@ -10,15 +10,20 @@ local p = require("plenary.path")
1010local M = {}
1111
1212--- @alias Adapter string | " auto"
13- --- @alias WinMode ' popup' | ' split' | ' auto'
14- --- @alias WinModeWithoutAuto ' popup' | ' split
13+ --- @alias WinMode " popup" | " split" | " auto"
14+ --- @alias WinModeWithoutAuto " popup" | " split
1515
1616--- @class AdapterRunOpts
17- --- @field additional_args string[] ?
17+ --- @field additional_args ? string[]
1818
19- --- @alias CmdData { type : ' stdout' , raw : string , output : string ?, decoded : any } | { type : ' stderr' , raw : string , output : string ?, decoded : any } | { type : ' exit' , code : number }
19+ --- @class CmdData
20+ --- @field type " stdout" | " stderr" | " exit"
21+ --- @field raw string
22+ --- @field output ? string
23+ --- @field decoded any
24+ --- @field code ? number
2025
21- --- @alias RunType ' line' | ' file' | ' dir' | ' all'
26+ --- @alias RunType " line" | " file" | " dir" | " all"
2227
2328--- @class QuicktestAdapter
2429--- @field name string
@@ -27,7 +32,7 @@ local M = {}
2732--- @field build_dir_run_params fun ( bufnr : integer , cursor_pos : integer[] , opts : AdapterRunOpts ): any
2833--- @field build_all_run_params fun ( bufnr : integer , cursor_pos : integer[] , opts : AdapterRunOpts ): any
2934--- @field run fun ( params : any , send : fun ( data : CmdData )): number
30- --- @field after_run fun ( params : any , results : CmdData )?
35+ --- @field after_run nil | fun ( params : any , results : CmdData )
3136--- @field title fun ( params : any ): string
3237--- @field is_enabled fun ( bufnr : number , type : RunType ): boolean
3338
@@ -36,13 +41,31 @@ local M = {}
3641--- @field default_win_mode WinModeWithoutAuto
3742--- @field use_builtin_colorizer boolean
3843
39- --- @alias JobStatus ' running' | ' finished' | ' canceled'
40- --- @alias CmdJob { id : number , started_at : number , finished_at ?: number , pid : number ?, status : JobStatus , exit_code ?: number }
44+ --- @alias JobStatus " running" | " finished" | " canceled"
45+
46+ --- @class CmdJob
47+ --- @field id number
48+ --- @field started_at integer
49+ --- @field finished_at ? integer
50+ --- @field pid ? number
51+ --- @field status JobStatus
52+ --- @field exit_code ? integer
53+
54+ --- @class PreviousRun
55+ --- @field type string
56+ --- @field adapter_name string
57+ --- @field bufname string
58+ --- @field cursor_pos integer[]
59+
60+ --- @alias PreviousRuns table<string , PreviousRun>
61+
4162--- @type CmdJob | nil
4263local current_job = nil
43- --- @type { [string] : { type : string , adapter_name : string , bufname : string , cursor_pos : integer[] }} | nil
64+
65+ --- @type nil | PreviousRuns
4466local previous_run = nil
4567
68+ --- @return PreviousRuns
4669local function load_previous_run ()
4770 local config_path = p :new (vim .fn .stdpath (" data" ), " quicktest_previous_runs.json" )
4871
6083
6184local function save_previous_run ()
6285 if previous_run then
63- --- @diagnostic disable-next-line : missing-parameter
86+ --- @diagnostic disable-next-line : missing-parameter
6487 a .run (function ()
6588 local config_path = p :new (vim .fn .stdpath (" data" ), " quicktest_previous_runs.json" )
6689 local current_data = load_previous_run ()
@@ -132,23 +155,22 @@ local stderr_ns = vim.api.nvim_create_namespace("quicktest_stderr")
132155--- @param opts AdapterRunOpts
133156function M .run (adapter , params , config , opts )
134157 if current_job then
135- if current_job .pid then
136- vim .system ({ " kill" , tostring (current_job .pid ) }):wait ()
137- current_job = nil
138- else
158+ if not current_job .pid then
139159 return notify .warn (" Already running" )
140160 end
161+ vim .system ({ " kill" , tostring (current_job .pid ) }):wait ()
162+ current_job = nil
141163 end
142164
143165 --- @param buf integer
144166 --- @param start integer
145- --- @param finish number
167+ --- @param finish integer
146168 --- @param strict_indexing boolean
147169 --- @param replacements string[]
148170 local set_ansi_lines = function (buf , start , finish , strict_indexing , replacements )
149171 local new_lines = {}
150172 for i , line in ipairs (replacements ) do
151- new_lines [i ] = string. gsub (line , " [\27\155 ][][()#;?%d]*[A-PRZcf-ntqry=><~]" , " " )
173+ new_lines [i ] = line : gsub (" [\27\155 ][][()#;?%d]*[A-PRZcf-ntqry=><~]" , " " )
152174 end
153175 vim .api .nvim_buf_set_lines (buf , start , finish , strict_indexing , new_lines )
154176 end
@@ -169,7 +191,7 @@ function M.run(adapter, params, config, opts)
169191 passedTime = job .finished_at - job .started_at
170192 end
171193
172- local time_display = string.format (" %.2f" , passedTime / 1000 ) .. " s"
194+ local time_display = (" %.2f" ): format ( passedTime / 1000 ) .. " s"
173195
174196 vim .api .nvim_buf_clear_namespace (buf , status_ns , 0 , - 1 )
175197
@@ -180,15 +202,17 @@ function M.run(adapter, params, config, opts)
180202 hl_group = " DiagnosticInfo"
181203 else
182204 if job .status == " canceled" then
183- line = " Canceled " .. time_display
205+ line = " Canceled "
184206 hl_group = " DiagnosticWarn"
185207 elseif job .exit_code ~= 0 then
186- line = " Failed " .. time_display
208+ line = " Failed "
187209 hl_group = " DiagnosticError"
188210 else
189- line = " Passed " .. time_display
211+ line = " Passed "
190212 hl_group = " DiagnosticOk"
191213 end
214+
215+ line = line .. time_display
192216 end
193217
194218 vim .api .nvim_buf_set_lines (buf , line_count - 1 , line_count , false , {
@@ -387,7 +411,7 @@ local function get_adapter_and_params(config, type, adapter_name, current_buffer
387411end
388412
389413--- @param config QuicktestConfig
390- --- @param type ' line' | ' file' | ' dir' | ' all'
414+ --- @param type " line" | " file" | " dir" | " all"
391415--- @param mode WinMode
392416--- @param adapter_name Adapter
393417--- @param opts AdapterRunOpts
0 commit comments