mirror of
https://github.com/dense-analysis/ale
synced 2024-12-24 07:02:52 +00:00
0cb432cb82
* Add autoimport support for deoplete * Fix test_deoplete_source.py * Use callback instead of is_async for deoplete Shuogo, the author of Deoplete, does not recommend using the `is_async` option: > I think is_async is not recommended. It is not so useful and broken. > You should use callback system instead. Link: https://github.com/Shougo/deoplete.nvim/issues/1006#issuecomment-526797857 Incidentally, the same thread mentiones an issue started by w0rp: https://github.com/Shougo/deoplete.nvim/issues/976 The deoplete docs also say is_async is deprecated: > is_async (Bool) > If the gather is asynchronous, the source must set > it to "True". A typical strategy for an asynchronous > gather_candidates method to use this flag is to > set is_async flag to True while results are being > produced in the background (optionally, returning them > as they become ready). Once background processing > has completed, is_async flag should be set to False > indicating that this is the last portion of the > candidates. > > Note: The feature is deprecated and not recommended. > You should use callback system by > |deoplete#auto_complete()| instead. Link: https://github.com/Shougo/deoplete.nvim/blob/master/doc/deoplete.txt Co-authored-by: w0rp <w0rp@users.noreply.github.com>
121 lines
3.7 KiB
Python
121 lines
3.7 KiB
Python
import unittest
|
|
import imp
|
|
|
|
ale_module = imp.load_source(
|
|
'deoplete.sources.ale',
|
|
'/testplugin/rplugin/python3/deoplete/sources/ale.py',
|
|
)
|
|
|
|
|
|
class VimMock(object):
|
|
def __init__(self, call_list, call_results, commands):
|
|
self.__call_list = call_list
|
|
self.__call_results = call_results
|
|
|
|
self.__commands = commands
|
|
|
|
def call(self, function, *args):
|
|
self.__call_list.append((function, args))
|
|
|
|
return self.__call_results.get(function, 0)
|
|
|
|
def command(self, command):
|
|
self.__commands.append(command)
|
|
|
|
|
|
class DeopleteSourceTest(unittest.TestCase):
|
|
def setUp(self):
|
|
super(DeopleteSourceTest, self).setUp()
|
|
|
|
self.call_list = []
|
|
self.call_results = {'ale#completion#CanProvideCompletions': 1}
|
|
self.commands = []
|
|
self.source = ale_module.Source('vim')
|
|
self.source.vim = VimMock(
|
|
self.call_list, self.call_results, self.commands)
|
|
|
|
def test_attributes(self):
|
|
"""
|
|
Check all of the attributes we set.
|
|
"""
|
|
attributes = dict(
|
|
(key, getattr(self.source, key))
|
|
for key in
|
|
dir(self.source)
|
|
if not key.startswith('__')
|
|
and key != 'vim'
|
|
and not hasattr(getattr(self.source, key), '__self__')
|
|
)
|
|
|
|
self.assertEqual(attributes, {
|
|
'input_patterns': {
|
|
'_': r'\.\w*$',
|
|
'rust': r'(\.|::)\w*$',
|
|
'typescript': r'(\.|\'|")\w*$',
|
|
'cpp': r'(\.|::|->)\w*$',
|
|
},
|
|
'is_bytepos': True,
|
|
'is_volatile': True,
|
|
'mark': '[L]',
|
|
'min_pattern_length': 1,
|
|
'name': 'ale',
|
|
'rank': 1000,
|
|
})
|
|
|
|
def test_complete_position(self):
|
|
self.call_results['ale#completion#GetCompletionPositionForDeoplete'] = 2
|
|
context = {'input': 'foo'}
|
|
|
|
self.assertEqual(self.source.get_complete_position(context), 2)
|
|
self.assertEqual(self.call_list, [
|
|
('ale#completion#GetCompletionPositionForDeoplete', ('foo',)),
|
|
])
|
|
|
|
def test_request_completion_results(self):
|
|
context = {'event': 'TextChangedI', 'is_refresh': True}
|
|
|
|
self.assertEqual(self.source.gather_candidates(context), [])
|
|
self.assertEqual(self.call_list, [
|
|
('ale#completion#CanProvideCompletions', ()),
|
|
])
|
|
self.assertEqual(self.commands, [
|
|
"call ale#completion#GetCompletions('ale-callback', " + \
|
|
"{'callback': {completions -> deoplete#auto_complete() }})"
|
|
])
|
|
|
|
def test_request_completion_results_from_buffer_without_providers(self):
|
|
self.call_results['ale#completion#CanProvideCompletions'] = 0
|
|
context = {'event': 'TextChangedI', 'is_refresh': True}
|
|
|
|
self.assertIsNone(self.source.gather_candidates(context), [])
|
|
self.assertEqual(self.call_list, [
|
|
('ale#completion#CanProvideCompletions', ()),
|
|
])
|
|
|
|
def test_async_event(self):
|
|
context = {'event': 'Async', 'is_refresh': True}
|
|
self.call_results['ale#completion#GetCompletionResult'] = [
|
|
{
|
|
'word': 'foobar',
|
|
'kind': 'v',
|
|
'icase': 1,
|
|
'menu': '',
|
|
'info': '',
|
|
},
|
|
]
|
|
|
|
self.assertEqual(self.source.gather_candidates(context), [
|
|
{
|
|
'word': 'foobar',
|
|
'kind': 'v',
|
|
'icase': 1,
|
|
'menu': '',
|
|
'info': '',
|
|
},
|
|
])
|
|
|
|
self.assertEqual(self.call_list, [
|
|
('ale#completion#CanProvideCompletions', ()),
|
|
('ale#completion#GetCompletionResult', ()),
|
|
])
|