From a918f8c7bc7faa8b035fecf23aa35d395d0636c4 Mon Sep 17 00:00:00 2001 From: Marios S Date: Mon, 4 Jul 2022 22:00:29 +0900 Subject: [PATCH] Improve struct and pointer autocompletion in C (#4231) * Add explicit trigger characters for C (#4226) * Stop completion before issuing subsequent requests (#4226) Co-authored-by: Marios Sioutis <26476573+s-marios@users.noreply.github.com> --- autoload/ale/completion.vim | 13 +++++++++++++ rplugin/python3/deoplete/sources/ale.py | 1 + test/python/test_deoplete_source.py | 1 + 3 files changed, 15 insertions(+) diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index 142c2e89..945dc2dd 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -6,6 +6,7 @@ scriptencoding utf-8 " only valid in Insert mode. This way, feedkeys() won't send these keys if you " quit Insert mode quickly enough. inoremap (ale_show_completion_menu) +inoremap (ale_stop_completion_menu) " 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 (ale_show_completion_menu) :call ale#completion#RestoreCompletionOptions() @@ -133,6 +134,7 @@ let s:should_complete_map = { \ 'typescript': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$|\.$|''$|"$', \ 'rust': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$|\.$|::$', \ 'cpp': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$|\.$|::$|-\>$', +\ 'c': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$|\.$|-\>$', \} " Regular expressions for finding the start column to replace with completion. @@ -148,6 +150,7 @@ let s:trigger_character_map = { \ 'typescript': ['.', '''', '"'], \ 'rust': ['.', '::'], \ 'cpp': ['.', '::', '->'], +\ 'c': ['.', '->'], \} function! s:GetFiletypeValue(map, filetype) abort @@ -978,6 +981,14 @@ function! ale#completion#StopTimer() abort let s:timer_id = -1 endfunction +" Close the previous completion menu (if any), so that the newer autocompletion +" candidates will show up +function! s:closePreviousCompletionMenu() abort + if exists('*complete_info') && !empty(complete_info(['mode'])) + call ale#util#FeedKeys("\(ale_stop_completion_menu)") + endif +endfunction + function! ale#completion#Queue() abort if !get(b:, 'ale_completion_enabled', g:ale_completion_enabled) return @@ -999,6 +1010,8 @@ function! ale#completion#Queue() abort call ale#completion#StopTimer() + call s:closePreviousCompletionMenu() + let s:timer_id = timer_start(g:ale_completion_delay, function('s:TimerHandler')) endfunction diff --git a/rplugin/python3/deoplete/sources/ale.py b/rplugin/python3/deoplete/sources/ale.py index 82d9bbf2..a692dc31 100644 --- a/rplugin/python3/deoplete/sources/ale.py +++ b/rplugin/python3/deoplete/sources/ale.py @@ -32,6 +32,7 @@ class Source(Base): 'rust': r'(\.|::)\w*$', 'typescript': r'(\.|\'|")\w*$', 'cpp': r'(\.|::|->)\w*$', + 'c': r'(\.|->)\w*$', } # Returns an integer for the start position, as with omnifunc. diff --git a/test/python/test_deoplete_source.py b/test/python/test_deoplete_source.py index 8304fa25..74a42dc2 100644 --- a/test/python/test_deoplete_source.py +++ b/test/python/test_deoplete_source.py @@ -53,6 +53,7 @@ class DeopleteSourceTest(unittest.TestCase): 'rust': r'(\.|::)\w*$', 'typescript': r'(\.|\'|")\w*$', 'cpp': r'(\.|::|->)\w*$', + 'c': r'(\.|->)\w*$', }, 'is_bytepos': True, 'is_volatile': True,