Skip to content

Commit

Permalink
#1006 Fix raw message handling for LSP support in NeoVim
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Nov 6, 2017
1 parent 8e7ede3 commit 55757e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
17 changes: 8 additions & 9 deletions autoload/ale/job.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ endfunction

" Note that jobs and IDs are the same thing on NeoVim.
function! ale#job#JoinNeovimOutput(job, last_line, data, mode, callback) abort
if a:mode is# 'raw'
call a:callback(a:job, join(a:data, "\n"))
return ''
endif

let l:lines = a:data[:-2]

if len(a:data) > 1
Expand All @@ -34,15 +39,9 @@ function! ale#job#JoinNeovimOutput(job, last_line, data, mode, callback) abort
let l:new_last_line = a:last_line . a:data[0]
endif

if a:mode is# 'raw'
if !empty(l:lines)
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
for l:line in l:lines
call a:callback(a:job, l:line)
endfor

return l:new_last_line
endfunction
Expand Down
24 changes: 6 additions & 18 deletions test/test_line_join.vader
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,17 @@ Execute (ALE should pass on full lines for NeoVim for raw data):
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
AssertEqual 'x', g:data
AssertEqual '', 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'))
Execute (ALE should pass on two lines and one incomplete one):
let g:last_line = ale#job#JoinNeovimOutput(1, '', ['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
AssertEqual "y\nz\na", g:data
AssertEqual '', g:last_line

0 comments on commit 55757e3

Please sign in to comment.