2017-07-24 04:23:53 -04:00
|
|
|
Before:
|
|
|
|
Save g:ale_completion_enabled
|
2017-08-15 19:45:46 -04:00
|
|
|
Save g:ale_completion_delay
|
2017-08-18 17:34:18 -04:00
|
|
|
Save g:ale_completion_max_suggestions
|
2017-08-15 19:45:46 -04:00
|
|
|
Save &l:omnifunc
|
2017-08-17 18:06:02 -04:00
|
|
|
Save &l:completeopt
|
2017-08-15 19:45:46 -04:00
|
|
|
|
|
|
|
let g:test_vars = {
|
|
|
|
\ 'feedkeys_calls': [],
|
|
|
|
\}
|
|
|
|
|
|
|
|
call ale#completion#Nop()
|
|
|
|
|
|
|
|
function! ale#completion#FeedKeys(string, mode) abort
|
|
|
|
call add(g:test_vars.feedkeys_calls, [a:string, a:mode])
|
|
|
|
endfunction
|
2017-07-24 04:23:53 -04:00
|
|
|
|
|
|
|
After:
|
|
|
|
Restore
|
|
|
|
|
2017-08-15 19:45:46 -04:00
|
|
|
unlet! g:test_vars
|
2017-08-17 18:06:02 -04:00
|
|
|
unlet! b:ale_old_omnifunc
|
|
|
|
unlet! b:ale_old_completopt
|
2017-08-15 19:45:46 -04:00
|
|
|
unlet! b:ale_completion_info
|
|
|
|
unlet! b:ale_completion_response
|
|
|
|
unlet! b:ale_completion_parser
|
|
|
|
|
|
|
|
runtime autoload/ale/completion.vim
|
2017-08-18 17:34:18 -04:00
|
|
|
runtime autoload/ale/lsp.vim
|
2017-08-15 19:45:46 -04:00
|
|
|
|
|
|
|
if g:ale_completion_enabled
|
|
|
|
call ale#completion#Enable()
|
|
|
|
else
|
2017-07-24 04:23:53 -04:00
|
|
|
call ale#completion#Disable()
|
|
|
|
endif
|
|
|
|
|
2017-07-01 19:28:00 -04:00
|
|
|
Execute(TypeScript completions responses should be parsed correctly):
|
|
|
|
AssertEqual [],
|
|
|
|
\ ale#completion#ParseTSServerCompletions({
|
|
|
|
\ 'body': [],
|
|
|
|
\})
|
|
|
|
AssertEqual ['foo', 'bar', 'baz'],
|
|
|
|
\ ale#completion#ParseTSServerCompletions({
|
|
|
|
\ 'body': [
|
|
|
|
\ {'name': 'foo'},
|
|
|
|
\ {'name': 'bar'},
|
|
|
|
\ {'name': 'baz'},
|
|
|
|
\ ],
|
|
|
|
\})
|
|
|
|
|
|
|
|
Execute(TypeScript completion details responses should be parsed correctly):
|
|
|
|
AssertEqual
|
|
|
|
\ [
|
|
|
|
\ {
|
|
|
|
\ 'word': 'abc',
|
|
|
|
\ 'menu': '(property) Foo.abc: number',
|
|
|
|
\ 'info': '',
|
2017-08-04 08:35:02 -04:00
|
|
|
\ 'kind': 'f',
|
|
|
|
\ 'icase': 1,
|
2017-07-01 19:28:00 -04:00
|
|
|
\ },
|
|
|
|
\ {
|
|
|
|
\ 'word': 'def',
|
|
|
|
\ 'menu': '(property) Foo.def: number',
|
|
|
|
\ 'info': 'foo bar baz',
|
2017-08-04 08:35:02 -04:00
|
|
|
\ 'kind': 'f',
|
|
|
|
\ 'icase': 1,
|
2017-07-01 19:28:00 -04:00
|
|
|
\ },
|
|
|
|
\ ],
|
|
|
|
\ ale#completion#ParseTSServerCompletionEntryDetails({
|
|
|
|
\ 'body': [
|
|
|
|
\ {
|
|
|
|
\ 'name': 'abc',
|
|
|
|
\ 'kind': 'parameterName',
|
|
|
|
\ 'displayParts': [
|
|
|
|
\ {'text': '('},
|
|
|
|
\ {'text': 'property'},
|
|
|
|
\ {'text': ')'},
|
|
|
|
\ {'text': ' '},
|
|
|
|
\ {'text': 'Foo'},
|
|
|
|
\ {'text': '.'},
|
|
|
|
\ {'text': 'abc'},
|
|
|
|
\ {'text': ':'},
|
|
|
|
\ {'text': ' '},
|
|
|
|
\ {'text': 'number'},
|
|
|
|
\ ],
|
|
|
|
\ },
|
|
|
|
\ {
|
|
|
|
\ 'name': 'def',
|
|
|
|
\ 'kind': 'parameterName',
|
|
|
|
\ 'displayParts': [
|
|
|
|
\ {'text': '('},
|
|
|
|
\ {'text': 'property'},
|
|
|
|
\ {'text': ')'},
|
|
|
|
\ {'text': ' '},
|
|
|
|
\ {'text': 'Foo'},
|
|
|
|
\ {'text': '.'},
|
|
|
|
\ {'text': 'def'},
|
|
|
|
\ {'text': ':'},
|
|
|
|
\ {'text': ' '},
|
|
|
|
\ {'text': 'number'},
|
|
|
|
\ ],
|
|
|
|
\ 'documentation': [
|
|
|
|
\ {'text': 'foo'},
|
|
|
|
\ {'text': ' '},
|
|
|
|
\ {'text': 'bar'},
|
|
|
|
\ {'text': ' '},
|
|
|
|
\ {'text': 'baz'},
|
|
|
|
\ ],
|
|
|
|
\ },
|
|
|
|
\ ],
|
|
|
|
\})
|
|
|
|
|
2017-08-18 17:34:18 -04:00
|
|
|
Execute(Prefix filtering should work for Lists of strings):
|
|
|
|
AssertEqual
|
|
|
|
\ ['FooBar', 'foo'],
|
|
|
|
\ ale#completion#Filter(['FooBar', 'FongBar', 'baz', 'foo'], 'foo')
|
|
|
|
AssertEqual
|
|
|
|
\ ['FooBar', 'FongBar', 'baz', 'foo'],
|
|
|
|
\ ale#completion#Filter(['FooBar', 'FongBar', 'baz', 'foo'], '.')
|
|
|
|
|
|
|
|
Execute(Prefix filtering should work for completion items):
|
|
|
|
AssertEqual
|
|
|
|
\ [{'word': 'FooBar'}, {'word': 'foo'}],
|
|
|
|
\ ale#completion#Filter(
|
|
|
|
\ [
|
|
|
|
\ {'word': 'FooBar'},
|
|
|
|
\ {'word': 'FongBar'},
|
|
|
|
\ {'word': 'baz'},
|
|
|
|
\ {'word': 'foo'},
|
|
|
|
\ ],
|
|
|
|
\ 'foo'
|
|
|
|
\ )
|
|
|
|
AssertEqual
|
|
|
|
\ [
|
|
|
|
\ {'word': 'FooBar'},
|
|
|
|
\ {'word': 'FongBar'},
|
|
|
|
\ {'word': 'baz'},
|
|
|
|
\ {'word': 'foo'},
|
|
|
|
\ ],
|
|
|
|
\ ale#completion#Filter(
|
|
|
|
\ [
|
|
|
|
\ {'word': 'FooBar'},
|
|
|
|
\ {'word': 'FongBar'},
|
|
|
|
\ {'word': 'baz'},
|
|
|
|
\ {'word': 'foo'},
|
|
|
|
\ ],
|
|
|
|
\ '.'
|
|
|
|
\ )
|
|
|
|
|
|
|
|
Execute(The right message sent to the tsserver LSP when the first completion message is received):
|
|
|
|
" The cursor position needs to match what was saved before.
|
|
|
|
call setpos('.', [bufnr(''), 1, 1, 0])
|
|
|
|
let b:ale_completion_info = {
|
|
|
|
\ 'conn_id': 123,
|
|
|
|
\ 'prefix': 'f',
|
|
|
|
\ 'request_id': 4,
|
|
|
|
\ 'line': 1,
|
|
|
|
\ 'column': 1,
|
|
|
|
\}
|
|
|
|
" We should only show up to this many suggestions.
|
|
|
|
let g:ale_completion_max_suggestions = 3
|
|
|
|
|
|
|
|
" Replace the Send function for LSP, so we can monitor calls to it.
|
|
|
|
function! ale#lsp#Send(conn_id, message) abort
|
|
|
|
let g:test_vars.message = a:message
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Handle the response for completions.
|
|
|
|
call ale#completion#HandleTSServerLSPResponse(123, {
|
|
|
|
\ 'request_seq': 4,
|
|
|
|
\ 'command': 'completions',
|
|
|
|
\ 'body': [
|
|
|
|
\ {'name': 'Baz'},
|
|
|
|
\ {'name': 'dingDong'},
|
|
|
|
\ {'name': 'Foo'},
|
|
|
|
\ {'name': 'FooBar'},
|
|
|
|
\ {'name': 'frazzle'},
|
|
|
|
\ {'name': 'FFS'},
|
|
|
|
\ ],
|
|
|
|
\})
|
|
|
|
|
|
|
|
" The entry details messages should have been sent.
|
|
|
|
AssertEqual
|
|
|
|
\ [
|
|
|
|
\ 0,
|
|
|
|
\ 'ts@completionEntryDetails',
|
|
|
|
\ {
|
|
|
|
\ 'file': expand('%:p'),
|
|
|
|
\ 'entryNames': ['Foo', 'FooBar', 'frazzle'],
|
|
|
|
\ 'offset': 1,
|
|
|
|
\ 'line': 1,
|
|
|
|
\ },
|
|
|
|
\ ],
|
|
|
|
\ g:test_vars.message
|
|
|
|
|
2017-07-01 19:28:00 -04:00
|
|
|
Given typescript():
|
|
|
|
let abc = y.
|
|
|
|
let foo = ab
|
|
|
|
let foo = (ab)
|
|
|
|
|
|
|
|
Execute(Completion should be done after dots in TypeScript):
|
|
|
|
AssertEqual '.', ale#completion#GetPrefix(&filetype, 1, 13)
|
|
|
|
|
|
|
|
Execute(Completion should be done after words in TypeScript):
|
|
|
|
AssertEqual 'ab', ale#completion#GetPrefix(&filetype, 2, 13)
|
|
|
|
|
|
|
|
Execute(Completion should be done after words in parens in TypeScript):
|
|
|
|
AssertEqual 'ab', ale#completion#GetPrefix(&filetype, 3, 14)
|
|
|
|
|
|
|
|
Execute(Completion should not be done after parens in TypeScript):
|
|
|
|
AssertEqual '', ale#completion#GetPrefix(&filetype, 3, 15)
|
2017-08-15 19:45:46 -04:00
|
|
|
|
|
|
|
Execute(ale#completion#Show() should remember the omnifunc setting and replace it):
|
|
|
|
let &l:omnifunc = 'FooBar'
|
|
|
|
|
|
|
|
call ale#completion#Show('Response', 'Parser')
|
|
|
|
|
|
|
|
AssertEqual 'FooBar', b:ale_old_omnifunc
|
|
|
|
AssertEqual 'ale#completion#OmniFunc', &l:omnifunc
|
|
|
|
|
2017-08-17 18:06:02 -04:00
|
|
|
Execute(ale#completion#Show() should remember the completeopt setting and replace it):
|
|
|
|
let &l:completeopt = 'menu'
|
|
|
|
|
|
|
|
call ale#completion#Show('Response', 'Parser')
|
|
|
|
|
|
|
|
AssertEqual 'menu', b:ale_old_completopt
|
|
|
|
AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt
|
|
|
|
|
2017-08-18 16:06:21 -04:00
|
|
|
Execute(ale#completion#OmniFunc() should also remember the completeopt setting and replace it):
|
|
|
|
let &l:completeopt = 'menu'
|
|
|
|
|
|
|
|
call ale#completion#OmniFunc(0, '')
|
|
|
|
|
|
|
|
AssertEqual 'menu', b:ale_old_completopt
|
|
|
|
AssertEqual 'menu,menuone,preview,noselect,noinsert', &l:completeopt
|
|
|
|
|
2017-08-15 19:45:46 -04:00
|
|
|
Execute(ale#completion#Show() should make the correct feedkeys() call):
|
|
|
|
call ale#completion#Show('Response', 'Parser')
|
|
|
|
|
|
|
|
AssertEqual [["\<C-x>\<C-o>", 'n']], g:test_vars.feedkeys_calls
|
|
|
|
|
|
|
|
Execute(ale#completion#Show() should set up the response and parser):
|
|
|
|
call ale#completion#Show('Response', 'Parser')
|
|
|
|
|
|
|
|
AssertEqual 'Response', b:ale_completion_response
|
|
|
|
AssertEqual 'Parser', b:ale_completion_parser
|
|
|
|
|
|
|
|
Execute(ale#completion#Done() should restore old omnifunc values):
|
|
|
|
let b:ale_old_omnifunc = 'FooBar'
|
|
|
|
|
|
|
|
call ale#completion#Done()
|
|
|
|
|
|
|
|
" We reset the old omnifunc setting and remove the buffer variable.
|
|
|
|
AssertEqual 'FooBar', &l:omnifunc
|
|
|
|
Assert !has_key(b:, 'ale_old_omnifunc')
|
|
|
|
|
2017-08-17 18:06:02 -04:00
|
|
|
Execute(ale#completion#Done() should restore the old completeopt setting):
|
|
|
|
let b:ale_old_completopt = 'menu'
|
|
|
|
let &l:completeopt = 'menu,menuone,preview,noselect,noinsert'
|
|
|
|
|
|
|
|
call ale#completion#Done()
|
|
|
|
|
|
|
|
AssertEqual 'menu', &l:completeopt
|
|
|
|
Assert !has_key(b:, 'ale_old_completopt')
|
|
|
|
|
|
|
|
Execute(ale#completion#Done() should leave settings alone when none were remembered):
|
|
|
|
let &l:omnifunc = 'BazBoz'
|
|
|
|
let &l:completeopt = 'menu'
|
|
|
|
|
|
|
|
call ale#completion#Done()
|
|
|
|
|
|
|
|
AssertEqual 'BazBoz', &l:omnifunc
|
|
|
|
AssertEqual 'menu', &l:completeopt
|
|
|
|
|
2017-08-15 19:45:46 -04:00
|
|
|
Execute(The completion request_id should be reset when queuing again):
|
|
|
|
let b:ale_completion_info = {'request_id': 123}
|
|
|
|
|
|
|
|
let g:ale_completion_delay = 0
|
|
|
|
call ale#completion#Queue()
|
|
|
|
sleep 1m
|
|
|
|
|
|
|
|
AssertEqual 0, b:ale_completion_info.request_id
|
|
|
|
|
|
|
|
Execute(b:ale_completion_info should be set up correctly when requesting completions):
|
|
|
|
call setpos('.', [bufnr(''), 3, 14, 0])
|
|
|
|
call ale#completion#GetCompletions()
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'request_id': 0,
|
|
|
|
\ 'conn_id': 0,
|
|
|
|
\ 'column': 14,
|
|
|
|
\ 'line': 3,
|
|
|
|
\ 'prefix': 'ab',
|
|
|
|
\ },
|
|
|
|
\ b:ale_completion_info
|
|
|
|
|
|
|
|
Execute(ale#completion#GetCompletions should be called when the cursor position stays the same):
|
|
|
|
let g:test_vars.get_completions_called = 0
|
|
|
|
|
|
|
|
" We just want to check if the function is called.
|
|
|
|
function! ale#completion#GetCompletions()
|
|
|
|
let g:test_vars.get_completions_called = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:ale_completion_delay = 0
|
|
|
|
call ale#completion#Queue()
|
|
|
|
sleep 1m
|
|
|
|
|
|
|
|
Assert g:test_vars.get_completions_called
|
|
|
|
|
|
|
|
Execute(ale#completion#GetCompletions should not be called when the cursor position changes):
|
|
|
|
call setpos('.', [bufnr(''), 1, 2, 0])
|
|
|
|
|
|
|
|
let g:test_vars.get_completions_called = 0
|
|
|
|
|
|
|
|
" We just want to check if the function is called.
|
|
|
|
function! ale#completion#GetCompletions()
|
|
|
|
let g:test_vars.get_completions_called = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:ale_completion_delay = 0
|
|
|
|
call ale#completion#Queue()
|
|
|
|
|
|
|
|
" Change the cursor position before the callback is triggered.
|
|
|
|
call setpos('.', [bufnr(''), 2, 2, 0])
|
|
|
|
|
|
|
|
sleep 1m
|
|
|
|
|
|
|
|
Assert !g:test_vars.get_completions_called
|