mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-03 10:03:47 +08:00
#1700 - Don't send <C-x><C-o> for completion in Insert mode
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Completion support for LSP linters
|
||||
|
||||
" The omnicompletion menu is shown through a special Plug mapping which is
|
||||
" only valid in Insert mode. This way, feedkeys() won't send these keys if you
|
||||
" quit Insert mode quickly enough.
|
||||
inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o>
|
||||
" If we hit the key sequence in normal mode, then we won't show the menu, so
|
||||
" we should restore the old settings right away.
|
||||
nnoremap <silent> <Plug>(ale_show_completion_menu) :call ale#completion#RestoreCompletionOptions()<CR>
|
||||
cnoremap <silent> <Plug>(ale_show_completion_menu) <Nop>
|
||||
vnoremap <silent> <Plug>(ale_show_completion_menu) <Nop>
|
||||
onoremap <silent> <Plug>(ale_show_completion_menu) <Nop>
|
||||
|
||||
let g:ale_completion_delay = get(g:, 'ale_completion_delay', 100)
|
||||
let g:ale_completion_excluded_words = get(g:, 'ale_completion_excluded_words', [])
|
||||
let g:ale_completion_max_suggestions = get(g:, 'ale_completion_max_suggestions', 50)
|
||||
@@ -129,7 +140,16 @@ function! ale#completion#Filter(buffer, suggestions, prefix) abort
|
||||
return l:filtered_suggestions
|
||||
endfunction
|
||||
|
||||
function! s:ReplaceCompleteopt() abort
|
||||
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
|
||||
endif
|
||||
|
||||
let &l:omnifunc = 'ale#completion#OmniFunc'
|
||||
|
||||
if !exists('b:ale_old_completopt')
|
||||
let b:ale_old_completopt = &l:completeopt
|
||||
endif
|
||||
@@ -141,6 +161,22 @@ function! s:ReplaceCompleteopt() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#completion#RestoreCompletionOptions() abort
|
||||
" Reset settings when completion is done.
|
||||
if exists('b:ale_old_omnifunc')
|
||||
if b:ale_old_omnifunc isnot# 'pythoncomplete#Complete'
|
||||
let &l:omnifunc = b:ale_old_omnifunc
|
||||
endif
|
||||
|
||||
unlet b:ale_old_omnifunc
|
||||
endif
|
||||
|
||||
if exists('b:ale_old_completopt')
|
||||
let &l:completeopt = b:ale_old_completopt
|
||||
unlet b:ale_old_completopt
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#completion#OmniFunc(findstart, base) abort
|
||||
if a:findstart
|
||||
let l:line = b:ale_completion_info.line
|
||||
@@ -163,7 +199,7 @@ function! ale#completion#OmniFunc(findstart, base) abort
|
||||
let b:ale_completion_result = function(l:parser)(l:response)
|
||||
endif
|
||||
|
||||
call s:ReplaceCompleteopt()
|
||||
call s:ReplaceCompletionOptions()
|
||||
|
||||
return get(b:, 'ale_completion_result', [])
|
||||
endif
|
||||
@@ -174,20 +210,12 @@ function! ale#completion#Show(response, completion_parser) abort
|
||||
return
|
||||
endif
|
||||
|
||||
" 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
|
||||
|
||||
" Set the list in the buffer, temporarily replace omnifunc with our
|
||||
" function, and then start omni-completion.
|
||||
let b:ale_completion_response = a:response
|
||||
let b:ale_completion_parser = a:completion_parser
|
||||
let &l:omnifunc = 'ale#completion#OmniFunc'
|
||||
call s:ReplaceCompleteopt()
|
||||
call ale#util#FeedKeys("\<C-x>\<C-o>", 'n')
|
||||
call s:ReplaceCompletionOptions()
|
||||
call ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)")
|
||||
endfunction
|
||||
|
||||
function! s:CompletionStillValid(request_id) abort
|
||||
@@ -523,19 +551,7 @@ endfunction
|
||||
function! ale#completion#Done() abort
|
||||
silent! pclose
|
||||
|
||||
" Reset settings when completion is done.
|
||||
if exists('b:ale_old_omnifunc')
|
||||
if b:ale_old_omnifunc isnot# 'pythoncomplete#Complete'
|
||||
let &l:omnifunc = b:ale_old_omnifunc
|
||||
endif
|
||||
|
||||
unlet b:ale_old_omnifunc
|
||||
endif
|
||||
|
||||
if exists('b:ale_old_completopt')
|
||||
let &l:completeopt = b:ale_old_completopt
|
||||
unlet b:ale_old_completopt
|
||||
endif
|
||||
call ale#completion#RestoreCompletionOptions()
|
||||
|
||||
let s:last_done_pos = getcurpos()[1:2]
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user