summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-17 09:43:22 +0100
committerw0rp <devw0rp@gmail.com>2017-05-17 09:43:28 +0100
commit5790df12722a31e913750fad955f2a4f0ed76269 (patch)
tree6034f3bc4347d3d105ca18ce9dcec7d6393a4850 /autoload
parent372a4dfd7e7166292d0f35ddc10f0365fe0e3053 (diff)
downloadale-5790df12722a31e913750fad955f2a4f0ed76269.zip
#562 Join split JSON lines together for new Rust output
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/handlers/rust.vim32
1 files changed, 26 insertions, 6 deletions
diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim
index 4fa7f059..7724ed72 100644
--- a/autoload/ale/handlers/rust.vim
+++ b/autoload/ale/handlers/rust.vim
@@ -20,17 +20,37 @@ function! s:FindErrorInExpansion(span, file_name) abort
return []
endfunction
+" The JSON output for Rust can be split over many lines.
+" Those lines should be joined together again.
+function! s:JoinJSONLines(lines) abort
+ let l:corrected_lines = []
+ let l:object_continues = 0
+
+ for l:line in a:lines
+ if l:object_continues
+ let l:corrected_lines[-1] .= l:line
+
+ if l:line =~# '}$'
+ let l:object_continues = 0
+ endif
+ elseif l:line =~# '^{'
+ call add(l:corrected_lines, l:line)
+
+ if l:line !~# '}$'
+ let l:object_continues = 1
+ endif
+ endif
+ endfor
+
+ return l:corrected_lines
+endfunction
+
" A handler function which accepts a file name, to make unit testing easier.
function! ale#handlers#rust#HandleRustErrorsForFile(buffer, full_filename, lines) abort
let l:filename = fnamemodify(a:full_filename, ':t')
let l:output = []
- for l:errorline in a:lines
- " ignore everything that is not Json
- if l:errorline !~# '^{'
- continue
- endif
-
+ for l:errorline in s:JoinJSONLines(a:lines)
let l:error = json_decode(l:errorline)
if has_key(l:error, 'message') && type(l:error.message) == type({})