From f5a908bf99a45b2602d01e07816aa513459f0197 Mon Sep 17 00:00:00 2001 From: delphinus Date: Wed, 19 Jun 2019 13:27:12 +0900 Subject: [PATCH 1/4] Add input_pattern setting for deoplete This option is used to determine if `min_pattern_length` is ignored. In usual, it does not start completion when the matched input string is shorter than `min_pattern_length`. But when the string matches `input_pattern`, it starts completion even when ths string is `''`. --- rplugin/python3/deoplete/sources/ale.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rplugin/python3/deoplete/sources/ale.py b/rplugin/python3/deoplete/sources/ale.py index 7f1c1d60..98c463e0 100644 --- a/rplugin/python3/deoplete/sources/ale.py +++ b/rplugin/python3/deoplete/sources/ale.py @@ -24,6 +24,7 @@ class Source(Base): self.rank = 1000 self.is_bytepos = True self.min_pattern_length = 1 + self.input_pattern = r'(\.|::|->)\w*$' # Returns an integer for the start position, as with omnifunc. def get_completion_position(self): From e0f8304860a8db06bca3ec8cdbd58f3852e5e789 Mon Sep 17 00:00:00 2001 From: delphinus Date: Wed, 19 Jun 2019 13:25:41 +0900 Subject: [PATCH 2/4] Add separated func for deoplete Deoplete needs `get_complete_position` method and it has a different signature. It already fetches the input string and attempts to detect the position with `\k*` regexp patterns. --- autoload/ale/completion.vim | 4 ++++ rplugin/python3/deoplete/sources/ale.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index ee156056..284b1e08 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -215,6 +215,10 @@ function! ale#completion#GetCompletionPosition() abort return l:column - len(l:match) - 1 endfunction +function! ale#completion#GetCompletionPositionForDeoplete(input) abort + return match(a:input, '\k*$') +endfunction + function! ale#completion#GetCompletionResult() abort if exists('b:ale_completion_result') return b:ale_completion_result diff --git a/rplugin/python3/deoplete/sources/ale.py b/rplugin/python3/deoplete/sources/ale.py index 98c463e0..653bc4fc 100644 --- a/rplugin/python3/deoplete/sources/ale.py +++ b/rplugin/python3/deoplete/sources/ale.py @@ -27,8 +27,10 @@ class Source(Base): self.input_pattern = r'(\.|::|->)\w*$' # Returns an integer for the start position, as with omnifunc. - def get_completion_position(self): - return self.vim.call('ale#completion#GetCompletionPosition') + def get_complete_position(self, context): + return self.vim.call( + 'ale#completion#GetCompletionPositionForDeoplete', context['input'] + ) def gather_candidates(self, context): # Stop early if ALE can't provide completion data for this buffer. From 4e1c46947dca552d86cd49a80714237801e01998 Mon Sep 17 00:00:00 2001 From: delphinus Date: Wed, 19 Jun 2019 15:25:58 +0900 Subject: [PATCH 3/4] Add & fix tests for added funcs --- test/completion/test_public_completion_api.vader | 4 ++++ test/python/test_deoplete_source.py | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test/completion/test_public_completion_api.vader b/test/completion/test_public_completion_api.vader index befbb436..c3cd42b8 100644 --- a/test/completion/test_public_completion_api.vader +++ b/test/completion/test_public_completion_api.vader @@ -32,6 +32,10 @@ Execute(ale#completion#GetCompletionPosition() should return the position in the " This is the first character of 'bar' AssertEqual 4, ale#completion#GetCompletionPosition() +Execute(ale#completion#GetCompletionPositionForDeoplete() should return the position on the given input string): + " This is the first character of 'bar' + AssertEqual 4, ale#completion#GetCompletionPositionForDeoplete('foo bar') + Execute(ale#completion#CanProvideCompletions should return 0 when no completion sources are available): AssertEqual 0, ale#completion#CanProvideCompletions() diff --git a/test/python/test_deoplete_source.py b/test/python/test_deoplete_source.py index 1462f77d..d219eef1 100644 --- a/test/python/test_deoplete_source.py +++ b/test/python/test_deoplete_source.py @@ -41,6 +41,7 @@ class DeopleteSourceTest(unittest.TestCase): ) self.assertEqual(attributes, { + 'input_pattern': r'(\.|::|->)\w*$', 'is_bytepos': True, 'mark': '[L]', 'min_pattern_length': 1, @@ -48,12 +49,13 @@ class DeopleteSourceTest(unittest.TestCase): 'rank': 1000, }) - def test_completion_position(self): - self.call_results['ale#completion#GetCompletionPosition'] = 2 + def test_complete_position(self): + self.call_results['ale#completion#GetCompletionPositionForDeoplete'] = 2 + context = {'input': 'foo'} - self.assertEqual(self.source.get_completion_position(), 2) + self.assertEqual(self.source.get_complete_position(context), 2) self.assertEqual(self.call_list, [ - ('ale#completion#GetCompletionPosition', ()), + ('ale#completion#GetCompletionPositionForDeoplete', ('foo',)), ]) def test_request_completion_results(self): From a3521de64e8dfc2e8dbfc562fbc73502ba3e09ce Mon Sep 17 00:00:00 2001 From: delphinus Date: Tue, 25 Jun 2019 17:57:38 +0900 Subject: [PATCH 4/4] Use input_patterns & add comments for updating it --- autoload/ale/completion.vim | 3 ++- rplugin/python3/deoplete/sources/ale.py | 8 +++++++- test/python/test_deoplete_source.py | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index 284b1e08..f0d6425d 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -59,7 +59,8 @@ let s:omni_start_map = { \ '': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$', \} -" A map of exact characters for triggering LSP completions. +" A map of exact characters for triggering LSP completions. Do not forget to +" update self.input_patterns in ale.py in updating entries in this map. let s:trigger_character_map = { \ '': ['.'], \ 'typescript': ['.', '''', '"'], diff --git a/rplugin/python3/deoplete/sources/ale.py b/rplugin/python3/deoplete/sources/ale.py index 653bc4fc..66a09551 100644 --- a/rplugin/python3/deoplete/sources/ale.py +++ b/rplugin/python3/deoplete/sources/ale.py @@ -24,7 +24,13 @@ class Source(Base): self.rank = 1000 self.is_bytepos = True self.min_pattern_length = 1 - self.input_pattern = r'(\.|::|->)\w*$' + # Do not forget to update s:trigger_character_map in completion.vim in + # updating entries in this map. + self.input_patterns = { + '_': r'\.\w*$', + 'rust': r'(\.|::)\w*$', + 'typescript': r'(\.|\'|")\w*$', + } # Returns an integer for the start position, as with omnifunc. def get_complete_position(self, context): diff --git a/test/python/test_deoplete_source.py b/test/python/test_deoplete_source.py index d219eef1..280df2e3 100644 --- a/test/python/test_deoplete_source.py +++ b/test/python/test_deoplete_source.py @@ -41,7 +41,11 @@ class DeopleteSourceTest(unittest.TestCase): ) self.assertEqual(attributes, { - 'input_pattern': r'(\.|::|->)\w*$', + 'input_patterns': { + '_': r'\.\w*$', + 'rust': r'(\.|::)\w*$', + 'typescript': r'(\.|\'|")\w*$', + }, 'is_bytepos': True, 'mark': '[L]', 'min_pattern_length': 1,