summaryrefslogtreecommitdiff
path: root/test/completion/test_lsp_completion_messages.vader
diff options
context:
space:
mode:
Diffstat (limited to 'test/completion/test_lsp_completion_messages.vader')
-rw-r--r--test/completion/test_lsp_completion_messages.vader89
1 files changed, 82 insertions, 7 deletions
diff --git a/test/completion/test_lsp_completion_messages.vader b/test/completion/test_lsp_completion_messages.vader
index 00a174dc..ed0f358b 100644
--- a/test/completion/test_lsp_completion_messages.vader
+++ b/test/completion/test_lsp_completion_messages.vader
@@ -13,11 +13,11 @@ Before:
runtime autoload/ale/lsp.vim
let g:message_list = []
+ let g:capability_checked = ''
let g:Callback = ''
+ let g:wait_callback_list = []
- function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort
- let g:Callback = a:callback
-
+ function! ale#lsp_linter#StartLSP(buffer, linter) abort
let l:conn = ale#lsp#NewConnection({})
let l:conn.id = 347
let l:conn.open_documents = {a:buffer : -1}
@@ -35,15 +35,28 @@ Before:
return 'i'
endfunction
+ function! ale#lsp#WaitForCapability(conn_id, project_root, capability, callback) abort
+ let g:capability_checked = a:capability
+ call add(g:wait_callback_list, a:callback)
+ endfunction
+
+ function! ale#lsp#RegisterCallback(conn_id, callback) abort
+ let g:Callback = a:callback
+ endfunction
+
" Replace the Send function for LSP, so we can monitor calls to it.
function! ale#lsp#Send(conn_id, message, ...) abort
call add(g:message_list, a:message)
+
+ return 1
endfunction
After:
Restore
unlet! g:message_list
+ unlet! g:capability_checked
+ unlet! g:wait_callback_list
unlet! g:Callback
unlet! b:ale_old_omnifunc
unlet! b:ale_old_completopt
@@ -84,6 +97,13 @@ Execute(The right message should be sent for the initial tsserver request):
call ale#completion#GetCompletions()
+ " We shouldn't register the callback yet.
+ AssertEqual '''''', string(g:Callback)
+
+ AssertEqual 1, len(g:wait_callback_list)
+ AssertEqual 'completion', g:capability_checked
+ call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])')
+
" We should send the right callback.
AssertEqual
\ 'function(''ale#completion#HandleTSServerResponse'')',
@@ -96,9 +116,9 @@ Execute(The right message should be sent for the initial tsserver request):
AssertEqual
\ {
\ 'line_length': 3,
- \ 'conn_id': 0,
+ \ 'conn_id': 347,
\ 'column': 3,
- \ 'request_id': 0,
+ \ 'request_id': 1,
\ 'line': 1,
\ 'prefix': 'fo',
\ },
@@ -164,6 +184,13 @@ Execute(The right message should be sent for the initial LSP request):
call ale#completion#GetCompletions()
+ " We shouldn't register the callback yet.
+ AssertEqual '''''', string(g:Callback)
+
+ AssertEqual 1, len(g:wait_callback_list)
+ AssertEqual 'completion', g:capability_checked
+ call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])')
+
" We should send the right callback.
AssertEqual
\ 'function(''ale#completion#HandleLSPResponse'')',
@@ -192,10 +219,58 @@ Execute(The right message should be sent for the initial LSP request):
AssertEqual
\ {
\ 'line_length': 3,
- \ 'conn_id': 0,
+ \ 'conn_id': 347,
\ 'column': 3,
- \ 'request_id': 0,
+ \ 'request_id': 1,
\ 'line': 1,
\ 'prefix': 'fo',
+ \ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
\ },
\ get(b:, 'ale_completion_info', {})
+
+Execute(Two completion requests shouldn't be sent in a row):
+ call ale#linter#PreventLoading('python')
+ call ale#linter#Define('python', {
+ \ 'name': 'foo',
+ \ 'lsp': 'stdio',
+ \ 'executable': 'foo',
+ \ 'command': 'foo',
+ \ 'project_root_callback': {-> '/foo/bar'},
+ \})
+ call ale#linter#Define('python', {
+ \ 'name': 'bar',
+ \ 'lsp': 'stdio',
+ \ 'executable': 'foo',
+ \ 'command': 'foo',
+ \ 'project_root_callback': {-> '/foo/bar'},
+ \})
+ let b:ale_linters = ['foo', 'bar']
+
+ " The cursor position needs to match what was saved before.
+ call setpos('.', [bufnr(''), 1, 5, 0])
+
+ call ale#completion#GetCompletions()
+
+ " We shouldn't register the callback yet.
+ AssertEqual '''''', string(g:Callback)
+
+ AssertEqual 2, len(g:wait_callback_list)
+ AssertEqual 'completion', g:capability_checked
+ call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])')
+
+ " We should only send one completion message for two LSP servers.
+ AssertEqual
+ \ [
+ \ [1, 'textDocument/didChange', {
+ \ 'textDocument': {
+ \ 'uri': ale#path#ToURI(expand('%:p')),
+ \ 'version': g:ale_lsp_next_version_id - 1,
+ \ },
+ \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}]
+ \ }],
+ \ [0, 'textDocument/completion', {
+ \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))},
+ \ 'position': {'line': 0, 'character': 3},
+ \ }],
+ \ ],
+ \ g:message_list