2
2
let s:plugin_patterns = {}
3
3
let s:remote_plugins_manifest = fnamemodify(expand($MYVIMRC, 1), ':h')
4
4
\.'/.'.fnamemodify($MYVIMRC, ':t').'-rplugin~'
5
let s:plugins_for_host = {}
7
8
" Register a host by associating it with a factory(funcref)
8
function! remote#host#Register(name, pattern, factory)
9
function! remote#host#Register(name, pattern, factory) abort
9
10
let s:hosts[a:name] = {'factory': a:factory, 'channel': 0, 'initialized': 0}
10
11
let s:plugin_patterns[a:name] = a:pattern
11
12
if type(a:factory) == type(1) && a:factory
19
20
" as `source`, but it will run as a different process. This can be used by
20
21
" plugins that should run isolated from other plugins created for the same host
22
function! remote#host#RegisterClone(name, orig_name)
23
function! remote#host#RegisterClone(name, orig_name) abort
23
24
if !has_key(s:hosts, a:orig_name)
24
25
throw 'No host named "'.a:orig_name.'" is registered'
36
37
" Get a host channel, bootstrapping it if necessary
37
function! remote#host#Require(name)
38
function! remote#host#Require(name) abort
39
if empty(s:plugins_for_host)
40
call remote#host#LoadRemotePlugins()
38
42
if !has_key(s:hosts, a:name)
39
43
throw 'No host named "'.a:name.'" is registered'
54
function! remote#host#IsRunning(name)
58
function! remote#host#IsRunning(name) abort
55
59
if !has_key(s:hosts, a:name)
56
60
throw 'No host named "'.a:name.'" is registered'
73
77
" The third item in a declaration is a boolean: non zero means the command,
74
78
" autocommand or function will be executed synchronously with rpcrequest.
75
function! remote#host#RegisterPlugin(host, path, specs)
79
function! remote#host#RegisterPlugin(host, path, specs) abort
76
80
let plugins = remote#host#PluginsForHost(a:host)
78
82
for plugin in plugins
119
function! remote#host#LoadRemotePlugins()
123
function! remote#host#LoadRemotePlugins() abort
120
124
if filereadable(s:remote_plugins_manifest)
121
125
exe 'source '.s:remote_plugins_manifest
126
function! s:RegistrationCommands(host)
130
function! remote#host#LoadRemotePluginsEvent(event, pattern) abort
131
autocmd! nvim-rplugin
132
call remote#host#LoadRemotePlugins()
133
execute 'silent doautocmd' a:event a:pattern
137
function! s:RegistrationCommands(host) abort
127
138
" Register a temporary host clone for discovering specs
128
139
let host_id = a:host.'-registration-clone'
129
140
call remote#host#RegisterClone(host_id, a:host)
139
150
let channel = remote#host#Require(host_id)
141
153
for path in paths
142
155
let specs = rpcrequest(channel, 'specs', path)
143
156
if type(specs) != type([])
144
157
" host didn't return a spec list, indicates a failure while loading a
151
164
call add(lines, " \\ ".string(spec).",")
153
166
call add(lines, " \\ ])")
167
call add(registered, path)
155
169
echomsg printf("remote/host: %s host registered plugins %s",
156
\ a:host, string(map(copy(paths), "fnamemodify(v:val, ':t')")))
170
\ a:host, string(map(registered, "fnamemodify(v:val, ':t')")))
158
172
" Delete the temporary host clone
159
173
call rpcstop(s:hosts[host_id].channel)
182
196
call writefile(commands, s:remote_plugins_manifest)
197
echomsg printf('remote/host: generated the manifest file in "%s"',
198
\ s:remote_plugins_manifest)
186
command! UpdateRemotePlugins call s:UpdateRemotePlugins()
189
let s:plugins_for_host = {}
190
function! remote#host#PluginsForHost(host)
202
function! remote#host#PluginsForHost(host) abort
191
203
if !has_key(s:plugins_for_host, a:host)
192
204
let s:plugins_for_host[a:host] = []
198
" Registration of standard hosts
201
function! s:RequirePythonHost(host)
202
let ver = (a:host.orig_name ==# 'python') ? 2 : 3
204
" Python host arguments
205
let args = ['-c', 'import sys; sys.path.remove(""); import neovim; neovim.start_host()']
207
" Collect registered Python plugins into args
208
let python_plugins = remote#host#PluginsForHost(a:host.name)
209
for plugin in python_plugins
210
call add(args, plugin.path)
214
let channel_id = rpcstart((ver == '2' ?
215
\ provider#python#Prog() : provider#python3#Prog()), args)
216
if rpcrequest(channel_id, 'poll') == 'ok'
223
throw 'Failed to load '. a:host.orig_name . ' host. '.
210
function! remote#host#LoadErrorForHost(host, log) abort
211
return 'Failed to load '. a:host . ' host. '.
224
212
\ 'You can try to see what happened '.
225
213
\ 'by starting Neovim with the environment variable '.
226
\ '$NVIM_PYTHON_LOG_FILE set to a file and opening '.
227
\ 'the generated log file. Also, the host stderr will be available '.
214
\ a:log . ' set to a file and opening the generated '.
215
\ 'log file. Also, the host stderr will be available '.
228
216
\ 'in Neovim log, so it may contain useful information. '.
229
217
\ 'See also ~/.nvimlog.'
232
call remote#host#Register('python', '*.py', function('s:RequirePythonHost'))
233
call remote#host#Register('python3', '*.py', function('s:RequirePythonHost'))
221
" Registration of standard hosts
224
call remote#host#Register('python', '*',
225
\ function('provider#pythonx#Require'))
226
call remote#host#Register('python3', '*',
227
\ function('provider#pythonx#Require'))
230
call remote#host#Register('ruby', '*.rb',
231
\ function('provider#ruby#Require'))