mirror of https://github.com/dense-analysis/ale
Add asyncomplete.vim Support (#2627)
This commit is contained in:
parent
28c93ab185
commit
5388ff1d54
|
@ -267,6 +267,14 @@ function! ale#completion#Show(result) abort
|
|||
\ {-> ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)")}
|
||||
\)
|
||||
endif
|
||||
|
||||
if l:source is# 'ale-callback'
|
||||
call b:CompleteCallback(b:ale_completion_result)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#completion#GetAllTriggers() abort
|
||||
return deepcopy(s:trigger_character_map)
|
||||
endfunction
|
||||
|
||||
function! s:CompletionStillValid(request_id) abort
|
||||
|
@ -280,6 +288,7 @@ function! s:CompletionStillValid(request_id) abort
|
|||
\ b:ale_completion_info.column == l:column
|
||||
\ || b:ale_completion_info.source is# 'deoplete'
|
||||
\ || b:ale_completion_info.source is# 'ale-omnifunc'
|
||||
\ || b:ale_completion_info.source is# 'ale-callback'
|
||||
\)
|
||||
endfunction
|
||||
|
||||
|
@ -560,12 +569,25 @@ endfunction
|
|||
|
||||
" This function can be used to manually trigger autocomplete, even when
|
||||
" g:ale_completion_enabled is set to false
|
||||
function! ale#completion#GetCompletions(source) abort
|
||||
function! ale#completion#GetCompletions(...) abort
|
||||
let l:source = get(a:000, 0, '')
|
||||
let l:options = get(a:000, 1, {})
|
||||
|
||||
if len(a:000) > 2
|
||||
throw 'Too many arguments!'
|
||||
endif
|
||||
|
||||
let l:CompleteCallback = get(l:options, 'callback', v:null)
|
||||
|
||||
if l:CompleteCallback isnot v:null
|
||||
let b:CompleteCallback = l:CompleteCallback
|
||||
endif
|
||||
|
||||
let [l:line, l:column] = getpos('.')[1:2]
|
||||
|
||||
let l:prefix = ale#completion#GetPrefix(&filetype, l:line, l:column)
|
||||
|
||||
if a:source is# 'ale-automatic' && empty(l:prefix)
|
||||
if l:source is# 'ale-automatic' && empty(l:prefix)
|
||||
return 0
|
||||
endif
|
||||
|
||||
|
@ -578,7 +600,7 @@ function! ale#completion#GetCompletions(source) abort
|
|||
\ 'prefix': l:prefix,
|
||||
\ 'conn_id': 0,
|
||||
\ 'request_id': 0,
|
||||
\ 'source': a:source,
|
||||
\ 'source': l:source,
|
||||
\}
|
||||
unlet! b:ale_completion_result
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
function! asyncomplete#sources#ale#get_source_options(...) abort
|
||||
let l:default = extend({
|
||||
\ 'name': 'ale',
|
||||
\ 'completor': function('asyncomplete#sources#ale#completor'),
|
||||
\ 'whitelist': ['*'],
|
||||
\ 'triggers': asyncomplete#sources#ale#get_triggers(),
|
||||
\ }, a:0 >= 1 ? a:1 : {})
|
||||
|
||||
return extend(l:default, {'refresh_pattern': '\k\+$'})
|
||||
endfunction
|
||||
|
||||
function! asyncomplete#sources#ale#get_triggers() abort
|
||||
let l:triggers = ale#completion#GetAllTriggers()
|
||||
let l:triggers['*'] = l:triggers['<default>']
|
||||
|
||||
return l:triggers
|
||||
endfunction
|
||||
|
||||
function! asyncomplete#sources#ale#completor(options, context) abort
|
||||
let l:keyword = matchstr(a:context.typed, '\w\+$')
|
||||
let l:startcol = a:context.col - len(l:keyword)
|
||||
|
||||
call ale#completion#GetCompletions('ale-callback', { 'callback': {completions ->
|
||||
\ asyncomplete#complete(a:options.name, a:context, l:startcol, completions)
|
||||
\ }})
|
||||
endfunction
|
11
doc/ale.txt
11
doc/ale.txt
|
@ -341,6 +341,17 @@ completion source for Deoplete is named `'ale'`, and should enabled
|
|||
automatically if Deoplete is enabled and configured correctly. Deoplete
|
||||
integration should not be combined with ALE's own implementation.
|
||||
|
||||
*ale-asyncomplete-integration*
|
||||
|
||||
ALE additionally integrates with asyncomplete.vim for offering automatic
|
||||
completion data. ALE's asyncomplete source requires registration and should
|
||||
use the defaults provided by the|asyncomplete#sources#ale#get_source_options| function >
|
||||
|
||||
" Use ALE's function for asyncomplete defaults
|
||||
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#ale#get_source_options({
|
||||
\ 'priority': 10, " Provide your own overrides here
|
||||
\ }))
|
||||
>
|
||||
ALE also offers its own completion implementation, which does not require any
|
||||
other plugins. Suggestions will be made while you type after completion is
|
||||
enabled. ALE's own completion implementation can be enabled by setting
|
||||
|
|
|
@ -62,6 +62,10 @@ After:
|
|||
|
||||
delfunction CheckCompletionCalled
|
||||
|
||||
if exists('*CompleteCallback')
|
||||
delfunction CompleteCallback
|
||||
endif
|
||||
|
||||
" Stop any timers we left behind.
|
||||
" This stops the tests from failing randomly.
|
||||
call ale#completion#StopTimer()
|
||||
|
@ -333,6 +337,30 @@ Execute(b:ale_completion_info should be set up correctly for other sources):
|
|||
\ b:ale_completion_info
|
||||
Assert !exists('b:ale_completion_result')
|
||||
|
||||
Execute(b:ale_completion_info should be set up correctly when requesting completions via callback):
|
||||
let b:ale_completion_result = []
|
||||
call setpos('.', [bufnr(''), 3, 14, 0])
|
||||
|
||||
function! CompleteCallback() abort
|
||||
echo 'Called'
|
||||
endfunction
|
||||
|
||||
|
||||
call ale#completion#GetCompletions('ale-callback', {'callback': funcref('CompleteCallback')})
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'request_id': 0,
|
||||
\ 'conn_id': 0,
|
||||
\ 'column': 14,
|
||||
\ 'line_length': 14,
|
||||
\ 'line': 3,
|
||||
\ 'prefix': 'ab',
|
||||
\ 'source': 'ale-callback',
|
||||
\ },
|
||||
\ b:ale_completion_info
|
||||
Assert !exists('b:ale_completion_result')
|
||||
|
||||
Execute(The correct keybinds should be configured):
|
||||
redir => g:output
|
||||
silent map <Plug>(ale_show_completion_menu)
|
||||
|
|
Loading…
Reference in New Issue