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 Save g:ale_run_synchronously
4 let g:ale_run_synchronously = 1
5 unlet! g:ale_run_synchronously_callbacks
6 unlet! g:ale_run_synchronously_emulate_commands
8 runtime autoload/ale/lsp.vim
9 runtime autoload/ale/lsp_linter.vim
10 runtime autoload/ale/engine.vim
11 runtime autoload/ale/job.vim
12 runtime autoload/ale/socket.vim
15 let g:emulate_job_failure = 0
20 let g:emulate_socket_failure = 0
21 let g:next_channel_id = 0
23 let g:message_buffer = ''
26 function! ale#engine#IsExecutable(buffer, executable) abort
27 return !empty(a:executable)
30 function! ale#job#HasOpenChannel(job_id) abort
31 return has_key(g:job_map, a:job_id)
34 function! ale#job#Stop(job_id) abort
35 if has_key(g:job_map, a:job_id)
36 call remove(g:job_map, a:job_id)
40 function! ale#job#Start(command, options) abort
41 if g:emulate_job_failure
45 let l:job_id = g:next_job_id
46 let g:next_job_id += 1
47 let g:job_map[l:job_id] = [a:command, a:options]
52 function! ale#job#SendRaw(job_id, data) abort
53 let g:message_buffer .= a:data
56 function! ale#socket#IsOpen(channel_id) abort
57 return has_key(g:socket_map, a:channel_id)
60 function! ale#socket#Close(channel_id) abort
61 if has_key(g:socket_map, a:channel_id)
62 call remove(g:socket_map, a:channel_id)
66 function! ale#socket#Open(address, options) abort
67 if g:emulate_socket_failure
71 let l:channel_id = g:next_channel_id
72 let g:next_channel_id += 1
73 let g:socket_map[l:channel_id] = [a:address, a:options]
78 function! ale#socket#Send(channel_id, data) abort
79 let g:message_buffer .= a:data
82 function! PopMessages() abort
83 let l:message_list = []
85 for l:line in split(g:message_buffer, '\(\r\|\n\|Content-Length\)\+')
87 let l:data = json_decode(l:line)
89 call add(l:message_list, l:data)
93 let g:message_buffer = ''
98 function! SendMessage(message) abort
99 let l:conn_id = keys(ale#lsp#GetConnections())[0]
100 let l:body = json_encode(a:message)
101 let l:data = 'Content-Length: ' . strlen(l:body) . "\r\n\r\n" . l:body
103 call ale#lsp#HandleMessage(l:conn_id, l:data)
106 function! Start(buffer) abort
107 let l:linter = values(ale#linter#GetLintersLoaded())[0][0]
109 return ale#lsp_linter#StartLSP(
112 \ {linter, details -> add(g:calls, [linter.name, details])},
116 function! AssertInitSuccess(linter_name, conn_prefix, language, root, command, buffer) abort
117 let l:messages = PopMessages()
119 if a:linter_name is# 'tsserver'
125 \ 'file': expand('#' . a:buffer . ':p'),
136 \ 'method': 'initialize',
140 \ 'initializationOptions': {},
141 \ 'rootUri': ale#path#ToFileURI(a:root),
142 \ 'rootPath': a:root,
143 \ 'processId': getpid(),
146 \ 'applyEdit': v:false,
147 \ 'didChangeConfiguration': {
148 \ 'dynamicRegistration': v:false,
151 \ 'dynamicRegistration': v:false,
153 \ 'workspaceFolders': v:false,
154 \ 'configuration': v:false,
157 \ 'synchronization': {
158 \ 'dynamicRegistration': v:false,
159 \ 'willSave': v:false,
160 \ 'willSaveWaitUntil': v:false,
164 \ 'dynamicRegistration': v:false,
165 \ 'completionItem': {
166 \ 'snippetSupport': v:false,
167 \ 'commitCharactersSupport': v:false,
168 \ 'documentationFormat': ['plaintext', 'markdown'],
169 \ 'deprecatedSupport': v:false,
170 \ 'preselectSupport': v:false,
172 \ 'contextSupport': v:false,
175 \ 'dynamicRegistration': v:false,
176 \ 'contentFormat': ['plaintext', 'markdown'],
179 \ 'dynamicRegistration': v:false,
181 \ 'documentSymbol': {
182 \ 'dynamicRegistration': v:false,
183 \ 'hierarchicalDocumentSymbolSupport': v:false,
186 \ 'dynamicRegistration': v:false,
187 \ 'linkSupport': v:false,
189 \ 'typeDefinition': {
190 \ 'dynamicRegistration': v:false,
192 \ 'implementation': {
193 \ 'dynamicRegistration': v:false,
194 \ 'linkSupport': v:false,
197 \ 'dynamicRegistration': v:true,
198 \ 'relatedDocumentSupport': v:true,
200 \ 'publishDiagnostics': {
201 \ 'relatedInformation': v:true,
204 \ 'dynamicRegistration': v:false,
205 \ 'codeActionLiteralSupport': {
206 \ 'codeActionKind': {
212 \ 'dynamicRegistration': v:false,
226 \ 'renameProvider': v:true,
227 \ 'executeCommandProvider': {
230 \ 'hoverProvider': v:true,
231 \ 'documentSymbolProvider': v:true,
232 \ 'documentRangeFormattingProvider': v:true,
233 \ 'codeLensProvider': {
234 \ 'resolveProvider': v:false
236 \ 'referencesProvider': v:true,
237 \ 'textDocumentSync': 2,
238 \ 'documentFormattingProvider': v:true,
239 \ 'codeActionProvider': v:true,
240 \ 'signatureHelpProvider': {
241 \ 'triggerCharacters': ['(', ','],
243 \ 'completionProvider': {
244 \ 'triggerCharacters': ['.'],
245 \ 'resolveProvider': v:false
247 \ 'definitionProvider': v:true,
248 \ 'experimental': {},
249 \ 'documentHighlightProvider': v:true,
250 \ 'workspaceSymbolProvider': v:true,
255 let l:messages = PopMessages()
260 \ 'method': 'initialized',
265 \ 'method': 'textDocument/didOpen',
269 \ 'uri': ale#path#ToFileURI(expand('#' . a:buffer . ':p')),
270 \ 'version': ale#lsp#message#GetNextVersionID() - 1,
271 \ 'languageId': a:language,
285 \ 'connection_id': a:conn_prefix . ':' . a:root,
286 \ 'project_root': a:root,
287 \ 'buffer': a:buffer,
288 \ 'command': !empty(a:command) ? ale#job#PrepareCommand(a:buffer, a:command) : '',
295 function! AssertInitFailure() abort
296 let l:messages = PopMessages()
298 AssertEqual [], l:messages
299 AssertEqual [], g:calls
302 call ale#linter#Reset()
307 call ale#linter#Reset()
308 call ale#lsp#ResetConnections()
310 unlet! g:ale_run_synchronously_callbacks
312 unlet! g:emulate_job_failure
317 unlet! g:emulate_socket_failure
318 unlet! g:next_channel_id
320 unlet! g:message_buffer
329 delfunction PopMessages
331 delfunction AssertInitSuccess
332 delfunction AssertInitFailure
334 runtime autoload/ale/engine.vim
335 runtime autoload/ale/job.vim
336 runtime autoload/ale/socket.vim
338 Execute(tsserver should be started correctly):
339 runtime ale_linters/typescript/tsserver.vim
341 Assert Start(bufnr(''))
342 call AssertInitSuccess('tsserver', 'tsserver', '', '', ale#Escape('tsserver'), bufnr(''))
344 Execute(tsserver failures should be handled appropriately):
345 runtime ale_linters/typescript/tsserver.vim
347 let g:emulate_job_failure = 1
349 Assert !Start(bufnr(''))
350 call AssertInitFailure()
352 Execute(LSP jobs should start correctly):
353 call ale#linter#Define('foobar', {
356 \ 'executable': 'foo',
358 \ 'project_root': '/foo/bar',
359 \ 'initialization_options': {},
362 Assert Start(bufnr(''))
363 call AssertInitSuccess('foo', 'foo', 'foobar', '/foo/bar', 'foo', bufnr(''))
365 Execute(LSP job failures should be handled):
366 call ale#linter#Define('foobar', {
369 \ 'executable': 'foo',
371 \ 'project_root': '/foo/bar',
372 \ 'initialization_options': {},
375 let g:emulate_job_failure = 1
377 Assert !Start(bufnr(''))
378 call AssertInitFailure()
380 Execute(LSP TCP connections should start correctly):
381 call ale#linter#Define('foobar', {
385 \ 'project_root': '/foo/bar',
386 \ 'initialization_options': {},
389 Assert Start(bufnr(''))
390 call AssertInitSuccess('foo', 'foo', 'foobar', '/foo/bar', '', bufnr(''))
392 Execute(LSP TCP connection failures should be handled):
393 call ale#linter#Define('foobar', {
397 \ 'project_root': '/foo/bar',
398 \ 'initialization_options': {},
401 let g:emulate_socket_failure = 1
403 Assert !Start(bufnr(''))
404 call AssertInitFailure()
406 Execute(Deferred executables should be handled correctly):
407 call ale#linter#Define('foobar', {
410 \ 'executable': {b -> ale#command#Run(b, 'echo', {-> 'foo'})},
411 \ 'command': '%e -c',
412 \ 'project_root': '/foo/bar',
413 \ 'initialization_options': {},
416 Assert Start(bufnr(''))
417 call ale#test#FlushJobs()
418 call AssertInitSuccess('foo', 'foo', 'foobar', '/foo/bar', ale#Escape('foo') . ' -c', bufnr(''))
420 Execute(Deferred commands should be handled correctly):
421 call ale#linter#Define('foobar', {
424 \ 'executable': 'foo',
425 \ 'command': {b -> ale#command#Run(b, 'echo', {-> '%e -c'})},
426 \ 'project_root': '/foo/bar',
427 \ 'initialization_options': {},
430 Assert Start(bufnr(''))
431 call ale#test#FlushJobs()
432 call AssertInitSuccess('foo', 'foo', 'foobar', '/foo/bar', ale#Escape('foo') . ' -c', bufnr(''))
434 Execute(Deferred addresses should be handled correctly):
435 call ale#linter#Define('foobar', {
438 \ 'address': {b -> ale#command#Run(b, 'echo', {-> 'localhost:1234'})},
439 \ 'project_root': '/foo/bar',
440 \ 'initialization_options': {},
443 Assert Start(bufnr(''))
444 call ale#test#FlushJobs()
445 call AssertInitSuccess('foo', 'localhost:1234', 'foobar', '/foo/bar', '', bufnr(''))
447 Execute(Servers that have crashed should be restarted):
448 call ale#lsp#Register('foo', '/foo/bar', '', {})
449 call extend(ale#lsp#GetConnections()['foo:/foo/bar'], {'initialized': 1})
451 " Starting the program again should reset initialized to `0`.
452 call ale#lsp#StartProgram('foo:/foo/bar', 'foobar', 'foobar --start')
454 AssertEqual 0, ale#lsp#GetConnections()['foo:/foo/bar']['initialized']
455 AssertEqual ['initialize'], map(PopMessages(), 'v:val[''method'']')
457 Execute(Current LSP buffer should receive ALELSPStarted):
458 call ale#linter#Define('foobar', {
462 \ 'project_root': '/foo/bar',
463 \ 'initialization_options': {},
468 autocmd User ALELSPStarted let g:lsp_started = 1
471 Assert Start(bufnr(''))
472 call AssertInitSuccess('foo', 'foo', 'foobar', '/foo/bar', '', bufnr(''))
473 AssertEqual g:lsp_started, 1
475 Execute(Target LSP buffer should receive ALELSPStarted):
476 call ale#linter#Define('foobar', {
480 \ 'project_root': '/foo/bar',
481 \ 'initialization_options': {},
486 autocmd User ALELSPStarted let g:lsp_started = 1
489 let buffer = bufnr('')
493 call AssertInitSuccess('foo', 'foo', 'foobar', '/foo/bar', '', buffer)
494 execute 'buffer' . buffer
496 AssertEqual g:lsp_started, 1