mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-09 21:12:31 +08:00
Add asyncomplete.vim Support (#2627)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
26
autoload/asyncomplete/sources/ale.vim
Normal file
26
autoload/asyncomplete/sources/ale.vim
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user