From 7890157931a3fdfddb647a06e27346071c55564c Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Sun, 29 Oct 2017 11:10:33 -0700 Subject: remote: add node.js as a remote plugin provider --- runtime/autoload/provider/node.vim | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 runtime/autoload/provider/node.vim (limited to 'runtime/autoload/provider') 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', []) -- cgit From eed10f7e23a7ec27e5ba147379fb6acbfcb10c20 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Tue, 31 Oct 2017 08:35:29 -0700 Subject: use `provider#stderr_collector` --- runtime/autoload/provider/node.vim | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'runtime/autoload/provider') diff --git a/runtime/autoload/provider/node.vim b/runtime/autoload/provider/node.vim index 8a2a105bb4..ce2740e813 100644 --- a/runtime/autoload/provider/node.vim +++ b/runtime/autoload/provider/node.vim @@ -3,16 +3,7 @@ if exists('g:loaded_node_provider') 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 +let s:job_opts = {'rpc': v:true, 'on_stderr': function('provider#stderr_collector')} function! provider#node#Detect() abort return exepath('neovim-node-host') @@ -44,10 +35,13 @@ function! provider#node#Require(host) abort catch echomsg v:throwpoint echomsg v:exception - for row in get(s:stderr, channel_id, []) + for row in provider#get_stderr(channel_id) echomsg row endfor endtry + finally + call provider#clear_stderr(channel_id) + endtry throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_NODE_LOG_FILE') endfunction -- cgit From e8af34dc635981367ba3b1da93b51e6984ef6111 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 17 Nov 2017 17:52:51 -0500 Subject: win: provider: Detect(): return *.cmd path (#7577) neovim-ruby-host is a ruby script. neovim-node-host is a shell script. Both don't work in cmd.exe so gem and npm provide batchfile shims. Return the full path of these shims, cmd.exe knows better what to do with these files. --- runtime/autoload/provider/node.vim | 16 ++++++++++------ runtime/autoload/provider/ruby.vim | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'runtime/autoload/provider') diff --git a/runtime/autoload/provider/node.vim b/runtime/autoload/provider/node.vim index ce2740e813..b08ad4f316 100644 --- a/runtime/autoload/provider/node.vim +++ b/runtime/autoload/provider/node.vim @@ -6,7 +6,7 @@ let g:loaded_node_provider = 1 let s:job_opts = {'rpc': v:true, 'on_stderr': function('provider#stderr_collector')} function! provider#node#Detect() abort - return exepath('neovim-node-host') + return has('win32') ? exepath('neovim-node-host.cmd') : exepath('neovim-node-host') endfunction function! provider#node#Prog() @@ -19,13 +19,17 @@ function! provider#node#Require(host) abort return endif - let args = ['node'] + if has('win32') + let args = provider#node#Prog() + else + let args = ['node'] - if !empty($NVIM_NODE_HOST_DEBUG) - call add(args, '--inspect-brk') - endif + if !empty($NVIM_NODE_HOST_DEBUG) + call add(args, '--inspect-brk') + endif - call add(args , provider#node#Prog()) + call add(args , provider#node#Prog()) + endif try let channel_id = jobstart(args, s:job_opts) diff --git a/runtime/autoload/provider/ruby.vim b/runtime/autoload/provider/ruby.vim index 7df3500267..518a9dc793 100644 --- a/runtime/autoload/provider/ruby.vim +++ b/runtime/autoload/provider/ruby.vim @@ -19,7 +19,7 @@ function! provider#ruby#Detect() abort if exists("g:ruby_host_prog") return g:ruby_host_prog else - return exepath('neovim-ruby-host') + return has('win32') ? exepath('neovim-ruby-host.cmd') : exepath('neovim-ruby-host') end endfunction -- cgit