diff options
author | Billy Vong <billyvg@gmail.com> | 2017-10-29 11:10:33 -0700 |
---|---|---|
committer | Billy Vong <billyvg@gmail.com> | 2017-10-29 11:10:33 -0700 |
commit | 7890157931a3fdfddb647a06e27346071c55564c (patch) | |
tree | 4eafc8720bfe367056c7cb4a8a1114b6302d9eb3 | |
parent | 8b199cb2fe5f9c2380937bfd5ea0654bdaef2918 (diff) | |
download | rneovim-7890157931a3fdfddb647a06e27346071c55564c.tar.gz rneovim-7890157931a3fdfddb647a06e27346071c55564c.tar.bz2 rneovim-7890157931a3fdfddb647a06e27346071c55564c.zip |
remote: add node.js as a remote plugin provider
-rw-r--r-- | runtime/autoload/provider/node.vim | 82 | ||||
-rw-r--r-- | runtime/autoload/remote/host.vim | 4 |
2 files changed, 86 insertions, 0 deletions
diff --git a/runtime/autoload/provider/node.vim b/runtime/autoload/provider/node.vim new file mode 100644 index 0000000000..8a2a105bb4 --- /dev/null +++ b/runtime/autoload/provider/node.vim @@ -0,0 +1,82 @@ +if exists('g:loaded_node_provider') + finish +endif +let g:loaded_node_provider = 1 + +let s:stderr = {} +let s:job_opts = {'rpc': v:true} + +function! s:job_opts.on_stderr(chan_id, data, event) + let stderr = get(s:stderr, a:chan_id, ['']) + let last = remove(stderr, -1) + let a:data[0] = last.a:data[0] + call extend(stderr, a:data) + let s:stderr[a:chan_id] = stderr +endfunction + +function! provider#node#Detect() abort + return exepath('neovim-node-host') +endfunction + +function! provider#node#Prog() + return s:prog +endfunction + +function! provider#node#Require(host) abort + if s:err != '' + echoerr s:err + return + endif + + let args = ['node'] + + if !empty($NVIM_NODE_HOST_DEBUG) + call add(args, '--inspect-brk') + endif + + call add(args , provider#node#Prog()) + + try + let channel_id = jobstart(args, s:job_opts) + if rpcrequest(channel_id, 'poll') ==# 'ok' + return channel_id + endif + catch + echomsg v:throwpoint + echomsg v:exception + for row in get(s:stderr, channel_id, []) + echomsg row + endfor + endtry + throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_NODE_LOG_FILE') +endfunction + +function! provider#node#Call(method, args) + if s:err != '' + echoerr s:err + return + endif + + if !exists('s:host') + try + let s:host = remote#host#Require('node') + catch + let s:err = v:exception + echohl WarningMsg + echomsg v:exception + echohl None + return + endtry + endif + return call('rpcrequest', insert(insert(a:args, 'node_'.a:method), s:host)) +endfunction + + +let s:err = '' +let s:prog = provider#node#Detect() + +if empty(s:prog) + let s:err = 'Cannot find the "neovim" node package. Try :CheckHealth' +endif + +call remote#host#RegisterPlugin('node-provider', 'node', []) diff --git a/runtime/autoload/remote/host.vim b/runtime/autoload/remote/host.vim index e695fb7df7..dfaab7d246 100644 --- a/runtime/autoload/remote/host.vim +++ b/runtime/autoload/remote/host.vim @@ -199,3 +199,7 @@ call remote#host#Register('python3', '*', " Ruby call remote#host#Register('ruby', '*.rb', \ function('provider#ruby#Require')) + +" nodejs +call remote#host#Register('node', '*', + \ function('provider#node#Require')) |