Fix #649 - Support tsserver linting for NeoVim

This commit is contained in:
w0rp 2017-06-14 17:08:39 +01:00
parent 25e4d1a353
commit e455d8219e
2 changed files with 62 additions and 11 deletions

View File

@ -24,7 +24,7 @@ function! s:KillHandler(timer) abort
endfunction endfunction
" Note that jobs and IDs are the same thing on NeoVim. " Note that jobs and IDs are the same thing on NeoVim.
function! ale#job#JoinNeovimOutput(job, last_line, data, callback) abort function! ale#job#JoinNeovimOutput(job, last_line, data, mode, callback) abort
let l:lines = a:data[:-2] let l:lines = a:data[:-2]
if len(a:data) > 1 if len(a:data) > 1
@ -34,9 +34,15 @@ function! ale#job#JoinNeovimOutput(job, last_line, data, callback) abort
let l:new_last_line = a:last_line . a:data[0] let l:new_last_line = a:last_line . a:data[0]
endif endif
for l:line in l:lines if a:mode ==# 'raw'
call a:callback(a:job, l:line) if !empty(l:lines)
endfor call a:callback(a:job, join(l:lines, "\n") . "\n")
endif
else
for l:line in l:lines
call a:callback(a:job, l:line)
endfor
endif
return l:new_last_line return l:new_last_line
endfunction endfunction
@ -49,6 +55,7 @@ function! s:NeoVimCallback(job, data, event) abort
\ a:job, \ a:job,
\ l:info.out_cb_line, \ l:info.out_cb_line,
\ a:data, \ a:data,
\ l:info.mode,
\ ale#util#GetFunction(l:info.out_cb), \ ale#util#GetFunction(l:info.out_cb),
\) \)
elseif a:event ==# 'stderr' elseif a:event ==# 'stderr'
@ -56,6 +63,7 @@ function! s:NeoVimCallback(job, data, event) abort
\ a:job, \ a:job,
\ l:info.err_cb_line, \ l:info.err_cb_line,
\ a:data, \ a:data,
\ l:info.mode,
\ ale#util#GetFunction(l:info.err_cb), \ ale#util#GetFunction(l:info.err_cb),
\) \)
else else

View File

@ -1,47 +1,90 @@
Before: Before:
let g:lines = [] let g:lines = []
let g:data = ''
function LineCallback(job_id, line) abort function! LineCallback(job_id, line) abort
call add(g:lines, a:line) call add(g:lines, a:line)
endfunction endfunction
function! RawCallback(job_id, some_data) abort
let g:data .= a:some_data
endfunction
After: After:
unlet! g:last_line unlet! g:last_line
unlet! g:lines unlet! g:lines
unlet! g:data
delfunction LineCallback delfunction LineCallback
delfunction RawCallback
Execute (ALE should pass on full lines for NeoVim): Execute (ALE should pass on full lines for NeoVim):
let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x', 'y', ''], function('LineCallback')) let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x', 'y', ''], 'nl', function('LineCallback'))
AssertEqual ['x', 'y'], g:lines AssertEqual ['x', 'y'], g:lines
AssertEqual '', g:last_line AssertEqual '', g:last_line
Execute (ALE should pass on a single long line): Execute (ALE should pass on a single long line):
let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x'], function('LineCallback')) let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x'], 'nl', function('LineCallback'))
AssertEqual [], g:lines AssertEqual [], g:lines
AssertEqual 'x', g:last_line AssertEqual 'x', g:last_line
Execute (ALE should handle just a single line of output): Execute (ALE should handle just a single line of output):
let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x', ''], function('LineCallback')) let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x', ''], 'nl', function('LineCallback'))
AssertEqual ['x'], g:lines AssertEqual ['x'], g:lines
AssertEqual '', g:last_line AssertEqual '', g:last_line
Execute (ALE should join two incomplete pieces of large lines together): Execute (ALE should join two incomplete pieces of large lines together):
let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y'], function('LineCallback')) let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y'], 'nl', function('LineCallback'))
AssertEqual [], g:lines AssertEqual [], g:lines
AssertEqual 'xy', g:last_line AssertEqual 'xy', g:last_line
Execute (ALE join incomplete lines, and set new ones): Execute (ALE join incomplete lines, and set new ones):
let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y', 'z', 'a'], function('LineCallback')) let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y', 'z', 'a'], 'nl', function('LineCallback'))
AssertEqual ['xy', 'z'], g:lines AssertEqual ['xy', 'z'], g:lines
AssertEqual 'a', g:last_line AssertEqual 'a', g:last_line
Execute (ALE join incomplete lines, and set new ones, with two elements): Execute (ALE join incomplete lines, and set new ones, with two elements):
let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y', 'z'], function('LineCallback')) let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y', 'z'], 'nl', function('LineCallback'))
AssertEqual ['xy'], g:lines AssertEqual ['xy'], g:lines
AssertEqual 'z', g:last_line AssertEqual 'z', g:last_line
Execute (ALE should pass on full lines for NeoVim for raw data):
let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x', 'y', ''], 'raw', function('RawCallback'))
AssertEqual "x\ny\n", g:data
AssertEqual '', g:last_line
Execute (ALE should pass on a single long line):
let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x'], 'raw', function('RawCallback'))
AssertEqual '', g:data
AssertEqual 'x', g:last_line
Execute (ALE should handle just a single line of output):
let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x', ''], 'raw', function('RawCallback'))
AssertEqual "x\n", g:data
AssertEqual '', g:last_line
Execute (ALE should join two incomplete pieces of large lines together):
let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y'], 'raw', function('RawCallback'))
AssertEqual '', g:data
AssertEqual 'xy', g:last_line
Execute (ALE join incomplete lines, and set new ones):
let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y', 'z', 'a'], 'raw', function('RawCallback'))
AssertEqual "xy\nz\n", g:data
AssertEqual 'a', g:last_line
Execute (ALE join incomplete lines, and set new ones, with two elements):
let g:last_line = ale#job#JoinNeovimOutput(1, 'x', ['y', 'z'], 'raw', function('RawCallback'))
AssertEqual "xy\n", g:data
AssertEqual 'z', g:last_line