All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
2 runtime autoload/ale/linter.vim
3 runtime autoload/ale/lsp.vim
4 runtime autoload/ale/lsp_linter.vim
6 let g:address = 'ccls_address'
8 let g:executable = 'ccls'
9 let g:executable_or_address = ''
10 let g:linter_name = 'ccls'
11 let g:magic_number = 42
13 let g:message_list = []
15 let g:method = '$ccls/call'
17 let g:project_root = '/project/root'
19 let g:return_value = -1
21 let g:linter_list = [{
22 \ 'output_stream': 'stdout',
25 \ 'name': g:linter_name,
26 \ 'project_root': {b -> g:project_root},
32 let g:callback_result = g:no_result
34 " Encode dictionary to jsonrpc
35 function! Encode(obj) abort
36 let l:body = json_encode(a:obj)
37 return 'Content-Length: ' . strlen(l:body) . "\r\n\r\n" . l:body
40 " Replace the StartLSP function to mock an LSP linter
41 function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
42 let g:conn_id = ale#lsp#Register(g:executable_or_address, g:project_root, '', {})
43 call ale#lsp#MarkDocumentAsOpen(g:conn_id, a:buffer)
44 call ale#lsp#HandleMessage(g:conn_id, Encode({'method': 'initialize'}))
47 \ 'command': g:executable,
49 \ 'connection_id': g:conn_id,
50 \ 'project_root': g:project_root,
53 call ale#lsp_linter#OnInit(a:linter, l:details, a:Callback)
57 function! Callback(response) abort
58 let g:callback_result = a:response.result.value
61 " Replace the GetAll function to mock an LSP linter
62 function! ale#linter#GetAll(filetype) abort
66 " Replace the Send function to mock an LSP linter
67 function! ale#lsp#Send(conn_id, message) abort
68 call add(g:message_list, a:message)
72 " Code for a test case
73 function! TestCase(is_notification) abort
74 " Test sending a custom request
75 let g:return_value = ale#lsp_linter#SendRequest(
78 \ [a:is_notification, g:method, g:parameters],
79 \ function('Callback'))
81 Assert index(g:message_list, [a:is_notification, g:method, g:parameters]) >= 0
83 " Mock an incoming response to the request
84 let g:response = Encode({
87 \ 'result': {'value': g:magic_number}
89 call ale#lsp#HandleMessage(g:conn_id, g:response)
92 \ a:is_notification ? g:no_result : g:magic_number,
97 if g:conn_id isnot v:null
98 call ale#lsp#RemoveConnectionWithID(g:conn_id)
101 unlet! g:callback_result
104 unlet! g:is_notification
106 unlet! g:magic_number
107 unlet! g:message_list
112 unlet! g:project_root
114 unlet! g:return_value
120 runtime autoload/ale/linter.vim
121 runtime autoload/ale/lsp.vim
122 runtime autoload/ale/lsp_linter.vim
124 Given cpp(Empty cpp file):
125 Execute(Test custom request to server identified by executable):
126 let g:executable_or_address = g:executable
127 let g:linter_list[0].executable = {b -> g:executable}
128 let g:linter_list[0].lsp = 'stdio'
129 let g:is_notification = 0
131 call TestCase(g:is_notification)
133 Given cpp(Empty cpp file):
134 Execute(Test custom notification to server identified by executable):
135 let g:executable_or_address = g:executable
136 let g:linter_list[0].executable = {b -> g:executable}
137 let g:linter_list[0].lsp = 'stdio'
138 let g:is_notification = 1
140 call TestCase(g:is_notification)
142 Given cpp(Empty cpp file):
143 Execute(Test custom request to server identified by address):
144 let g:executable_or_address = g:address
145 let g:linter_list[0].address = {b -> g:address}
146 let g:linter_list[0].lsp = 'socket'
147 let g:is_notification = 0
149 call TestCase(g:is_notification)
151 Given cpp(Empty cpp file):
152 Execute(Test custom notification to server identified by address):
153 let g:executable_or_address = g:address
154 let g:linter_list[0].address = {b -> g:address}
155 let g:linter_list[0].lsp = 'socket'
156 let g:is_notification = 1
158 call TestCase(g:is_notification)