summaryrefslogtreecommitdiff
path: root/test/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'test/lsp')
-rw-r--r--test/lsp/test_lsp_custom_request.vader58
1 files changed, 37 insertions, 21 deletions
diff --git a/test/lsp/test_lsp_custom_request.vader b/test/lsp/test_lsp_custom_request.vader
index e5fecafc..f50a4cf2 100644
--- a/test/lsp/test_lsp_custom_request.vader
+++ b/test/lsp/test_lsp_custom_request.vader
@@ -7,13 +7,15 @@ Before:
let g:callback_result = 0
let g:conn_id = -1
let g:executable = 'ccls'
+ let g:executable_or_address = ''
let g:linter_name = 'ccls'
let g:magic_number = 42
- let g:message = -1
+ let g:message_list = []
let g:message_id = 1
let g:method = '$ccls/call'
let g:parameters = {}
- let g:project = '/project/root'
+ let g:project_root = '/project/root'
+ let g:response = ''
let g:return_value = -1
let g:linter_list = [{
@@ -21,7 +23,7 @@ Before:
\ 'lint_file': 0,
\ 'language': 'cpp',
\ 'name': g:linter_name,
- \ 'project_root': {b -> g:project},
+ \ 'project_root': {b -> g:project_root},
\ 'aliases': [],
\ 'language_callback': {b -> 'cpp'},
\ 'read_buffer': 1,
@@ -34,10 +36,20 @@ Before:
return 'Content-Length: ' . strlen(l:body) . "\r\n\r\n" . l:body
endfunction
- " Register the server with given executable or address
- function! InitServer(executable_or_address) abort
- let g:conn_id = ale#lsp#Register(a:executable_or_address, g:project, {})
+ " Replace the StartLSP function to mock an LSP linter
+ function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
+ let g:conn_id = ale#lsp#Register(g:executable_or_address, g:project_root, {})
+ call ale#lsp#MarkDocumentAsOpen(g:conn_id, a:buffer)
call ale#lsp#HandleMessage(g:conn_id, Encode({'method': 'initialize'}))
+
+ let l:details = {
+ \ 'command': g:executable,
+ \ 'buffer': a:buffer,
+ \ 'connection_id': g:conn_id,
+ \ 'project_root': g:project_root,
+ \}
+
+ call ale#lsp_linter#OnInit(a:linter, l:details, a:Callback)
endfunction
" Dummy callback
@@ -52,25 +64,29 @@ Before:
" Replace the Send function to mock an LSP linter
function! ale#lsp#Send(conn_id, message) abort
- let g:message = a:message
+ call add(g:message_list, a:message)
return g:message_id
endfunction
" Code for a test case
function! TestCase() abort
" Test sending a custom request
- let g:return_value = ale#lsp_linter#SendRequest(bufnr('%'), g:linter_name, g:method, g:parameters, function('Callback'))
+ let g:return_value = ale#lsp_linter#SendRequest(
+ \ bufnr('%'),
+ \ g:linter_name,
+ \ g:method,
+ \ g:parameters,
+ \ function('Callback'))
- AssertEqual
- \ 0,
- \ g:return_value
-
- AssertEqual
- \ [0, g:method, g:parameters],
- \ g:message
+ Assert index(g:message_list, [0, g:method, g:parameters]) >= 0
" Mock an incoming response to the request
- call ale#lsp#HandleMessage(g:conn_id, Encode({'id': g:message_id, 'jsonrpc': '2.0', 'result': {'value': g:magic_number}}))
+ let g:response = Encode({
+ \ 'id': g:message_id,
+ \ 'jsonrpc': '2.0',
+ \ 'result': {'value': g:magic_number}
+ \ })
+ call ale#lsp#HandleMessage(g:conn_id, g:response)
AssertEqual
\ g:magic_number,
@@ -87,15 +103,15 @@ After:
unlet! g:executable
unlet! g:linter_name
unlet! g:magic_number
- unlet! g:message
+ unlet! g:message_list
unlet! g:message_id
unlet! g:method
unlet! g:parameters
- unlet! g:project
+ unlet! g:project_root
+ unlet! g:response
unlet! g:return_value
delfunction Encode
- delfunction InitServer
delfunction Callback
delfunction TestCase
@@ -105,7 +121,7 @@ After:
Given cpp(Empty cpp file):
Execute(Test custom request to server identified by executable):
- call InitServer(g:executable)
+ let g:executable_or_address = g:executable
let g:linter_list[0].executable = {b -> g:executable}
let g:linter_list[0].lsp = 'stdio'
@@ -113,7 +129,7 @@ Execute(Test custom request to server identified by executable):
Given cpp(Empty cpp file):
Execute(Test custom request to server identified by address):
- call InitServer(g:address)
+ let g:executable_or_address = g:address
let g:linter_list[0].address = {b -> g:address}
let g:linter_list[0].lsp = 'socket'