diff --git a/.travis.yml b/.travis.yml index 21a72f2..7f06348 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,3 +27,17 @@ jobs: script: - cd $HOME/build/heavenshell/vim-jsdoc/tests - VIM_EXE=$HOME/bin/vim/bin/vim ./run.sh + + - env: ENV="Neovim" + install: + - mkdir -p ~/tmp/nvim/bin + - curl -L https://github.com/neovim/neovim/releases/download/v0.4.3/nvim.appimage -o ~/tmp/nvim/bin/nvim + - chmod u+x ~/tmp/nvim/bin/nvim + + before_script: + - cd $HOME/build/heavenshell/vim-jsdoc + - make install + + script: + - cd $HOME/build/heavenshell/vim-jsdoc/tests + - VIM_EXE=$HOME/tmp/nvim/bin/nvim ./run.sh diff --git a/autoload/jsdoc.vim b/autoload/jsdoc.vim index bfbf1e0..85ce5f4 100644 --- a/autoload/jsdoc.vim +++ b/autoload/jsdoc.vim @@ -93,7 +93,12 @@ function! s:exit_callback(msg) abort if len(s:results) let view = winsaveview() silent execute '% delete' - call setline(1, s:results) + if has('nvim') + " the -2 slicing is required to remove an extra new line + call setline(1, s:results[0][:-2]) + else + call setline(1, s:results) + endif call winrestview(view) endif @@ -106,20 +111,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 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) + 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 diff --git a/tests/run.sh b/tests/run.sh index 292723f..70d40c5 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,6 +1,11 @@ #!/bin/sh : "${VIM_EXE:=vim}" +# download test dependency if needed +if [[ ! -d "./vader.vim" ]]; then + git clone https://github.com/junegunn/vader.vim.git vader.vim +fi + # If nvim is available in PATH, then we prefer to use nvim # since it works better with nodemon if hash nvim 2>/dev/null ; then