#2492 - Try to fix a deoplete bug again
This commit is contained in:
parent
7943bfab96
commit
bfc79bd2aa
@ -549,6 +549,19 @@ function! s:OnReady(linter, lsp_details) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" This function can be called to check if ALE can provide completion data for
|
||||
" the current buffer. 1 will be returned if there's a potential source of
|
||||
" completion data ALE can use, and 0 will be returned otherwise.
|
||||
function! ale#completion#CanProvideCompletions() abort
|
||||
for l:linter in ale#linter#Get(&filetype)
|
||||
if !empty(l:linter.lsp)
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" This function can be used to manually trigger autocomplete, even when
|
||||
" g:ale_completion_enabled is set to false
|
||||
function! ale#completion#GetCompletions(source) abort
|
||||
|
@ -30,6 +30,10 @@ class Source(Base):
|
||||
return self.vim.call('ale#completion#GetCompletionPosition')
|
||||
|
||||
def gather_candidates(self, context):
|
||||
# Stop early if ALE can't provide completion data for this buffer.
|
||||
if not self.vim.call('ale#completion#CanProvideCompletions'):
|
||||
return None
|
||||
|
||||
if context.get('is_refresh'):
|
||||
context['is_async'] = False
|
||||
|
||||
@ -47,4 +51,4 @@ class Source(Base):
|
||||
# Request some completion results.
|
||||
self.vim.call('ale#completion#GetCompletions', 'deoplete')
|
||||
|
||||
return None
|
||||
return []
|
||||
|
63
test/completion/test_public_completion_api.vader
Normal file
63
test/completion/test_public_completion_api.vader
Normal file
@ -0,0 +1,63 @@
|
||||
Before:
|
||||
call ale#linter#Reset()
|
||||
|
||||
unlet! b:ale_linters
|
||||
unlet! b:ale_completion_info
|
||||
unlet! b:ale_completion_response
|
||||
unlet! b:ale_completion_parser
|
||||
unlet! b:ale_completion_result
|
||||
|
||||
function! Identity(x) abort
|
||||
return a:x
|
||||
endfunction
|
||||
|
||||
After:
|
||||
delfunction Identity
|
||||
|
||||
call ale#linter#Reset()
|
||||
|
||||
unlet! b:ale_linters
|
||||
unlet! b:ale_completion_info
|
||||
unlet! b:ale_completion_response
|
||||
unlet! b:ale_completion_parser
|
||||
unlet! b:ale_completion_result
|
||||
|
||||
Execute(ale#completion#GetCompletionResult() should return v:null when there are no results):
|
||||
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):
|
||||
let b:ale_completion_result = [1]
|
||||
|
||||
Assert !exists('b:ale_completion_response')
|
||||
Assert !exists('b:ale_completion_parser')
|
||||
AssertEqual [1], ale#completion#GetCompletionResult()
|
||||
|
||||
Execute(ale#completion#GetCompletionPosition() should return 0 when there is no completion information):
|
||||
AssertEqual 0, ale#completion#GetCompletionPosition()
|
||||
|
||||
Given python(Some Python file):
|
||||
foo bar
|
||||
|
||||
Execute(ale#completion#GetCompletionPosition() should return the position in the file when information is available):
|
||||
let b:ale_completion_info = {'line': 1, 'column': 6}
|
||||
|
||||
" This is the first character of 'bar'
|
||||
AssertEqual 4, ale#completion#GetCompletionPosition()
|
||||
|
||||
Execute(ale#completion#CanProvideCompletions should return 0 when no completion sources are available):
|
||||
AssertEqual 0, ale#completion#CanProvideCompletions()
|
||||
|
||||
Execute(ale#completion#CanProvideCompletions should return 1 when at least one completion source is available):
|
||||
runtime ale_linters/python/pyls.vim
|
||||
let b:ale_linters = ['pyls']
|
||||
|
||||
AssertEqual 1, ale#completion#CanProvideCompletions()
|
@ -23,7 +23,7 @@ class DeopleteSourceTest(unittest.TestCase):
|
||||
super(DeopleteSourceTest, self).setUp()
|
||||
|
||||
self.call_list = []
|
||||
self.call_results = {}
|
||||
self.call_results = {'ale#completion#CanProvideCompletions': 1}
|
||||
self.source = ale_module.Source('vim')
|
||||
self.source.vim = VimMock(self.call_list, self.call_results)
|
||||
|
||||
@ -59,27 +59,41 @@ class DeopleteSourceTest(unittest.TestCase):
|
||||
def test_request_completion_results(self):
|
||||
context = {'is_async': False}
|
||||
|
||||
self.assertIsNone(self.source.gather_candidates(context))
|
||||
self.assertEqual(self.source.gather_candidates(context), [])
|
||||
self.assertEqual(context, {'is_async': True})
|
||||
self.assertEqual(self.call_list, [
|
||||
('ale#completion#CanProvideCompletions', ()),
|
||||
('ale#completion#GetCompletions', ('deoplete',)),
|
||||
])
|
||||
|
||||
def test_request_completion_results_from_buffer_without_providers(self):
|
||||
self.call_results['ale#completion#CanProvideCompletions'] = 0
|
||||
context = {'is_async': False}
|
||||
|
||||
self.assertIsNone(self.source.gather_candidates(context), [])
|
||||
self.assertEqual(context, {'is_async': False})
|
||||
self.assertEqual(self.call_list, [
|
||||
('ale#completion#CanProvideCompletions', ()),
|
||||
])
|
||||
|
||||
def test_refresh_completion_results(self):
|
||||
context = {'is_async': False}
|
||||
|
||||
self.assertIsNone(self.source.gather_candidates(context))
|
||||
self.assertEqual(self.source.gather_candidates(context), [])
|
||||
self.assertEqual(context, {'is_async': True})
|
||||
self.assertEqual(self.call_list, [
|
||||
('ale#completion#CanProvideCompletions', ()),
|
||||
('ale#completion#GetCompletions', ('deoplete',)),
|
||||
])
|
||||
|
||||
context = {'is_async': True, 'is_refresh': True}
|
||||
|
||||
self.assertIsNone(self.source.gather_candidates(context))
|
||||
self.assertEqual(self.source.gather_candidates(context), [])
|
||||
self.assertEqual(context, {'is_async': True, 'is_refresh': True})
|
||||
self.assertEqual(self.call_list, [
|
||||
('ale#completion#CanProvideCompletions', ()),
|
||||
('ale#completion#GetCompletions', ('deoplete',)),
|
||||
('ale#completion#CanProvideCompletions', ()),
|
||||
('ale#completion#GetCompletions', ('deoplete',)),
|
||||
])
|
||||
|
||||
@ -87,9 +101,10 @@ class DeopleteSourceTest(unittest.TestCase):
|
||||
context = {'is_async': True}
|
||||
self.call_results['ale#completion#GetCompletionResult'] = None
|
||||
|
||||
self.assertIsNone(self.source.gather_candidates(context))
|
||||
self.assertEqual(self.source.gather_candidates(context), [])
|
||||
self.assertEqual(context, {'is_async': True})
|
||||
self.assertEqual(self.call_list, [
|
||||
('ale#completion#CanProvideCompletions', ()),
|
||||
('ale#completion#GetCompletionResult', ()),
|
||||
])
|
||||
|
||||
@ -100,6 +115,7 @@ class DeopleteSourceTest(unittest.TestCase):
|
||||
self.assertEqual(self.source.gather_candidates(context), [])
|
||||
self.assertEqual(context, {'is_async': False})
|
||||
self.assertEqual(self.call_list, [
|
||||
('ale#completion#CanProvideCompletions', ()),
|
||||
('ale#completion#GetCompletionResult', ()),
|
||||
])
|
||||
|
||||
@ -126,5 +142,6 @@ class DeopleteSourceTest(unittest.TestCase):
|
||||
])
|
||||
self.assertEqual(context, {'is_async': False})
|
||||
self.assertEqual(self.call_list, [
|
||||
('ale#completion#CanProvideCompletions', ()),
|
||||
('ale#completion#GetCompletionResult', ()),
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user