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
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 33 additions & 13 deletions autoload/jsdoc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down