diff options
Diffstat (limited to 'runtime/autoload/provider')
-rw-r--r-- | runtime/autoload/provider/clipboard.vim | 102 | ||||
-rw-r--r-- | runtime/autoload/provider/python.vim | 2 | ||||
-rw-r--r-- | runtime/autoload/provider/python3.vim | 2 | ||||
-rw-r--r-- | runtime/autoload/provider/pythonx.vim | 84 | ||||
-rw-r--r-- | runtime/autoload/provider/ruby.vim | 68 | ||||
-rw-r--r-- | runtime/autoload/provider/script_host.rb | 8 |
6 files changed, 181 insertions, 85 deletions
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index c7cb14ded7..1bcc1dea74 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -22,54 +22,85 @@ function! s:try_cmd(cmd, ...) let argv = split(a:cmd, " ") let out = a:0 ? systemlist(argv, a:1, 1) : systemlist(argv, [''], 1) if v:shell_error - echohl WarningMsg - echo "clipboard: error: ".(len(out) ? out[0] : '') - echohl None + if !exists('s:did_error_try_cmd') + echohl WarningMsg + echomsg "clipboard: error: ".(len(out) ? out[0] : '') + echohl None + let s:did_error_try_cmd = 1 + endif return 0 endif return out endfunction +" Returns TRUE if `cmd` exits with success, else FALSE. +function! s:cmd_ok(cmd) + call system(a:cmd) + return v:shell_error == 0 +endfunction + let s:cache_enabled = 1 -if executable('pbcopy') - let s:copy['+'] = 'pbcopy' - let s:paste['+'] = 'pbpaste' - let s:copy['*'] = s:copy['+'] - let s:paste['*'] = s:paste['+'] - let s:cache_enabled = 0 -elseif exists('$DISPLAY') && executable('xsel') - let s:copy['+'] = 'xsel --nodetach -i -b' - let s:paste['+'] = 'xsel -o -b' - let s:copy['*'] = 'xsel --nodetach -i -p' - let s:paste['*'] = 'xsel -o -p' -elseif exists('$DISPLAY') && executable('xclip') - let s:copy['+'] = 'xclip -quiet -i -selection clipboard' - let s:paste['+'] = 'xclip -o -selection clipboard' - let s:copy['*'] = 'xclip -quiet -i -selection primary' - let s:paste['*'] = 'xclip -o -selection primary' -elseif executable('lemonade') - let s:copy['+'] = 'lemonade copy' - let s:paste['+'] = 'lemonade paste' - let s:copy['*'] = 'lemonade copy' - let s:paste['*'] = 'lemonade paste' -elseif executable('doitclient') - let s:copy['+'] = 'doitclient wclip' - let s:paste['+'] = 'doitclient wclip -r' - let s:copy['*'] = s:copy['+'] - let s:paste['*'] = s:paste['+'] -else - echom 'clipboard: No clipboard tool available. See :help nvim-clipboard' +let s:err = '' + +function! provider#clipboard#Error() abort + return s:err +endfunction + +function! provider#clipboard#Executable() abort + if has('mac') && executable('pbcopy') + let s:copy['+'] = 'pbcopy' + let s:paste['+'] = 'pbpaste' + let s:copy['*'] = s:copy['+'] + let s:paste['*'] = s:paste['+'] + let s:cache_enabled = 0 + return 'pbcopy' + elseif exists('$DISPLAY') && executable('xsel') && s:cmd_ok('xsel -o -b') + let s:copy['+'] = 'xsel --nodetach -i -b' + let s:paste['+'] = 'xsel -o -b' + let s:copy['*'] = 'xsel --nodetach -i -p' + let s:paste['*'] = 'xsel -o -p' + return 'xsel' + elseif exists('$DISPLAY') && executable('xclip') + let s:copy['+'] = 'xclip -quiet -i -selection clipboard' + let s:paste['+'] = 'xclip -o -selection clipboard' + let s:copy['*'] = 'xclip -quiet -i -selection primary' + let s:paste['*'] = 'xclip -o -selection primary' + return 'xclip' + elseif executable('lemonade') + let s:copy['+'] = 'lemonade copy' + let s:paste['+'] = 'lemonade paste' + let s:copy['*'] = 'lemonade copy' + let s:paste['*'] = 'lemonade paste' + return 'lemonade' + elseif executable('doitclient') + let s:copy['+'] = 'doitclient wclip' + let s:paste['+'] = 'doitclient wclip -r' + let s:copy['*'] = s:copy['+'] + let s:paste['*'] = s:paste['+'] + return 'doitclient' + elseif executable('win32yank') + let s:copy['+'] = 'win32yank -i --crlf' + let s:paste['+'] = 'win32yank -o --lf' + let s:copy['*'] = s:copy['+'] + let s:paste['*'] = s:paste['+'] + return 'win32yank' + endif + + let s:err = 'clipboard: No clipboard tool available. See :help clipboard' + return '' +endfunction + +if empty(provider#clipboard#Executable()) finish endif let s:clipboard = {} function! s:clipboard.get(reg) - let reg = a:reg == '"' ? '+' : a:reg - if s:selections[reg].owner > 0 - return s:selections[reg].data + if s:selections[a:reg].owner > 0 + return s:selections[a:reg].data end - return s:try_cmd(s:paste[reg]) + return s:try_cmd(s:paste[a:reg]) endfunction function! s:clipboard.set(lines, regtype, reg) @@ -94,6 +125,7 @@ function! s:clipboard.set(lines, regtype, reg) let selection.data = [a:lines, a:regtype] let argv = split(s:copy[a:reg], " ") let selection.detach = s:cache_enabled + let selection.cwd = "/" let jobid = jobstart(argv, selection) if jobid <= 0 echohl WarningMsg diff --git a/runtime/autoload/provider/python.vim b/runtime/autoload/provider/python.vim index cb9d5c5296..b99a046375 100644 --- a/runtime/autoload/provider/python.vim +++ b/runtime/autoload/provider/python.vim @@ -1,5 +1,5 @@ " The Python provider uses a Python host to emulate an environment for running -" python-vim plugins. See ":help nvim-provider" for more information. +" python-vim plugins. See ":help provider". " " Associating the plugin with the Python host is the first step because plugins " will be passed as command-line arguments diff --git a/runtime/autoload/provider/python3.vim b/runtime/autoload/provider/python3.vim index f4a751e7a2..4f47a03a9b 100644 --- a/runtime/autoload/provider/python3.vim +++ b/runtime/autoload/provider/python3.vim @@ -1,5 +1,5 @@ " The Python3 provider uses a Python3 host to emulate an environment for running -" python3 plugins. See ":help nvim-provider" for more information. +" python3 plugins. See ":help provider". " " Associating the plugin with the Python3 host is the first step because " plugins will be passed as command-line arguments diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim index 05815a4896..08a0f39b01 100644 --- a/runtime/autoload/provider/pythonx.vim +++ b/runtime/autoload/provider/pythonx.vim @@ -5,11 +5,24 @@ endif let s:loaded_pythonx_provider = 1 +let s:stderr = {} +let s:job_opts = {'rpc': v:true} + +" TODO(bfredl): this logic is common and should be builtin +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#pythonx#Require(host) abort let ver = (a:host.orig_name ==# 'python') ? 2 : 3 " Python host arguments - let args = ['-c', 'import sys; sys.path.remove(""); import neovim; neovim.start_host()'] + let prog = (ver == '2' ? provider#python#Prog() : provider#python3#Prog()) + let args = [prog, '-c', 'import sys; sys.path.remove(""); import neovim; neovim.start_host()'] " Collect registered Python plugins into args let python_plugins = remote#host#PluginsForHost(a:host.name) @@ -18,46 +31,44 @@ function! provider#pythonx#Require(host) abort endfor try - let channel_id = rpcstart((ver == '2' ? - \ provider#python#Prog() : provider#python3#Prog()), args) - if rpcrequest(channel_id, 'poll') == 'ok' + 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_PYTHON_LOG_FILE') endfunction function! provider#pythonx#Detect(major_ver) abort - let host_var = (a:major_ver == 2) ? - \ 'g:python_host_prog' : 'g:python3_host_prog' - let skip_var = (a:major_ver == 2) ? - \ 'g:python_host_skip_check' : 'g:python3_host_skip_check' - let skip = exists(skip_var) ? {skip_var} : 0 - if exists(host_var) - " Disable auto detection. - let [result, err] = s:check_interpreter({host_var}, a:major_ver, skip) - if result - return [{host_var}, err] + if a:major_ver == 2 + if exists('g:python_host_prog') + return [g:python_host_prog, ''] + else + let progs = ['python2', 'python2.7', 'python2.6', 'python'] + endif + else + if exists('g:python3_host_prog') + return [g:python3_host_prog, ''] + else + let progs = ['python3', 'python3.7', 'python3.6', 'python3.5', + \ 'python3.4', 'python3.3', 'python'] endif - return ['', 'provider/pythonx: Could not load Python ' . a:major_ver - \ . ' from ' . host_var . ': ' . err] endif - let prog_suffixes = (a:major_ver == 2) ? - \ ['2', '2.7', '2.6', ''] - \ : ['3', '3.5', '3.4', '3.3', ''] - let errors = [] - for prog in map(prog_suffixes, "'python' . v:val") - let [result, err] = s:check_interpreter(prog, a:major_ver, skip) + + for prog in progs + let [result, err] = s:check_interpreter(prog, a:major_ver) if result return [prog, err] endif - " Accumulate errors in case we don't find " any suitable Python interpreter. call add(errors, err) @@ -68,23 +79,19 @@ function! provider#pythonx#Detect(major_ver) abort \ . ":\n" . join(errors, "\n")] endfunction -function! s:check_interpreter(prog, major_ver, skip) abort +function! s:check_interpreter(prog, major_ver) abort let prog_path = exepath(a:prog) - if prog_path == '' + if prog_path ==# '' return [0, a:prog . ' not found in search path or not executable.'] endif - if a:skip - return [1, ''] - endif - let min_version = (a:major_ver == 2) ? '2.6' : '3.3' " Try to load neovim module, and output Python version. " Return codes: " 0 Neovim module can be loaded. - " 1 Something else went wrong. " 2 Neovim module cannot be loaded. + " Otherwise something else went wrong (e.g. 1 or 127). let prog_ver = system([ a:prog , '-c' , \ 'import sys; ' . \ 'sys.path.remove(""); ' . @@ -93,7 +100,8 @@ function! s:check_interpreter(prog, major_ver, skip) abort \ 'exit(2*int(pkgutil.get_loader("neovim") is None))' \ ]) - if prog_ver + if v:shell_error == 2 || v:shell_error == 0 + " Check version only for expected return codes. if prog_ver !~ '^' . a:major_ver return [0, prog_path . ' is Python ' . prog_ver . ' and cannot provide Python ' \ . a:major_ver . '.'] @@ -103,12 +111,16 @@ function! s:check_interpreter(prog, major_ver, skip) abort endif endif - if v:shell_error == 1 + if v:shell_error == 2 + return [0, prog_path . ' does not have the neovim module installed. ' + \ . 'See ":help provider-python".'] + elseif v:shell_error == 127 + " This can happen with pyenv's shims. + return [0, prog_path . ' does not exist: ' . prog_ver] + elseif v:shell_error return [0, 'Checking ' . prog_path . ' caused an unknown error. ' - \ . 'Please report this at github.com/neovim/neovim.'] - elseif v:shell_error == 2 - return [0, prog_path . ' does have not have the neovim module installed. ' - \ . 'See ":help nvim-python".'] + \ . '(' . v:shell_error . ', output: ' . prog_ver . ')' + \ . ' Please report this at github.com/neovim/neovim.'] endif return [1, ''] diff --git a/runtime/autoload/provider/ruby.vim b/runtime/autoload/provider/ruby.vim index aad8c09d28..c8ede20a75 100644 --- a/runtime/autoload/provider/ruby.vim +++ b/runtime/autoload/provider/ruby.vim @@ -1,13 +1,30 @@ " The Ruby provider helper -if exists('s:loaded_ruby_provider') +if exists('g:loaded_ruby_provider') finish endif +let g:loaded_ruby_provider = 1 -let s:loaded_ruby_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#ruby#Detect() abort + return exepath('neovim-ruby-host') +endfunction + +function! provider#ruby#Prog() + return s:prog +endfunction function! provider#ruby#Require(host) abort - " Collect registered Ruby plugins into args - let args = [] + let args = [provider#ruby#Prog()] let ruby_plugins = remote#host#PluginsForHost(a:host.name) for plugin in ruby_plugins @@ -15,20 +32,47 @@ function! provider#ruby#Require(host) abort endfor try - let channel_id = rpcstart(provider#ruby#Prog(), args) - - if rpcrequest(channel_id, 'poll') == 'ok' + 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_RUBY_LOG_FILE') + throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_RUBY_LOG_FILE') endfunction -function! provider#ruby#Prog() abort - return 'neovim-ruby-host' +function! provider#ruby#Call(method, args) + if s:err != '' + echoerr s:err + return + endif + + if !exists('s:host') + try + let s:host = remote#host#Require('legacy-ruby-provider') + catch + let s:err = v:exception + echohl WarningMsg + echomsg v:exception + echohl None + return + endtry + endif + return call('rpcrequest', insert(insert(a:args, 'ruby_'.a:method), s:host)) endfunction + +let s:err = '' +let s:prog = provider#ruby#Detect() +let s:plugin_path = expand('<sfile>:p:h') . '/script_host.rb' + +if empty(s:prog) + let s:err = 'Cannot find the neovim RubyGem. Try :CheckHealth' +endif + +call remote#host#RegisterClone('legacy-ruby-provider', 'ruby') +call remote#host#RegisterPlugin('legacy-ruby-provider', s:plugin_path, []) diff --git a/runtime/autoload/provider/script_host.rb b/runtime/autoload/provider/script_host.rb new file mode 100644 index 0000000000..1dade766c7 --- /dev/null +++ b/runtime/autoload/provider/script_host.rb @@ -0,0 +1,8 @@ +begin + require "neovim/ruby_provider" +rescue LoadError + warn( + "Your neovim RubyGem is missing or out of date. " + + "Install the latest version using `gem install neovim`." + ) +end |