11Before:
22 runtime autoload/ale/lsp.vim
3+ runtime autoload/ale/job.vim
34
45 let g:conn_id = ale#lsp#Register('executable', '/foo/bar', '', {})
6+ let g:sent_data = []
57
6- " Stub out this function, so we test updating configs .
8+ " Stub out these functions to capture calls without side effects .
79 function! ale#lsp#Send(conn_id, message) abort
810 endfunction
911
12+ function! ale#job#SendRaw(job_id, data) abort
13+ call add(g:sent_data, a:data)
14+ endfunction
15+
1016After:
1117 Restore
1218
1319 unlet! g:conn_id
20+ unlet! g:conn
21+ unlet! g:sent_data
22+ unlet! g:remainder
23+ unlet! g:messages
1424
1525 runtime autoload/ale/lsp.vim
1626
@@ -19,3 +29,27 @@ Execute(Only send updates when the configuration dictionary changes):
1929 AssertEqual 1, ale#lsp#UpdateConfig(g:conn_id, bufnr(''), {'a': 1})
2030 AssertEqual 0, ale#lsp#UpdateConfig(g:conn_id, bufnr(''), {'a': 1})
2131 AssertEqual 1, ale#lsp#UpdateConfig(g:conn_id, bufnr(''), {})
32+
33+ Execute(ale#lsp#GetConnectionConfig() should return empty dict for unknown connections):
34+ AssertEqual {}, ale#lsp#GetConnectionConfig('unknown:conn')
35+
36+ Execute(ale#lsp#GetConnectionConfig() should return the current connection config):
37+ call ale#lsp#UpdateConfig(g:conn_id, bufnr(''), {'foo': 'bar'})
38+ AssertEqual {'foo': 'bar'}, ale#lsp#GetConnectionConfig(g:conn_id)
39+
40+ Execute(ale#lsp#SendResponse() should do nothing for unknown connections):
41+ " Should not throw
42+ call ale#lsp#SendResponse('unknown:conn', 1, [])
43+ AssertEqual [], g:sent_data
44+
45+ Execute(ale#lsp#SendResponse() should send a JSON-RPC response message):
46+ " Give the connection a job_id so s:SendMessageData routes to ale#job#SendRaw
47+ let g:conn = ale#lsp#GetConnections()[g:conn_id]
48+ let g:conn.job_id = 1
49+
50+ call ale#lsp#SendResponse(g:conn_id, 42, ['result_value'])
51+
52+ AssertEqual 1, len(g:sent_data)
53+ let [g:remainder, g:messages] = ale#lsp#ReadMessageData(g:sent_data[0])
54+ AssertEqual '', g:remainder
55+ AssertEqual [{'jsonrpc': '2.0', 'id': 42, 'result': ['result_value']}], g:messages
0 commit comments