@@ -250,22 +250,45 @@ function! xolox#lua#completefunc(init, base) " {{{1
250
250
endif
251
251
let items = []
252
252
if xolox#lua#getopt (' lua_complete_keywords' , 1 )
253
- call extend (items , g: xolox #lua_complete #keywords)
253
+ call extend (items , g: xolox #lua_data #keywords)
254
254
endif
255
255
if xolox#lua#getopt (' lua_complete_globals' , 1 )
256
- call extend (items , g: xolox #lua_complete #globals)
256
+ call extend (items , g: xolox #lua_data #globals)
257
257
endif
258
258
if xolox#lua#getopt (' lua_complete_library' , 1 )
259
- call extend (items , g: xolox #lua_complete #library)
259
+ call extend (items , g: xolox #lua_data #library)
260
260
endif
261
261
let pattern = xolox#misc#escape#pattern (a: base )
262
- return filter (items , ' v:val.word =~ pattern' )
262
+ call filter (items , ' v:val.word =~ pattern' )
263
+ return s: addsignatures (items )
263
264
endfunction
264
265
265
266
function ! s: get_completion_prefix ()
266
267
return match (strpart (getline (' .' ), 0 , col (' .' ) - 2 ), ' \w\+\.\?\w*$' )
267
268
endfunction
268
269
270
+ function ! s: addsignatures (entries)
271
+ for entry in a: entries
272
+ let signature = xolox#lua#getsignature (entry.word)
273
+ if ! empty (signature)
274
+ let entry.menu = signature
275
+ endif
276
+ endfor
277
+ return a: entries
278
+ endfunction
279
+
280
+ function ! xolox#lua#getsignature (identifier ) " {{{1
281
+ let identifier = substitute (a: identifier , ' ()$' , ' ' , ' ' )
282
+ let signature = get (g: xolox #lua_data#signatures, identifier , ' ' )
283
+ if empty (signature)
284
+ let signature = get (g: xolox #lua_data#signatures, ' string.' . identifier , ' ' )
285
+ endif
286
+ if empty (signature)
287
+ let signature = get (g: xolox #lua_data#signatures, ' file:' . identifier , ' ' )
288
+ endif
289
+ return signature
290
+ endfunction
291
+
269
292
function ! xolox#lua#omnifunc (init, base) " {{{1
270
293
if a: init
271
294
return s: get_completion_prefix ()
@@ -277,6 +300,7 @@ function! xolox#lua#omnifunc(init, base) " {{{1
277
300
endif
278
301
if ! exists (' s:omnifunc_variables' )
279
302
let s: omnifunc_variables = xolox#lua#getomnivariables (s: omnifunc_modules )
303
+ call s: addsignatures (s: omnifunc_variables )
280
304
endif
281
305
" FIXME When you type "require'" without a space in between
282
306
" the getline('.') call below returns an empty string?!
@@ -287,7 +311,7 @@ function! xolox#lua#omnifunc(init, base) " {{{1
287
311
return s: omnifunc_variables
288
312
else
289
313
let pattern = xolox#misc#escape#pattern (a: base )
290
- return filter (copy (s: omnifunc_variables ), ' v:val =~ pattern' )
314
+ return filter (copy (s: omnifunc_variables ), ' v:val.word =~ pattern' )
291
315
endif
292
316
endfunction
293
317
@@ -346,8 +370,7 @@ endfunction
346
370
function ! xolox#lua#getomnivariables (modules) " {{{1
347
371
let starttime = xolox#misc#timer#start ()
348
372
let output = xolox#lua#dofile (s: omnicomplete_script , a: modules )
349
- let variables = split (output, " \n " )
350
- call sort (variables, 1 )
373
+ let variables = eval (' [' . substitute (output, ' \_s\+' , ' ,' , ' g' ) . ' ]' )
351
374
let msg = " %s: Collected %i variables for omni completion in %s"
352
375
call xolox#misc#timer#stop (msg, s: script , len (variables), starttime)
353
376
return variables
@@ -369,37 +392,33 @@ function! xolox#lua#completedynamic(type) " {{{1
369
392
" are available, which is kind of annoying. But I don't know of an
370
393
" alternative to :silent that can be used inside of <expr>
371
394
" mappings?!
372
- return a: type . " \<C-x>\<C-u> "
395
+ if xolox#lua#getopt (' lua_complete_omni' , 0 )
396
+ return a: type . " \<C-x>\<C-o> "
397
+ else
398
+ return a: type . " \<C-x>\<C-u> "
399
+ endif
373
400
endif
374
401
endif
375
402
endif
376
403
return a: type
377
404
endfunction
378
405
379
406
function ! xolox#lua#dofile (pathname, arguments) " {{{1
380
- " First try to use the Lua Interface for Vim.
381
- try
382
- call xolox#misc#msg#debug (" %s: Trying Lua Interface for Vim .." , s: script )
407
+ if has (' lua' )
408
+ " Use the Lua Interface for Vim.
383
409
redir = > output
384
410
lua arg = vim .eval (' a:arguments' )
385
411
execute ' silent luafile' fnameescape (a: pathname )
386
412
redir END
387
- if ! empty (output)
388
- return output
389
- endif
390
- catch
391
- redir END
392
- call xolox#misc#msg#warn (" %s: %s (at %s)" , s: script , v: exception , v: throwpoint )
393
- endtry
394
- " Fall back to the command line Lua interpreter.
395
- call xolox#misc#msg#debug (" Falling back to external Lua interpreter .." )
396
- let output = system (join ([' lua' , a: pathname ] + a: arguments ))
397
- if v: shell_error
398
- let msg = " %s: Failed to retrieve omni completion candidates (output: '%s')"
399
- call xolox#misc#msg#warn (msg, s: script , output)
400
- return ' '
401
413
else
402
- return output
414
+ " Use the command line Lua interpreter.
415
+ let output = xolox#misc#str#trim (system (join ([' lua' , a: pathname ] + a: arguments )))
416
+ if v: shell_error
417
+ let msg = " %s: Failed to retrieve omni completion candidates (output: '%s')"
418
+ call xolox#misc#msg#warn (msg, s: script , output)
419
+ endif
420
+ endif
421
+ return xolox#misc#str#trim (output)
403
422
endfunction
404
423
405
424
" vim: ts = 2 sw = 2 et
0 commit comments