Make tsserver completion more reliable, but not quite ready for documentation yet

This commit is contained in:
w0rp 2017-07-13 11:59:28 +01:00
parent bc97735b6d
commit f7f6f6541d
1 changed files with 41 additions and 13 deletions

View File

@ -49,25 +49,32 @@ function! ale#completion#OmniFunc(findstart, base) abort
return l:column - len(l:match) - 1
else
" Reset the settings now
let &omnifunc = b:ale_old_omnifunc
let &completeopt = b:ale_old_completeopt
let l:response = b:ale_completion_response
let l:parser = b:ale_completion_parser
" 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
unlet b:ale_old_omnifunc
unlet b:ale_old_completeopt
unlet b:ale_completion_response
unlet b:ale_completion_parser
return function(l:parser)(l:response)
let b:ale_completion_result = function(l:parser)(l:response)
endif
return get(b:, 'ale_completion_result', [])
endif
endfunction
function! ale#completion#Show(response, completion_parser) abort
" Remember the old omnifunc value.
if !exists('b:ale_old_omnifunc')
" 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(&omnifunc)
let b:ale_old_omnifunc = &omnifunc
endif
" Remember the old completion options, if they are set.
if !exists('b:ale_old_completeopt') && !empty(&completeopt)
let b:ale_old_completeopt = &completeopt
endif
@ -248,6 +255,12 @@ endfunction
function! ale#completion#Queue() abort
let s:timer_pos = getcurpos()[1:2]
" If we changed the text again while we're still waiting for a response,
" then invalidate the requests before the timer ticks again.
if exists('b:ale_completion_info')
let b:ale_completion_info.request_id = 0
endif
if s:timer_id != -1
call timer_stop(s:timer_id)
endif
@ -255,13 +268,28 @@ function! ale#completion#Queue() abort
let s:timer_id = timer_start(g:ale_completion_delay, function('s:TimerHandler'))
endfunction
function! ale#completion#Done() abort
silent! pclose
" Reset settings when completion is done.
if exists('b:ale_old_omnifunc')
let &omnifunc = b:ale_old_omnifunc
unlet b:ale_old_omnifunc
endif
if exists('b:ale_old_completeopt')
let &completeopt = b:ale_old_completeopt
unlet b:ale_old_completeopt
endif
endfunction
function! s:Setup(enabled) abort
augroup ALECompletionGroup
autocmd!
if a:enabled
autocmd TextChangedI * call ale#completion#Queue()
autocmd CompleteDone * silent! pclose
autocmd CompleteDone * call ale#completion#Done()
endif
augroup END