Fix #2535 - Automatically emit <C-x><C-o> less to prevent <C-o> issues

This commit is contained in:
w0rp 2019-05-28 20:03:35 +01:00
parent bc0abc3b96
commit 67d7caee30
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
5 changed files with 29 additions and 77 deletions

View File

@ -216,18 +216,6 @@ function! ale#completion#GetCompletionPosition() abort
endfunction endfunction
function! ale#completion#GetCompletionResult() abort 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') if exists('b:ale_completion_result')
return b:ale_completion_result return b:ale_completion_result
endif endif
@ -247,15 +235,20 @@ function! ale#completion#AutomaticOmniFunc(findstart, base) abort
endif endif
endfunction endfunction
function! ale#completion#Show(response, completion_parser) abort function! ale#completion#Show(result) abort
if ale#util#Mode() isnot# 'i' if ale#util#Mode() isnot# 'i'
return return
endif endif
" Set the list in the buffer, temporarily replace omnifunc with our " Set the list in the buffer, temporarily replace omnifunc with our
" function, and then start omni-completion. " function, and then start omni-completion.
let b:ale_completion_response = a:response let b:ale_completion_result = a:result
let b:ale_completion_parser = a:completion_parser
" Don't try to open the completion menu if there's nothing to show.
if empty(b:ale_completion_result)
return
endif
" Replace completion options shortly before opening the menu. " Replace completion options shortly before opening the menu.
call s:ReplaceCompletionOptions() call s:ReplaceCompletionOptions()
@ -475,8 +468,7 @@ function! ale#completion#HandleTSServerResponse(conn_id, response) abort
endif endif
elseif l:command is# 'completionEntryDetails' elseif l:command is# 'completionEntryDetails'
call ale#completion#Show( call ale#completion#Show(
\ a:response, \ ale#completion#ParseTSServerCompletionEntryDetails(a:response),
\ 'ale#completion#ParseTSServerCompletionEntryDetails',
\) \)
endif endif
endfunction endfunction
@ -488,8 +480,7 @@ function! ale#completion#HandleLSPResponse(conn_id, response) abort
endif endif
call ale#completion#Show( call ale#completion#Show(
\ a:response, \ ale#completion#ParseLSPCompletions(a:response),
\ 'ale#completion#ParseLSPCompletions',
\) \)
endfunction endfunction
@ -585,8 +576,6 @@ function! ale#completion#GetCompletions(source) abort
\ 'request_id': 0, \ 'request_id': 0,
\ 'source': a:source, \ 'source': a:source,
\} \}
unlet! b:ale_completion_response
unlet! b:ale_completion_parser
unlet! b:ale_completion_result unlet! b:ale_completion_result
let l:buffer = bufnr('') let l:buffer = bufnr('')

View File

@ -57,8 +57,6 @@ After:
unlet! b:ale_old_omnifunc unlet! b:ale_old_omnifunc
unlet! b:ale_old_completeopt unlet! b:ale_old_completeopt
unlet! b:ale_completion_info unlet! b:ale_completion_info
unlet! b:ale_completion_response
unlet! b:ale_completion_parser
unlet! b:ale_completion_result unlet! b:ale_completion_result
unlet! b:ale_complete_done_time unlet! b:ale_complete_done_time
@ -136,7 +134,7 @@ Execute(ale#completion#Show() should remember the omnifunc setting and replace i
let &l:omnifunc = 'FooBar' let &l:omnifunc = 'FooBar'
let b:ale_completion_info = {'source': 'ale-automatic'} let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
AssertEqual 'FooBar', b:ale_old_omnifunc AssertEqual 'FooBar', b:ale_old_omnifunc
AssertEqual 'ale#completion#AutomaticOmniFunc', &l:omnifunc AssertEqual 'ale#completion#AutomaticOmniFunc', &l:omnifunc
@ -149,7 +147,7 @@ Execute(ale#completion#Show() should remember the completeopt setting and replac
let &l:completeopt = 'menu' let &l:completeopt = 'menu'
let b:ale_completion_info = {'source': 'ale-automatic'} let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
AssertEqual 'menu', b:ale_old_completeopt AssertEqual 'menu', b:ale_old_completeopt
AssertEqual 'menu,menuone,noselect,noinsert', &l:completeopt AssertEqual 'menu,menuone,noselect,noinsert', &l:completeopt
@ -162,7 +160,7 @@ Execute(ale#completion#Show() should set the preview option if it's set):
let &l:completeopt = 'menu,preview' let &l:completeopt = 'menu,preview'
let b:ale_completion_info = {'source': 'ale-automatic'} let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
AssertEqual 'menu,preview', b:ale_old_completeopt AssertEqual 'menu,preview', b:ale_old_completeopt
AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt
@ -176,7 +174,7 @@ Execute(ale#completion#Show() should not replace the completeopt setting for man
let &l:completeopt = 'menu,preview' let &l:completeopt = 'menu,preview'
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
Assert !exists('b:ale_old_completeopt') Assert !exists('b:ale_old_completeopt')
@ -204,7 +202,7 @@ Execute(ale#completion#AutomaticOmniFunc() should set the preview option if it's
Execute(ale#completion#Show() should make the correct feedkeys() call for automatic completion): Execute(ale#completion#Show() should make the correct feedkeys() call for automatic completion):
let b:ale_completion_info = {'source': 'ale-automatic'} let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
AssertEqual [], g:feedkeys_calls AssertEqual [], g:feedkeys_calls
sleep 1ms sleep 1ms
@ -212,7 +210,7 @@ Execute(ale#completion#Show() should make the correct feedkeys() call for automa
Execute(ale#completion#Show() should make the correct feedkeys() call for manual completion): Execute(ale#completion#Show() should make the correct feedkeys() call for manual completion):
let b:ale_completion_info = {'source': 'ale-automatic'} let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
AssertEqual [], g:feedkeys_calls AssertEqual [], g:feedkeys_calls
sleep 1ms sleep 1ms
@ -220,7 +218,7 @@ Execute(ale#completion#Show() should make the correct feedkeys() call for manual
Execute(ale#completion#Show() should not call feedkeys() for other sources): Execute(ale#completion#Show() should not call feedkeys() for other sources):
let b:ale_completion_info = {'source': 'deoplete'} let b:ale_completion_info = {'source': 'deoplete'}
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
sleep 1ms sleep 1ms
AssertEqual [], g:feedkeys_calls AssertEqual [], g:feedkeys_calls
@ -229,20 +227,22 @@ Execute(ale#completion#Show() shouldn't do anything if you switch back to normal
let &l:completeopt = 'menu,preview' let &l:completeopt = 'menu,preview'
let g:fake_mode = 'n' let g:fake_mode = 'n'
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
AssertEqual 'menu,preview', &l:completeopt AssertEqual 'menu,preview', &l:completeopt
Assert !exists('b:ale_old_omnifunc') Assert !exists('b:ale_old_omnifunc')
Assert !exists('b:ale_old_completeopt') Assert !exists('b:ale_old_completeopt')
Assert !exists('b:ale_completion_response') Assert !exists('b:ale_completion_result')
Assert !exists('b:ale_completion_parser')
AssertEqual [], g:feedkeys_calls AssertEqual [], g:feedkeys_calls
Execute(ale#completion#Show() should set up the response and parser): Execute(ale#completion#Show() should save the result it is given):
call ale#completion#Show('Response', 'Parser') call ale#completion#Show([])
AssertEqual 'Response', b:ale_completion_response AssertEqual [], b:ale_completion_result
AssertEqual 'Parser', b:ale_completion_parser
call ale#completion#Show([{'word': 'x', 'kind': 'v', 'icase': 1}])
AssertEqual [{'word': 'x', 'kind': 'v', 'icase': 1}], b:ale_completion_result
Execute(ale#completion#Done() should restore old omnifunc values): Execute(ale#completion#Done() should restore old omnifunc values):
let b:ale_old_omnifunc = 'FooBar' let b:ale_old_omnifunc = 'FooBar'
@ -317,8 +317,6 @@ Execute(b:ale_completion_info should be set up correctly when requesting complet
Execute(b:ale_completion_info should be set up correctly for other sources): Execute(b:ale_completion_info should be set up correctly for other sources):
let b:ale_completion_result = [] let b:ale_completion_result = []
let b:ale_completion_response = []
let b:ale_completion_parser = 'type'
call setpos('.', [bufnr(''), 3, 14, 0]) call setpos('.', [bufnr(''), 3, 14, 0])
call ale#completion#GetCompletions('deoplete') call ale#completion#GetCompletions('deoplete')
@ -334,8 +332,6 @@ Execute(b:ale_completion_info should be set up correctly for other sources):
\ }, \ },
\ b:ale_completion_info \ b:ale_completion_info
Assert !exists('b:ale_completion_result') Assert !exists('b:ale_completion_result')
Assert !exists('b:ale_completion_response')
Assert !exists('b:ale_completion_parser')
Execute(The correct keybinds should be configured): Execute(The correct keybinds should be configured):
redir => g:output redir => g:output

View File

@ -69,8 +69,6 @@ After:
unlet! b:ale_old_omnifunc unlet! b:ale_old_omnifunc
unlet! b:ale_old_completeopt unlet! b:ale_old_completeopt
unlet! b:ale_completion_info unlet! b:ale_completion_info
unlet! b:ale_completion_response
unlet! b:ale_completion_parser
unlet! b:ale_complete_done_time unlet! b:ale_complete_done_time
unlet! b:ale_linters unlet! b:ale_linters
unlet! b:ale_tsserver_completion_names unlet! b:ale_tsserver_completion_names
@ -246,14 +244,14 @@ Execute(Two completion requests shouldn't be sent in a row):
\ 'lsp': 'stdio', \ 'lsp': 'stdio',
\ 'executable': 'foo', \ 'executable': 'foo',
\ 'command': 'foo', \ 'command': 'foo',
\ 'project_root_callback': {-> '/foo/bar'}, \ 'project_root': {-> '/foo/bar'},
\}) \})
call ale#linter#Define('python', { call ale#linter#Define('python', {
\ 'name': 'bar', \ 'name': 'bar',
\ 'lsp': 'stdio', \ 'lsp': 'stdio',
\ 'executable': 'foo', \ 'executable': 'foo',
\ 'command': 'foo', \ 'command': 'foo',
\ 'project_root_callback': {-> '/foo/bar'}, \ 'project_root': {-> '/foo/bar'},
\}) \})
let b:ale_linters = ['foo', 'bar'] let b:ale_linters = ['foo', 'bar']

View File

@ -1,7 +1,5 @@
Before: Before:
unlet! b:ale_completion_info unlet! b:ale_completion_info
unlet! b:ale_completion_response
unlet! b:ale_completion_parser
unlet! b:ale_completion_result unlet! b:ale_completion_result
let b:lsp_started = 0 let b:lsp_started = 0
@ -12,27 +10,19 @@ Before:
return b:lsp_started return b:lsp_started
endfunction endfunction
function! Identity(x) abort
return a:x
endfunction
function! SetCompletionResult(...) abort function! SetCompletionResult(...) abort
let b:ale_completion_result = ['foo'] let b:ale_completion_result = ['foo']
endfunction endfunction
function! SetCompletionResponse(...) abort function! SetCompletionResponse(...) abort
let b:ale_completion_response = ['foo'] let b:ale_completion_result = ['foo']
let b:ale_completion_parser = 'Identity'
endfunction endfunction
After: After:
unlet! b:ale_completion_info unlet! b:ale_completion_info
unlet! b:ale_completion_response
unlet! b:ale_completion_parser
unlet! b:ale_completion_result unlet! b:ale_completion_result
unlet! b:lsp_started unlet! b:lsp_started
delfunction Identity
delfunction SetCompletionResult delfunction SetCompletionResult
delfunction SetCompletionResponse delfunction SetCompletionResponse

View File

@ -3,42 +3,21 @@ Before:
unlet! b:ale_linters unlet! b:ale_linters
unlet! b:ale_completion_info unlet! b:ale_completion_info
unlet! b:ale_completion_response
unlet! b:ale_completion_parser
unlet! b:ale_completion_result unlet! b:ale_completion_result
function! Identity(x) abort
return a:x
endfunction
After: After:
delfunction Identity
call ale#linter#Reset() call ale#linter#Reset()
unlet! b:ale_linters unlet! b:ale_linters
unlet! b:ale_completion_info unlet! b:ale_completion_info
unlet! b:ale_completion_response
unlet! b:ale_completion_parser
unlet! b:ale_completion_result unlet! b:ale_completion_result
Execute(ale#completion#GetCompletionResult() should return v:null when there are no results): Execute(ale#completion#GetCompletionResult() should return v:null when there are no results):
AssertEqual v:null, ale#completion#GetCompletionResult() AssertEqual v:null, ale#completion#GetCompletionResult()
Execute(ale#completion#GetCompletionResult() should parse the result when it has yet to be parsed):
let b:ale_completion_response = [1]
let b:ale_completion_parser = 'Identity'
AssertEqual [1], ale#completion#GetCompletionResult()
Assert !exists('b:ale_completion_response')
Assert !exists('b:ale_completion_parser')
AssertEqual [1], b:ale_completion_result
Execute(ale#completion#GetCompletionResult() should return a result computed previously): Execute(ale#completion#GetCompletionResult() should return a result computed previously):
let b:ale_completion_result = [1] let b:ale_completion_result = [1]
Assert !exists('b:ale_completion_response')
Assert !exists('b:ale_completion_parser')
AssertEqual [1], ale#completion#GetCompletionResult() AssertEqual [1], ale#completion#GetCompletionResult()
Execute(ale#completion#GetCompletionPosition() should return 0 when there is no completion information): Execute(ale#completion#GetCompletionPosition() should return 0 when there is no completion information):