aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload/provider
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/autoload/provider')
-rw-r--r--runtime/autoload/provider/perl.vim80
-rw-r--r--runtime/autoload/provider/python3.vim44
-rw-r--r--runtime/autoload/provider/pythonx.vim112
-rw-r--r--runtime/autoload/provider/ruby.vim67
4 files changed, 18 insertions, 285 deletions
diff --git a/runtime/autoload/provider/perl.vim b/runtime/autoload/provider/perl.vim
index 24f2b018bb..b439f751ae 100644
--- a/runtime/autoload/provider/perl.vim
+++ b/runtime/autoload/provider/perl.vim
@@ -1,83 +1,15 @@
-if exists('s:loaded_perl_provider')
+if exists('g:loaded_perl_provider')
finish
endif
-let s:loaded_perl_provider = 1
-
-function! provider#perl#Detect() abort
- " use g:perl_host_prog if set or check if perl is on the path
- let prog = exepath(get(g:, 'perl_host_prog', 'perl'))
- if empty(prog)
- return ['', '']
- endif
-
- " if perl is available, make sure we have 5.22+
- call system([prog, '-e', 'use v5.22'])
- if v:shell_error
- return ['', 'Perl version is too old, 5.22+ required']
- endif
-
- " if perl is available, make sure the required module is available
- call system([prog, '-W', '-MNeovim::Ext', '-e', ''])
- if v:shell_error
- return ['', '"Neovim::Ext" cpan module is not installed']
- endif
-
- return [prog, '']
-endfunction
-
-function! provider#perl#Prog() abort
- return s:prog
+function! provider#perl#Call(method, args) abort
+ return v:lua.vim.provider.perl.call(a:method, a:args)
endfunction
function! provider#perl#Require(host) abort
- if s:err != ''
- echoerr s:err
- return
- endif
-
- let prog = provider#perl#Prog()
- let args = [s:prog, '-e', 'use Neovim::Ext; start_host();']
-
- " Collect registered perl plugins into args
- let perl_plugins = remote#host#PluginsForHost(a:host.name)
- for plugin in perl_plugins
- call add(args, plugin.path)
- endfor
-
- return provider#Poll(args, a:host.orig_name, '$NVIM_PERL_LOG_FILE')
+ return v:lua.vim.provider.perl.require(a:host, s:prog)
endfunction
-function! provider#perl#Call(method, args) abort
- if s:err != ''
- echoerr s:err
- return
- endif
-
- if !exists('s:host')
- try
- let s:host = remote#host#Require('legacy-perl-provider')
- catch
- let s:err = v:exception
- echohl WarningMsg
- echomsg v:exception
- echohl None
- return
- endtry
- endif
- return call('rpcrequest', insert(insert(a:args, 'perl_'.a:method), s:host))
-endfunction
-
-let [s:prog, s:err] = provider#perl#Detect()
+let s:prog = v:lua.vim.provider.perl.detect()
let g:loaded_perl_provider = empty(s:prog) ? 1 : 2
-
-if g:loaded_perl_provider != 2
- let s:err = 'Cannot find perl or the required perl module'
-endif
-
-
-" The perl provider plugin will run in a separate instance of the perl
-" host.
-call remote#host#RegisterClone('legacy-perl-provider', 'perl')
-call remote#host#RegisterPlugin('legacy-perl-provider', 'ScriptHost.pm', [])
-
+call v:lua.require'vim.provider.perl'.start()
diff --git a/runtime/autoload/provider/python3.vim b/runtime/autoload/provider/python3.vim
index 38ef0cccfc..43c14122d0 100644
--- a/runtime/autoload/provider/python3.vim
+++ b/runtime/autoload/provider/python3.vim
@@ -1,45 +1,15 @@
-" The Python3 provider uses a Python3 host to emulate an environment for running
-" python3 plugins. :help provider
-"
-" Associating the plugin with the Python3 host is the first step because
-" plugins will be passed as command-line arguments
-
if exists('g:loaded_python3_provider')
finish
endif
-let [s:prog, s:err] = provider#pythonx#Detect(3)
-let g:loaded_python3_provider = empty(s:prog) ? 1 : 2
-function! provider#python3#Prog() abort
- return s:prog
+function! provider#python3#Call(method, args) abort
+ return v:lua.vim.provider.python.call(a:method, a:args)
endfunction
-function! provider#python3#Error() abort
- return s:err
+function! provider#python3#Require(host) abort
+ return v:lua.vim.provider.python.require(a:host)
endfunction
-" The Python3 provider plugin will run in a separate instance of the Python3
-" host.
-call remote#host#RegisterClone('legacy-python3-provider', 'python3')
-call remote#host#RegisterPlugin('legacy-python3-provider', 'script_host.py', [])
-
-function! provider#python3#Call(method, args) abort
- if s:err != ''
- return
- endif
- if !exists('s:host')
- let s:rpcrequest = function('rpcrequest')
-
- " Ensure that we can load the Python3 host before bootstrapping
- try
- let s:host = remote#host#Require('legacy-python3-provider')
- catch
- let s:err = v:exception
- echohl WarningMsg
- echomsg v:exception
- echohl None
- return
- endtry
- endif
- return call(s:rpcrequest, insert(insert(a:args, 'python_'.a:method), s:host))
-endfunction
+let s:prog = v:lua.vim.provider.python.detect_by_module('neovim')
+let g:loaded_python3_provider = empty(s:prog) ? 1 : 2
+call v:lua.require'vim.provider.python'.start()
diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim
deleted file mode 100644
index 48b96c699a..0000000000
--- a/runtime/autoload/provider/pythonx.vim
+++ /dev/null
@@ -1,112 +0,0 @@
-" The Python provider helper
-if exists('s:loaded_pythonx_provider')
- finish
-endif
-
-let s:loaded_pythonx_provider = 1
-
-function! provider#pythonx#Require(host) abort
- " Python host arguments
- let prog = provider#python3#Prog()
- let args = [prog, '-c', 'import sys; sys.path = [p for p in sys.path if p != ""]; import neovim; neovim.start_host()']
-
-
- " Collect registered Python plugins into args
- let python_plugins = remote#host#PluginsForHost(a:host.name)
- for plugin in python_plugins
- call add(args, plugin.path)
- endfor
-
- return provider#Poll(args, a:host.orig_name, '$NVIM_PYTHON_LOG_FILE', {'overlapped': v:true})
-endfunction
-
-function! s:get_python_executable_from_host_var(major_version) abort
- return expand(get(g:, 'python'.(a:major_version == 3 ? '3' : execute("throw 'unsupported'")).'_host_prog', ''), v:true)
-endfunction
-
-function! s:get_python_candidates(major_version) abort
- return {
- \ 3: ['python3', 'python3.12', 'python3.11', 'python3.10', 'python3.9', 'python3.8', 'python3.7', 'python']
- \ }[a:major_version]
-endfunction
-
-" Returns [path_to_python_executable, error_message]
-function! provider#pythonx#Detect(major_version) abort
- return provider#pythonx#DetectByModule('neovim', a:major_version)
-endfunction
-
-" Returns [path_to_python_executable, error_message]
-function! provider#pythonx#DetectByModule(module, major_version) abort
- let python_exe = s:get_python_executable_from_host_var(a:major_version)
-
- if !empty(python_exe)
- return [exepath(expand(python_exe, v:true)), '']
- endif
-
- let candidates = s:get_python_candidates(a:major_version)
- let errors = []
-
- for exe in candidates
- let [result, error] = provider#pythonx#CheckForModule(exe, a:module, a:major_version)
- if result
- return [exe, error]
- endif
- " Accumulate errors in case we don't find any suitable Python executable.
- call add(errors, error)
- endfor
-
- " No suitable Python executable found.
- return ['', 'Could not load Python '.a:major_version.":\n".join(errors, "\n")]
-endfunction
-
-" Returns array: [prog_exitcode, prog_version]
-function! s:import_module(prog, module) abort
- let prog_version = system([a:prog, '-W', 'ignore', '-c', printf(
- \ 'import sys, importlib.util; ' .
- \ 'sys.path = [p for p in sys.path if p != ""]; ' .
- \ 'sys.stdout.write(str(sys.version_info[0]) + "." + str(sys.version_info[1])); ' .
- \ 'sys.exit(2 * int(importlib.util.find_spec("%s") is None))',
- \ a:module)])
- return [v:shell_error, prog_version]
-endfunction
-
-" Returns array: [was_success, error_message]
-function! provider#pythonx#CheckForModule(prog, module, major_version) abort
- let prog_path = exepath(a:prog)
- if prog_path ==# ''
- return [0, a:prog . ' not found in search path or not executable.']
- endif
-
- let min_version = '3.7'
-
- " Try to load module, and output Python version.
- " Exit codes:
- " 0 module can be loaded.
- " 2 module cannot be loaded.
- " Otherwise something else went wrong (e.g. 1 or 127).
- let [prog_exitcode, prog_version] = s:import_module(a:prog, a:module)
-
- if prog_exitcode == 2 || prog_exitcode == 0
- " Check version only for expected return codes.
- if prog_version !~ '^' . a:major_version
- return [0, prog_path . ' is Python ' . prog_version . ' and cannot provide Python '
- \ . a:major_version . '.']
- elseif prog_version =~ '^' . a:major_version && str2nr(prog_version[2:]) < str2nr(min_version[2:])
- return [0, prog_path . ' is Python ' . prog_version . ' and cannot provide Python >= '
- \ . min_version . '.']
- endif
- endif
-
- if prog_exitcode == 2
- return [0, prog_path.' does not have the "' . a:module . '" module.']
- elseif prog_exitcode == 127
- " This can happen with pyenv's shims.
- return [0, prog_path . ' does not exist: ' . prog_version]
- elseif prog_exitcode
- return [0, 'Checking ' . prog_path . ' caused an unknown error. '
- \ . '(' . prog_exitcode . ', output: ' . prog_version . ')'
- \ . ' Report this at https://github.com/neovim/neovim']
- endif
-
- return [1, '']
-endfunction
diff --git a/runtime/autoload/provider/ruby.vim b/runtime/autoload/provider/ruby.vim
index 1428fab1cc..07b4aca23f 100644
--- a/runtime/autoload/provider/ruby.vim
+++ b/runtime/autoload/provider/ruby.vim
@@ -1,73 +1,16 @@
-" The Ruby provider helper
if exists('g:loaded_ruby_provider')
finish
endif
-let g:loaded_ruby_provider = 1
-
-function! provider#ruby#Detect() abort
- let e = empty(s:prog) ? 'missing ruby or ruby-host' : ''
- return [s:prog, e]
-endfunction
-
-function! provider#ruby#Prog() abort
- return s:prog
-endfunction
function! provider#ruby#Require(host) abort
- let prog = provider#ruby#Prog()
- let ruby_plugins = remote#host#PluginsForHost(a:host.name)
-
- for plugin in ruby_plugins
- let prog .= " " . shellescape(plugin.path)
- endfor
-
- return provider#Poll(prog, a:host.orig_name, '$NVIM_RUBY_LOG_FILE')
+ return v:lua.vim.provider.ruby.require(a:host)
endfunction
function! provider#ruby#Call(method, args) abort
- 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))
+ return v:lua.vim.provider.ruby.call(a:method, a:args)
endfunction
-function! s:detect()
- if exists("g:ruby_host_prog")
- return expand(g:ruby_host_prog, v:true)
- elseif has('win32')
- return exepath('neovim-ruby-host.bat')
- else
- let p = exepath('neovim-ruby-host')
- if empty(p)
- return ''
- endif
- " neovim-ruby-host could be an rbenv shim for another Ruby version.
- call system(p)
- return v:shell_error ? '' : p
- end
-endfunction
-
-let s:err = ''
-let s:prog = s:detect()
-let s:plugin_path = expand('<sfile>:p:h') . '/script_host.rb'
+let s:prog = v:lua.vim.provider.ruby.detect()
let g:loaded_ruby_provider = empty(s:prog) ? 1 : 2
-
-if g:loaded_ruby_provider != 2
- 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, [])
+let s:plugin_path = expand('<sfile>:p:h') . '/script_host.rb'
+call v:lua.require'vim.provider.ruby'.start(s:plugin_path)