Skip to content

Commit c7104e6

Browse files
committed
Expose job state
1 parent cb74f19 commit c7104e6

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

autoload/tpipeline.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,15 @@ func tpipeline#deferred_cleanup()
311311
let s:needs_cleanup = 1
312312
let s:cleanup_timer = timer_start(s:cleanup_delay, {-> tpipeline#cautious_cleanup()})
313313
endfunc
314+
315+
func tpipeline#job_state()
316+
let res = ""
317+
if s:is_nvim
318+
let pid = jobpid(s:job)
319+
let res = pid ? "run as PID " . pid : "dead"
320+
else
321+
let res = job_status(s:job)
322+
endif
323+
324+
return res
325+
endfunc

autoload/tpipeline/debug.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ func tpipeline#debug#info()
1818
let left = readfile(s:tpipeline_filepath)
1919
let right = readfile(s:tpipeline_right_filepath)
2020
let tmux = systemlist("tmux -V")[-1]
21+
let jobstate = tpipeline#job_state()
2122
let os = tpipeline#debug#os()
22-
let result = #{left: left, right: right, tmux: tmux, plugin_version: tpipeline#version#string(), os: os}
23+
let result = #{left: left, right: right, tmux: tmux, plugin_version: tpipeline#version#string(), job_state: jobstate, os: os}
2324

2425
if has('nvim')
2526
let stl = g:tpipeline_statusline

lua/tpipeline/health.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ M.check = function()
1010
else
1111
vim.health.report_ok("Neovim version is supported")
1212
end
13+
14+
if vim.regex('%run'):match_str(info.job_state) == nil then
15+
vim.health.report_ok("Background job is running")
16+
else
17+
vim.health.report_error(string.format("Background job is not running: %s", info.job_state))
18+
end
1319
end
1420

1521
return M

tests/test_general.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ func Read_socket()
2626
endif
2727
endfunc
2828

29+
func Test_loaded()
30+
call assert_equal(1, g:loaded_tpipeline)
31+
endfunc
32+
33+
func Test_job_runs()
34+
let job = tpipeline#debug#info()
35+
" background job is still running
36+
call assert_match("^run", job.job_state)
37+
endfunc
38+
2939
func Strip_hl(s)
3040
return substitute(a:s, '#\[[^\]]*\]', '', 'g')
3141
endfunc

0 commit comments

Comments
 (0)