Skip to content

Commit bf1af1e

Browse files
authored
add support for neovim
Notice that on vim 8.0+, `job_status` returns` "run", "fail" or "dead". So I consider the `job_status` check branch is a bug. Tested on `nvim v0.5.0-6ca7ebb`
1 parent 3b88595 commit bf1af1e

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

autoload/jsdoc.vim

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,35 @@ function! s:exit_callback(msg) abort
106106
endfunction
107107

108108
function! s:vim.execute(cmd, lines, start_lineno, is_method, cb, ex_cb) dict
109-
if exists('s:job') && job_status(s:job) != 'stop'
110-
call job_stop(s:job)
111-
endif
109+
if has('nvim')
110+
if exists('s:job') && jobwait([s:job], 0)[0] == -1
111+
call jobstop(s:job)
112+
endif
112113

113-
let s:job = job_start(a:cmd, {
114-
\ 'callback': {_, m -> a:cb(m, a:start_lineno, a:is_method)},
115-
\ 'exit_cb': {_, m -> a:ex_cb(m)},
116-
\ 'in_mode': 'nl',
117-
\ })
114+
let s:job = jobstart(a:cmd, {
115+
\ 'on_stdout': {_, m -> a:cb(m, a:start_lineno, a:is_method)},
116+
\ 'on_exit': {_, m -> a:ex_cb(m)},
117+
\ 'stdout_buffered': 1,
118+
\ })
119+
120+
call chansend(s:job, a:lines)
121+
call chanclose(s:job, 'stdin')
122+
elseif v:version >= 800 && !has('nvim')
123+
if exists('s:job') && job_status(s:job) != 'dead'
124+
call job_stop(s:job)
125+
endif
118126

119-
let channel = job_getchannel(s:job)
120-
if ch_status(channel) ==# 'open'
121-
call ch_sendraw(channel, a:lines)
122-
call ch_close_in(channel)
127+
let s:job = job_start(a:cmd, {
128+
\ 'callback': {_, m -> a:cb(m, a:start_lineno, a:is_method)},
129+
\ 'exit_cb': {_, m -> a:ex_cb(m)},
130+
\ 'in_mode': 'nl',
131+
\ })
132+
133+
let channel = job_getchannel(s:job)
134+
if ch_status(channel) ==# 'open'
135+
call ch_sendraw(channel, a:lines)
136+
call ch_close_in(channel)
137+
endif
123138
endif
124139
endfunction
125140

0 commit comments

Comments
 (0)