Close #1753 - Implement minimum viable integration with Deoplete

This commit is contained in:
w0rp
2019-04-23 21:26:16 +01:00
parent ce0b14979e
commit 01331266a8
10 changed files with 354 additions and 71 deletions

View File

@@ -27,7 +27,7 @@ Before:
let g:get_completions_called = 0
" We just want to check if the function is called.
function! ale#completion#GetCompletions(manual)
function! ale#completion#GetCompletions(source)
let g:get_completions_called = 1
endfunction
@@ -57,6 +57,7 @@ After:
unlet! b:ale_completion_info
unlet! b:ale_completion_response
unlet! b:ale_completion_parser
unlet! b:ale_completion_result
unlet! b:ale_complete_done_time
delfunction CheckCompletionCalled
@@ -86,7 +87,7 @@ Execute(ale#completion#GetCompletions should not be called when the cursor posit
call setpos('.', [bufnr(''), 1, 2, 0])
" We just want to check if the function is called.
function! ale#completion#GetCompletions(manual)
function! ale#completion#GetCompletions(source)
let g:get_completions_called = 1
endfunction
@@ -105,7 +106,7 @@ Execute(ale#completion#GetCompletions should not be called if you switch to norm
let g:fake_mode = 'n'
" We just want to check if the function is called.
function! ale#completion#GetCompletions(manual)
function! ale#completion#GetCompletions(source)
let g:get_completions_called = 1
endfunction
@@ -124,6 +125,7 @@ Execute(Completion should not be done shortly after the CompleteDone function):
Execute(ale#completion#Show() should remember the omnifunc setting and replace it):
let &l:omnifunc = 'FooBar'
let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser')
AssertEqual 'FooBar', b:ale_old_omnifunc
@@ -136,6 +138,7 @@ Execute(ale#completion#Show() should remember the omnifunc setting and replace i
Execute(ale#completion#Show() should remember the completeopt setting and replace it):
let &l:completeopt = 'menu'
let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser')
AssertEqual 'menu', b:ale_old_completeopt
@@ -148,6 +151,7 @@ Execute(ale#completion#Show() should remember the completeopt setting and replac
Execute(ale#completion#Show() should set the preview option if it's set):
let &l:completeopt = 'menu,preview'
let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser')
AssertEqual 'menu,preview', b:ale_old_completeopt
@@ -158,7 +162,7 @@ Execute(ale#completion#Show() should set the preview option if it's set):
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
Execute(ale#completion#Show() should not replace the completeopt setting for manual completion):
let b:ale_completion_info = {'manual': 1}
let b:ale_completion_info = {'source': 'ale-manual'}
let &l:completeopt = 'menu,preview'
@@ -173,6 +177,7 @@ Execute(ale#completion#Show() should not replace the completeopt setting for man
Execute(ale#completion#OmniFunc() should also remember the completeopt setting and replace it):
let &l:completeopt = 'menu'
let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#OmniFunc(0, '')
AssertEqual 'menu', b:ale_old_completeopt
@@ -181,18 +186,35 @@ Execute(ale#completion#OmniFunc() should also remember the completeopt setting a
Execute(ale#completion#OmniFunc() should set the preview option if it's set):
let &l:completeopt = 'menu,preview'
let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#OmniFunc(0, '')
AssertEqual 'menu,preview', b:ale_old_completeopt
AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt
Execute(ale#completion#Show() should make the correct feedkeys() call):
Execute(ale#completion#Show() should make the correct feedkeys() call for automatic completion):
let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser')
AssertEqual [], g:feedkeys_calls
sleep 1ms
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
Execute(ale#completion#Show() should make the correct feedkeys() call for manual completion):
let b:ale_completion_info = {'source': 'ale-automatic'}
call ale#completion#Show('Response', 'Parser')
AssertEqual [], g:feedkeys_calls
sleep 1ms
AssertEqual [["\<Plug>(ale_show_completion_menu)"]], g:feedkeys_calls
Execute(ale#completion#Show() should not call feedkeys() for other sources):
let b:ale_completion_info = {'source': 'deoplete'}
call ale#completion#Show('Response', 'Parser')
sleep 1ms
AssertEqual [], g:feedkeys_calls
Execute(ale#completion#Show() shouldn't do anything if you switch back to normal mode):
let &l:completeopt = 'menu,preview'
let g:fake_mode = 'n'
@@ -247,9 +269,10 @@ Execute(The completion request_id should be reset when queuing again):
AssertEqual 0, b:ale_completion_info.request_id
Execute(b:ale_completion_info should be set up correctly when requesting completions):
Execute(b:ale_completion_info should be set up correctly when requesting completions automatically):
let b:ale_completion_result = []
call setpos('.', [bufnr(''), 3, 14, 0])
call ale#completion#GetCompletions(0)
call ale#completion#GetCompletions('ale-automatic')
AssertEqual
\ {
@@ -259,11 +282,13 @@ Execute(b:ale_completion_info should be set up correctly when requesting complet
\ 'line_length': 14,
\ 'line': 3,
\ 'prefix': 'ab',
\ 'manual': 0,
\ 'source': 'ale-automatic',
\ },
\ b:ale_completion_info
Assert !exists('b:ale_completion_result')
Execute(b:ale_completion_info should be set up correctly when requesting completions):
Execute(b:ale_completion_info should be set up correctly when requesting completions manually):
let b:ale_completion_result = []
call setpos('.', [bufnr(''), 3, 14, 0])
ALEComplete
@@ -275,9 +300,28 @@ Execute(b:ale_completion_info should be set up correctly when requesting complet
\ 'line_length': 14,
\ 'line': 3,
\ 'prefix': 'ab',
\ 'manual': 1,
\ 'source': 'ale-manual',
\ },
\ b:ale_completion_info
Assert !exists('b:ale_completion_result')
Execute(b:ale_completion_info should be set up correctly for other sources):
let b:ale_completion_result = []
call setpos('.', [bufnr(''), 3, 14, 0])
call ale#completion#GetCompletions('deoplete')
AssertEqual
\ {
\ 'request_id': 0,
\ 'conn_id': 0,
\ 'column': 14,
\ 'line_length': 14,
\ 'line': 3,
\ 'prefix': 'ab',
\ 'source': 'deoplete',
\ },
\ b:ale_completion_info
Assert !exists('b:ale_completion_result')
Execute(The correct keybinds should be configured):
redir => g:output

View File

@@ -102,7 +102,7 @@ Execute(The right message should be sent for the initial tsserver request):
" The cursor position needs to match what was saved before.
call setpos('.', [bufnr(''), 1, 3, 0])
call ale#completion#GetCompletions(0)
call ale#completion#GetCompletions('ale-automatic')
" We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback)
@@ -129,7 +129,7 @@ Execute(The right message should be sent for the initial tsserver request):
\ 'request_id': 1,
\ 'line': 1,
\ 'prefix': 'fo',
\ 'manual': 0,
\ 'source': 'ale-automatic',
\ },
\ get(b:, 'ale_completion_info', {})
@@ -191,7 +191,7 @@ Execute(The right message should be sent for the initial LSP request):
" The cursor position needs to match what was saved before.
call setpos('.', [bufnr(''), 1, 5, 0])
call ale#completion#GetCompletions(0)
call ale#completion#GetCompletions('ale-automatic')
" We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback)
@@ -234,7 +234,7 @@ Execute(The right message should be sent for the initial LSP request):
\ 'request_id': 1,
\ 'line': 1,
\ 'prefix': 'fo',
\ 'manual': 0,
\ 'source': 'ale-automatic',
\ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
\ },
\ get(b:, 'ale_completion_info', {})
@@ -260,7 +260,7 @@ Execute(Two completion requests shouldn't be sent in a row):
" The cursor position needs to match what was saved before.
call setpos('.', [bufnr(''), 1, 5, 0])
call ale#completion#GetCompletions(0)
call ale#completion#GetCompletions('ale-automatic')
" We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback)

View File

@@ -0,0 +1,130 @@
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):
self.__call_list = call_list
self.__call_results = call_results
def call(self, function, *args):
self.__call_list.append((function, args))
return self.__call_results.get(function, 0)
class DeopleteSourceTest(unittest.TestCase):
def setUp(self):
super(DeopleteSourceTest, self).setUp()
self.call_list = []
self.call_results = {}
self.source = ale_module.Source('vim')
self.source.vim = VimMock(self.call_list, self.call_results)
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, {
'is_bytepos': True,
'mark': '[L]',
'min_pattern_length': 1,
'name': 'ale',
'rank': 100,
})
def test_completion_position(self):
self.call_results['ale#completion#GetCompletionPosition'] = 2
self.assertEqual(self.source.get_completion_position(), 2)
self.assertEqual(self.call_list, [
('ale#completion#GetCompletionPosition', ()),
])
def test_request_completion_results(self):
context = {'is_async': False}
self.assertEqual(self.source.gather_candidates(context), [])
self.assertEqual(context, {'is_async': True})
self.assertEqual(self.call_list, [
('ale#completion#GetCompletions', ('deoplete',)),
])
def test_refresh_completion_results(self):
context = {'is_async': False}
self.assertEqual(self.source.gather_candidates(context), [])
self.assertEqual(context, {'is_async': True})
self.assertEqual(self.call_list, [
('ale#completion#GetCompletions', ('deoplete',)),
])
context = {'is_async': True, 'is_refresh': True}
self.assertEqual(self.source.gather_candidates(context), [])
self.assertEqual(context, {'is_async': True, 'is_refresh': True})
self.assertEqual(self.call_list, [
('ale#completion#GetCompletions', ('deoplete',)),
('ale#completion#GetCompletions', ('deoplete',)),
])
def test_poll_no_result(self):
context = {'is_async': True}
self.call_results['ale#completion#GetCompletionResult'] = None
self.assertEqual(self.source.gather_candidates(context), [])
self.assertEqual(context, {'is_async': True})
self.assertEqual(self.call_list, [
('ale#completion#GetCompletionResult', ()),
])
def test_poll_empty_result_ready(self):
context = {'is_async': True}
self.call_results['ale#completion#GetCompletionResult'] = []
self.assertEqual(self.source.gather_candidates(context), [])
self.assertEqual(context, {'is_async': False})
self.assertEqual(self.call_list, [
('ale#completion#GetCompletionResult', ()),
])
def test_poll_non_empty_result_ready(self):
context = {'is_async': 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(context, {'is_async': False})
self.assertEqual(self.call_list, [
('ale#completion#GetCompletionResult', ()),
])

View File

@@ -67,4 +67,14 @@ echo
test/script/check-toc || exit_code=$?
echo '========================================'
echo 'Check Python code'
echo '========================================'
echo
docker run --rm -v "$PWD:/testplugin" "$DOCKER_RUN_IMAGE" \
python -W ignore -m unittest discover /testplugin/test/python \
|| exit_code=$?
echo
exit $exit_code