summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2019-07-14 10:29:03 +0100
committerGitHub <noreply@github.com>2019-07-14 10:29:03 +0100
commit36a50111b91d05afc4ed92a5b5415d0c5527dc6b (patch)
tree3e79ccf9a7ba8e878685ad10da4af08306cf1d29
parentabb38955d3acd452e37c15e7bae62022d1153859 (diff)
parenta3521de64e8dfc2e8dbfc562fbc73502ba3e09ce (diff)
downloadale-36a50111b91d05afc4ed92a5b5415d0c5527dc6b.zip
Merge pull request #2601 from delphinus/feature/better-completion-for-deoplete
Show more candidates for Deoplete completion
-rw-r--r--autoload/ale/completion.vim7
-rw-r--r--rplugin/python3/deoplete/sources/ale.py13
-rw-r--r--test/completion/test_public_completion_api.vader4
-rw-r--r--test/python/test_deoplete_source.py14
4 files changed, 31 insertions, 7 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim
index 43d84ea6..c0e8abd9 100644
--- a/autoload/ale/completion.vim
+++ b/autoload/ale/completion.vim
@@ -60,7 +60,8 @@ let s:omni_start_map = {
\ '<default>': '\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 = {
\ '<default>': ['.'],
\ 'typescript': ['.', '''', '"'],
@@ -217,6 +218,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 7f1c1d60..66a09551 100644
--- a/rplugin/python3/deoplete/sources/ale.py
+++ b/rplugin/python3/deoplete/sources/ale.py
@@ -24,10 +24,19 @@ class Source(Base):
self.rank = 1000
self.is_bytepos = True
self.min_pattern_length = 1
+ # 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_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.
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..280df2e3 100644
--- a/test/python/test_deoplete_source.py
+++ b/test/python/test_deoplete_source.py
@@ -41,6 +41,11 @@ class DeopleteSourceTest(unittest.TestCase):
)
self.assertEqual(attributes, {
+ 'input_patterns': {
+ '_': r'\.\w*$',
+ 'rust': r'(\.|::)\w*$',
+ 'typescript': r'(\.|\'|")\w*$',
+ },
'is_bytepos': True,
'mark': '[L]',
'min_pattern_length': 1,
@@ -48,12 +53,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):