aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-11-11 01:54:32 +0100
committerGitHub <noreply@github.com>2017-11-11 01:54:32 +0100
commitb6a603fe515ee1cd554a8c4151286b26209a467b (patch)
treef40fa782d89c304045ebb7cb4184f0ac52204deb
parenta2fdd0a72f9d1f72f2e49e80719902a6f555454e (diff)
parenteed10f7e23a7ec27e5ba147379fb6acbfcb10c20 (diff)
downloadrneovim-b6a603fe515ee1cd554a8c4151286b26209a467b.tar.gz
rneovim-b6a603fe515ee1cd554a8c4151286b26209a467b.tar.bz2
rneovim-b6a603fe515ee1cd554a8c4151286b26209a467b.zip
Merge #7458 'remote: add node host'
-rw-r--r--runtime/autoload/health/provider.vim62
-rw-r--r--runtime/autoload/provider/node.vim76
-rw-r--r--runtime/autoload/remote/host.vim4
3 files changed, 142 insertions, 0 deletions
diff --git a/runtime/autoload/health/provider.vim b/runtime/autoload/health/provider.vim
index 0eaa678459..806a9d043b 100644
--- a/runtime/autoload/health/provider.vim
+++ b/runtime/autoload/health/provider.vim
@@ -487,9 +487,71 @@ function! s:check_ruby() abort
endif
endfunction
+function! s:check_node() abort
+ call health#report_start('Node provider (optional)')
+
+ let loaded_var = 'g:loaded_node_provider'
+ if exists(loaded_var) && !exists('*provider#node#Call')
+ call health#report_info('Disabled. '.loaded_var.'='.eval(loaded_var))
+ return
+ endif
+
+ if !executable('node') || !executable('npm') || !executable('yarn')
+ call health#report_warn(
+ \ '`node` and `npm` must be in $PATH.',
+ \ ['Install Node.js and verify that `node` and `npm` commands work.'])
+ return
+ endif
+ call health#report_info('Node: '. s:system('node -v'))
+
+ let host = provider#node#Detect()
+ if empty(host)
+ call health#report_warn('Missing "neovim" npm package.',
+ \ ['Run in shell: npm install -g neovim',
+ \ 'Is the npm bin directory in $PATH?'])
+ return
+ endif
+ call health#report_info('Host: '. host)
+
+ let latest_npm_cmd = has('win32') ? 'cmd /c npm info neovim --json' : 'npm info neovim --json'
+ let latest_npm = s:system(split(latest_npm_cmd))
+ if s:shell_error || empty(latest_npm)
+ call health#report_error('Failed to run: '. latest_npm_cmd,
+ \ ["Make sure you're connected to the internet.",
+ \ 'Are you behind a firewall or proxy?'])
+ return
+ endif
+ if !empty(latest_npm)
+ try
+ let pkg_data = json_decode(latest_npm)
+ catch /E474/
+ return 'error: '.latest_npm
+ endtry
+ let latest_npm = get(get(pkg_data, 'dist-tags', {}), 'latest', 'unable to parse')
+ endif
+
+ let current_npm_cmd = host .' --version'
+ let current_npm = s:system(current_npm_cmd)
+ if s:shell_error
+ call health#report_error('Failed to run: '. current_npm_cmd,
+ \ ['Report this issue with the output of: ', current_npm_cmd])
+ return
+ endif
+
+ if s:version_cmp(current_npm, latest_npm) == -1
+ call health#report_warn(
+ \ printf('Package "neovim" is out-of-date. Installed: %s, latest: %s',
+ \ current_npm, latest_npm),
+ \ ['Run in shell: npm update neovim'])
+ else
+ call health#report_ok('Latest "neovim" npm is installed: '. current_npm)
+ endif
+endfunction
+
function! health#provider#check() abort
call s:check_clipboard()
call s:check_python(2)
call s:check_python(3)
call s:check_ruby()
+ call s:check_node()
endfunction
diff --git a/runtime/autoload/provider/node.vim b/runtime/autoload/provider/node.vim
new file mode 100644
index 0000000000..ce2740e813
--- /dev/null
+++ b/runtime/autoload/provider/node.vim
@@ -0,0 +1,76 @@
+if exists('g:loaded_node_provider')
+ finish
+endif
+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')
+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 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
+
+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'))