Skip to content

add support for neovim fix #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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`
  • Loading branch information
Cyperwu authored Jun 10, 2020
commit bf1af1e582d5aabfe0c78fe6e161028fa73ab713
39 changes: 27 additions & 12 deletions autoload/jsdoc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,35 @@ function! s:exit_callback(msg) abort
endfunction

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

let s:job = job_start(a:cmd, {
\ 'callback': {_, m -> a:cb(m, a:start_lineno, a:is_method)},
\ 'exit_cb': {_, m -> a:ex_cb(m)},
\ 'in_mode': 'nl',
\ })
let s:job = jobstart(a:cmd, {
\ 'on_stdout': {_, m -> a:cb(m, a:start_lineno, a:is_method)},
\ 'on_exit': {_, m -> a:ex_cb(m)},
\ 'stdout_buffered': 1,
\ })

call chansend(s:job, a:lines)
call chanclose(s:job, 'stdin')
elseif v:version >= 800 && !has('nvim')
if exists('s:job') && job_status(s:job) != 'dead'
call job_stop(s:job)
endif

let channel = job_getchannel(s:job)
if ch_status(channel) ==# 'open'
call ch_sendraw(channel, a:lines)
call ch_close_in(channel)
let s:job = job_start(a:cmd, {
\ 'callback': {_, m -> a:cb(m, a:start_lineno, a:is_method)},
\ 'exit_cb': {_, m -> a:ex_cb(m)},
\ 'in_mode': 'nl',
\ })

let channel = job_getchannel(s:job)
if ch_status(channel) ==# 'open'
call ch_sendraw(channel, a:lines)
call ch_close_in(channel)
endif
endif
endfunction

Expand Down