Join the lines Neovim passes to ale (#263)
* Join the lines Neovim passes to ale Fixes #256 * Refactor line joining into own function * Add test for line joining * Fix the test. Sorry.
This commit is contained in:
parent
2478d7d925
commit
831f783493
@ -72,22 +72,39 @@ function! s:StopPreviousJobs(buffer, linter) abort
|
|||||||
let g:ale_buffer_info[a:buffer].job_list = l:new_job_list
|
let g:ale_buffer_info[a:buffer].job_list = l:new_job_list
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GatherOutput(job, data) abort
|
function! s:GatherOutputVim(channel, data) abort
|
||||||
|
let l:job_id = s:GetJobID(ch_getjob(a:channel))
|
||||||
|
|
||||||
|
if !has_key(s:job_info_map, l:job_id)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
call add(s:job_info_map[l:job_id].output, a:data)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:GatherOutputNeoVim(job, data, event) abort
|
||||||
let l:job_id = s:GetJobID(a:job)
|
let l:job_id = s:GetJobID(a:job)
|
||||||
|
|
||||||
if !has_key(s:job_info_map, l:job_id)
|
if !has_key(s:job_info_map, l:job_id)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call extend(s:job_info_map[l:job_id].output, a:data)
|
" Join the lines passed to ale, because Neovim splits them up.
|
||||||
|
" a:data is a list of strings, where every item is a new line, except the
|
||||||
|
" first one, which is the continuation of the last item passed last time.
|
||||||
|
call ale#engine#JoinNeovimOutput(s:job_info_map[l:job_id].output, a:data)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GatherOutputVim(channel, data) abort
|
function! ale#engine#JoinNeovimOutput(output, data) abort
|
||||||
call s:GatherOutput(ch_getjob(a:channel), [a:data])
|
if empty(a:output)
|
||||||
endfunction
|
call extend(a:output, a:data)
|
||||||
|
else
|
||||||
|
" Extend the previous line, which can be continued.
|
||||||
|
let a:output[-1] .= get(a:data, 0, '')
|
||||||
|
|
||||||
function! s:GatherOutputNeoVim(job, data, event) abort
|
" Add the new lines.
|
||||||
call s:GatherOutput(a:job, a:data)
|
call extend(a:output, a:data[1:])
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:HandleExit(job) abort
|
function! s:HandleExit(job) abort
|
||||||
|
23
test/test_line_join.vader
Normal file
23
test/test_line_join.vader
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Before:
|
||||||
|
let g:test_output = [
|
||||||
|
\ ['one', 'two', 'thr'],
|
||||||
|
\ ['ee', ''],
|
||||||
|
\ ['fou'],
|
||||||
|
\ [''],
|
||||||
|
\ ['r', 'five'],
|
||||||
|
\ [],
|
||||||
|
\ ['', 'six']
|
||||||
|
\]
|
||||||
|
|
||||||
|
let g:expected_result = ['one', 'two', 'three', 'four', 'five', 'six']
|
||||||
|
|
||||||
|
After:
|
||||||
|
unlet g:test_output
|
||||||
|
unlet g:expected_result
|
||||||
|
|
||||||
|
Execute (Join the lines):
|
||||||
|
let joined_result = []
|
||||||
|
for item in g:test_output
|
||||||
|
call ale#engine#JoinNeovimOutput(joined_result, item)
|
||||||
|
endfor
|
||||||
|
AssertEqual g:expected_result, joined_result
|
Loading…
Reference in New Issue
Block a user