mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-20 16:48:34 +08:00
Close #1753 - Implement minimum viable integration with Deoplete
This commit is contained in:
@@ -159,18 +159,20 @@ function! ale#completion#Filter(buffer, filetype, suggestions, prefix) abort
|
||||
endfunction
|
||||
|
||||
function! s:ReplaceCompletionOptions() abort
|
||||
" Remember the old omnifunc value, if there is one.
|
||||
" If we don't store an old one, we'll just never reset the option.
|
||||
" This will stop some random exceptions from appearing.
|
||||
if !exists('b:ale_old_omnifunc') && !empty(&l:omnifunc)
|
||||
let b:ale_old_omnifunc = &l:omnifunc
|
||||
let l:source = get(get(b:, 'ale_completion_info', {}), 'source', '')
|
||||
|
||||
if l:source is# 'ale-automatic' || l:source is# 'ale-manual'
|
||||
" Remember the old omnifunc value, if there is one.
|
||||
" If we don't store an old one, we'll just never reset the option.
|
||||
" This will stop some random exceptions from appearing.
|
||||
if !exists('b:ale_old_omnifunc') && !empty(&l:omnifunc)
|
||||
let b:ale_old_omnifunc = &l:omnifunc
|
||||
endif
|
||||
|
||||
let &l:omnifunc = 'ale#completion#OmniFunc'
|
||||
endif
|
||||
|
||||
let &l:omnifunc = 'ale#completion#OmniFunc'
|
||||
|
||||
let l:info = get(b:, 'ale_completion_info', {})
|
||||
|
||||
if !get(l:info, 'manual')
|
||||
if l:source is# 'ale-automatic'
|
||||
if !exists('b:ale_old_completeopt')
|
||||
let b:ale_old_completeopt = &l:completeopt
|
||||
endif
|
||||
@@ -199,31 +201,49 @@ function! ale#completion#RestoreCompletionOptions() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#completion#GetCompletionPosition() abort
|
||||
if !exists('b:ale_completion_info')
|
||||
return 0
|
||||
endif
|
||||
|
||||
let l:line = b:ale_completion_info.line
|
||||
let l:column = b:ale_completion_info.column
|
||||
let l:regex = s:GetFiletypeValue(s:omni_start_map, &filetype)
|
||||
let l:up_to_column = getline(l:line)[: l:column - 2]
|
||||
let l:match = matchstr(l:up_to_column, l:regex)
|
||||
|
||||
return l:column - len(l:match) - 1
|
||||
endfunction
|
||||
|
||||
function! ale#completion#GetCompletionResult() abort
|
||||
" Parse a new response if there is one.
|
||||
if exists('b:ale_completion_response')
|
||||
\&& exists('b:ale_completion_parser')
|
||||
let l:response = b:ale_completion_response
|
||||
let l:parser = b:ale_completion_parser
|
||||
|
||||
unlet b:ale_completion_response
|
||||
unlet b:ale_completion_parser
|
||||
|
||||
let b:ale_completion_result = function(l:parser)(l:response)
|
||||
endif
|
||||
|
||||
if exists('b:ale_completion_result')
|
||||
return b:ale_completion_result
|
||||
endif
|
||||
|
||||
return v:null
|
||||
endfunction
|
||||
|
||||
function! ale#completion#OmniFunc(findstart, base) abort
|
||||
if a:findstart
|
||||
let l:line = b:ale_completion_info.line
|
||||
let l:column = b:ale_completion_info.column
|
||||
let l:regex = s:GetFiletypeValue(s:omni_start_map, &filetype)
|
||||
let l:up_to_column = getline(l:line)[: l:column - 2]
|
||||
let l:match = matchstr(l:up_to_column, l:regex)
|
||||
|
||||
return l:column - len(l:match) - 1
|
||||
return ale#completion#GetCompletionPosition()
|
||||
else
|
||||
" Parse a new response if there is one.
|
||||
if exists('b:ale_completion_response')
|
||||
\&& exists('b:ale_completion_parser')
|
||||
let l:response = b:ale_completion_response
|
||||
let l:parser = b:ale_completion_parser
|
||||
|
||||
unlet b:ale_completion_response
|
||||
unlet b:ale_completion_parser
|
||||
|
||||
let b:ale_completion_result = function(l:parser)(l:response)
|
||||
endif
|
||||
let l:result = ale#completion#GetCompletionResult()
|
||||
|
||||
call s:ReplaceCompletionOptions()
|
||||
|
||||
return get(b:, 'ale_completion_result', [])
|
||||
return l:result isnot v:null ? l:result : []
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -239,7 +259,14 @@ function! ale#completion#Show(response, completion_parser) abort
|
||||
" Replace completion options shortly before opening the menu.
|
||||
call s:ReplaceCompletionOptions()
|
||||
|
||||
call timer_start(0, {-> ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)")})
|
||||
let l:source = get(get(b:, 'ale_completion_info', {}), 'source', '')
|
||||
|
||||
if l:source is# 'ale-automatic' || l:source is# 'ale-manual'
|
||||
call timer_start(
|
||||
\ 0,
|
||||
\ {-> ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)")}
|
||||
\)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:CompletionStillValid(request_id) abort
|
||||
@@ -249,7 +276,10 @@ function! s:CompletionStillValid(request_id) abort
|
||||
\&& has_key(b:, 'ale_completion_info')
|
||||
\&& b:ale_completion_info.request_id == a:request_id
|
||||
\&& b:ale_completion_info.line == l:line
|
||||
\&& b:ale_completion_info.column == l:column
|
||||
\&& (
|
||||
\ b:ale_completion_info.column == l:column
|
||||
\ || b:ale_completion_info.source is# 'deoplete'
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale#completion#ParseTSServerCompletions(response) abort
|
||||
@@ -519,12 +549,12 @@ endfunction
|
||||
|
||||
" This function can be used to manually trigger autocomplete, even when
|
||||
" g:ale_completion_enabled is set to false
|
||||
function! ale#completion#GetCompletions(manual) abort
|
||||
function! ale#completion#GetCompletions(source) abort
|
||||
let [l:line, l:column] = getpos('.')[1:2]
|
||||
|
||||
let l:prefix = ale#completion#GetPrefix(&filetype, l:line, l:column)
|
||||
|
||||
if !a:manual && empty(l:prefix)
|
||||
if a:source is# 'ale-automatic' && empty(l:prefix)
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -537,8 +567,9 @@ function! ale#completion#GetCompletions(manual) abort
|
||||
\ 'prefix': l:prefix,
|
||||
\ 'conn_id': 0,
|
||||
\ 'request_id': 0,
|
||||
\ 'manual': a:manual,
|
||||
\ 'source': a:source,
|
||||
\}
|
||||
unlet! b:ale_completion_result
|
||||
|
||||
let l:buffer = bufnr('')
|
||||
let l:Callback = function('s:OnReady')
|
||||
@@ -562,7 +593,7 @@ function! s:TimerHandler(...) abort
|
||||
" When running the timer callback, we have to be sure that the cursor
|
||||
" hasn't moved from where it was when we requested completions by typing.
|
||||
if s:timer_pos == [l:line, l:column] && ale#util#Mode() is# 'i'
|
||||
call ale#completion#GetCompletions(0)
|
||||
call ale#completion#GetCompletions('ale-automatic')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user