summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-20 12:49:55 +0100
committerw0rp <devw0rp@gmail.com>2017-05-20 12:50:19 +0100
commit0f0d1709c5b91a52b6d383762b5f47f20263d141 (patch)
treea42593cc7860d6a2a926eab577b08597bc4f059e
parent455793dfd9c657a76d7a143e0e0eb395d779379b (diff)
downloadale-0f0d1709c5b91a52b6d383762b5f47f20263d141.zip
#567 Try and fix NeoVim split line handling
-rw-r--r--autoload/ale/job.vim41
-rw-r--r--test/test_line_join.vader64
2 files changed, 63 insertions, 42 deletions
diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim
index 11a36045..d35fc020 100644
--- a/autoload/ale/job.vim
+++ b/autoload/ale/job.vim
@@ -18,43 +18,40 @@ function! s:KillHandler(timer) abort
call job_stop(l:job, 'kill')
endfunction
-function! ale#job#JoinNeovimOutput(output, data) abort
- if empty(a:output)
- call extend(a:output, a:data)
- else
- " Extend the previous line, which can be continued.
- let a:output[-1] .= get(a:data, 0, '')
+" Note that jobs and IDs are the same thing on NeoVim.
+function! ale#job#JoinNeovimOutput(job, last_line, data, callback) abort
+ let l:lines = a:data[:-2]
- " Add the new lines.
- call extend(a:output, a:data[1:])
+ if len(a:data) > 1
+ let l:lines[0] = a:last_line . l:lines[0]
+ let l:new_last_line = a:data[-1]
+ else
+ let l:new_last_line = a:last_line . a:data[0]
endif
-endfunction
-
-" Note that jobs and IDs are the same thing on NeoVim.
-function! s:HandleNeoVimLines(job, callback, output, data) abort
- call ale#job#JoinNeovimOutput(a:output, a:data)
- for l:line in a:output
+ for l:line in l:lines
call a:callback(a:job, l:line)
endfor
+
+ return l:new_last_line
endfunction
function! s:NeoVimCallback(job, data, event) abort
let l:job_info = s:job_map[a:job]
if a:event ==# 'stdout'
- call s:HandleNeoVimLines(
+ let l:job_info.out_cb_line = ale#job#JoinNeovimOutput(
\ a:job,
- \ ale#util#GetFunction(l:job_info.out_cb),
- \ l:job_info.out_cb_output,
+ \ l:job_info.out_cb_line,
\ a:data,
+ \ ale#util#GetFunction(l:job_info.out_cb),
\)
elseif a:event ==# 'stderr'
- call s:HandleNeoVimLines(
+ let l:job_info.err_cb_line = ale#job#JoinNeovimOutput(
\ a:job,
- \ ale#util#GetFunction(l:job_info.err_cb),
- \ l:job_info.err_cb_output,
+ \ l:job_info.err_cb_line,
\ a:data,
+ \ ale#util#GetFunction(l:job_info.err_cb),
\)
else
try
@@ -165,12 +162,12 @@ function! ale#job#Start(command, options) abort
if has('nvim')
if has_key(a:options, 'out_cb')
let l:job_options.on_stdout = function('s:NeoVimCallback')
- let l:job_info.out_cb_output = []
+ let l:job_info.out_cb_line = ''
endif
if has_key(a:options, 'err_cb')
let l:job_options.on_stderr = function('s:NeoVimCallback')
- let l:job_info.err_cb_output = []
+ let l:job_info.err_cb_line = ''
endif
if has_key(a:options, 'exit_cb')
diff --git a/test/test_line_join.vader b/test/test_line_join.vader
index 63d8d338..389632b9 100644
--- a/test/test_line_join.vader
+++ b/test/test_line_join.vader
@@ -1,23 +1,47 @@
Before:
- let g:test_output = [
- \ ['one', 'two', 'thr'],
- \ ['ee', ''],
- \ ['fou'],
- \ [''],
- \ ['r', 'five'],
- \ [],
- \ ['', 'six']
- \]
-
- let g:expected_result = ['one', 'two', 'three', 'four', 'five', 'six']
+ let g:lines = []
+
+ function LineCallback(job_id, line) abort
+ call add(g:lines, a:line)
+ endfunction
After:
- unlet g:test_output
- unlet g:expected_result
-
-Execute (Join the lines):
- let joined_result = []
- for item in g:test_output
- call ale#job#JoinNeovimOutput(joined_result, item)
- endfor
- AssertEqual g:expected_result, joined_result
+ unlet! g:last_line
+ unlet! g:lines
+ delfunction LineCallback
+
+Execute (ALE should pass on full lines for NeoVim):
+ let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x', 'y', ''], function('LineCallback'))
+
+ AssertEqual ['x', 'y'], g:lines
+ AssertEqual '', g:last_line
+
+Execute (ALE should pass on a single long line):
+ let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x'], function('LineCallback'))
+
+ AssertEqual [], g:lines
+ AssertEqual 'x', g:last_line
+
+Execute (ALE should handle just a single line of output):
+ let g:last_line = ale#job#JoinNeovimOutput(1, '', ['x', ''], function('LineCallback'))
+
+ AssertEqual ['x'], g:lines
+ 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'], function('LineCallback'))
+
+ AssertEqual [], g:lines
+ 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'], function('LineCallback'))
+
+ AssertEqual ['xy', 'z'], g:lines
+ 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'], function('LineCallback'))
+
+ AssertEqual ['xy'], g:lines
+ AssertEqual 'z', g:last_line