diff options
author | Donnie West <igneo676@gmail.com> | 2019-08-17 12:40:05 -0500 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2019-08-17 18:40:05 +0100 |
commit | 5388ff1d54e05cfaa9429cdbf9a2cacba94d190f (patch) | |
tree | 33d333acf8d89cb59a407b1549701007f51ce5a8 /autoload | |
parent | 28c93ab1854ef41a46855401cc4addbaf7dfb9d4 (diff) | |
download | ale-5388ff1d54e05cfaa9429cdbf9a2cacba94d190f.zip |
Add asyncomplete.vim Support (#2627)
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/completion.vim | 28 | ||||
-rw-r--r-- | autoload/asyncomplete/sources/ale.vim | 26 |
2 files changed, 51 insertions, 3 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index c0e8abd9..ebf32909 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -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 diff --git a/autoload/asyncomplete/sources/ale.vim b/autoload/asyncomplete/sources/ale.vim new file mode 100644 index 00000000..ce793773 --- /dev/null +++ b/autoload/asyncomplete/sources/ale.vim @@ -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 |