~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to runtime/autoload/remote/host.vim

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 = {}
5
6
 
6
7
 
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
21
22
" type
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'
25
26
  endif
34
35
 
35
36
 
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()
 
41
  endif
38
42
  if !has_key(s:hosts, a:name)
39
43
    throw 'No host named "'.a:name.'" is registered'
40
44
  endif
51
55
endfunction
52
56
 
53
57
 
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'
57
61
  endif
72
76
"
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)
77
81
 
78
82
  for plugin in plugins
116
120
endfunction
117
121
 
118
122
 
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
122
126
  endif
123
127
endfunction
124
128
 
125
129
 
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
 
134
endfunction
 
135
 
 
136
 
 
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)
138
149
  endfor
139
150
  let channel = remote#host#Require(host_id)
140
151
  let lines = []
 
152
  let registered = []
141
153
  for path in paths
 
154
    unlet! specs
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).",")
152
165
    endfor
153
166
    call add(lines, "     \\ ])")
 
167
    call add(registered, path)
154
168
  endfor
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')")))
157
171
 
158
172
  " Delete the temporary host clone
159
173
  call rpcstop(s:hosts[host_id].channel)
163
177
endfunction
164
178
 
165
179
 
166
 
function! s:UpdateRemotePlugins()
 
180
function! remote#host#UpdateRemotePlugins() abort
167
181
  let commands = []
168
182
  let hosts = keys(s:hosts)
169
183
  for host in hosts
180
194
    endif
181
195
  endfor
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)
183
199
endfunction
184
200
 
185
201
 
186
 
command! UpdateRemotePlugins call s:UpdateRemotePlugins()
187
 
 
188
 
 
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] = []
193
205
  end
195
207
endfunction
196
208
 
197
209
 
198
 
" Registration of standard hosts
199
 
 
200
 
" Python/Python3 {{{
201
 
function! s:RequirePythonHost(host)
202
 
  let ver = (a:host.orig_name ==# 'python') ? 2 : 3
203
 
 
204
 
  " Python host arguments
205
 
  let args = ['-c', 'import sys; sys.path.remove(""); import neovim; neovim.start_host()']
206
 
 
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)
211
 
  endfor
212
 
 
213
 
  try
214
 
    let channel_id = rpcstart((ver == '2' ?
215
 
          \ provider#python#Prog() : provider#python3#Prog()), args)
216
 
    if rpcrequest(channel_id, 'poll') == 'ok'
217
 
      return channel_id
218
 
    endif
219
 
  catch
220
 
    echomsg v:throwpoint
221
 
    echomsg v:exception
222
 
  endtry
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.'
230
218
endfunction
231
219
 
232
 
call remote#host#Register('python', '*.py', function('s:RequirePythonHost'))
233
 
call remote#host#Register('python3', '*.py', function('s:RequirePythonHost'))
234
 
" }}}
 
220
 
 
221
" Registration of standard hosts
 
222
 
 
223
" Python/Python3
 
224
call remote#host#Register('python', '*',
 
225
      \ function('provider#pythonx#Require'))
 
226
call remote#host#Register('python3', '*',
 
227
      \ function('provider#pythonx#Require'))
 
228
 
 
229
" Ruby
 
230
call remote#host#Register('ruby', '*.rb',
 
231
      \ function('provider#ruby#Require'))