diff options
author | w0rp <devw0rp@gmail.com> | 2017-05-17 09:43:22 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-05-17 09:43:28 +0100 |
commit | 5790df12722a31e913750fad955f2a4f0ed76269 (patch) | |
tree | 6034f3bc4347d3d105ca18ce9dcec7d6393a4850 | |
parent | 372a4dfd7e7166292d0f35ddc10f0365fe0e3053 (diff) | |
download | ale-5790df12722a31e913750fad955f2a4f0ed76269.zip |
#562 Join split JSON lines together for new Rust output
-rw-r--r-- | autoload/ale/handlers/rust.vim | 32 | ||||
-rw-r--r-- | test/handler/test_rust_handler.vader | 18 |
2 files changed, 44 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({}) diff --git a/test/handler/test_rust_handler.vader b/test/handler/test_rust_handler.vader index 3e0ed43d..052d722b 100644 --- a/test/handler/test_rust_handler.vader +++ b/test/handler/test_rust_handler.vader @@ -46,3 +46,21 @@ Execute(The Rust handler should handle cargo output): \ '{"message":{"children":[],"code":null,"level":"error","message":"no method named `wat` found for type `std::string::String` in the current scope","rendered":null,"spans":[{"byte_end":11497,"byte_start":11494,"column_end":10,"column_start":7,"expansion":null,"file_name":"src/playpen.rs","is_primary":true,"label":null,"line_end":13,"line_start":13,"suggested_replacement":null,"text":[{"highlight_end":10,"highlight_start":7,"text":" s.wat()"}]}]},"package_id":"update 0.0.1 (path+file:///home/w0rp/Downloads/rust-by-example)","reason":"compiler-message","target":{"kind":["bin"],"name":"update","src_path":"/home/w0rp/Downloads/rust-by-example/src/main.rs"}}', \ '{"message":{"children":[],"code":null,"level":"error","message":"aborting due to previous error","rendered":null,"spans":[]},"package_id":"update 0.0.1 (path+file:///home/w0rp/Downloads/rust-by-example)","reason":"compiler-message","target":{"kind":["bin"],"name":"update","src_path":"/home/w0rp/Downloads/rust-by-example/src/main.rs"}}', \ ]) + +Execute(The Rust handler should handle JSON split over many lines): + AssertEqual + \ [ + \ { + \ 'lnum': 15, + \ 'type': 'E', + \ 'col': 11505, + \ 'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`', + \ }, + \ ], + \ ale#handlers#rust#HandleRustErrorsForFile(347, 'src/playpen.rs', [ + \ '', + \ 'ignore this', + \ '{"message":{"children":[],"code":null,"level":"error","message":"expected one of `.`, `;`, `?`, `}`, or an operator, found `for`","rendered":null,"spans":[{"byte_end":11508,"byte_start":11505,"column_end":8,"column_start":5,"expansion":null', + \ ',"file_name":"src/playpen.rs","is_primary":true,"label":null,"line_end":15,"line_start":15,"suggested_replacement":null,', + \ '"text":[{"highlight_end":8,"highlight_start":5,"text":" for chr in source.trim().chars() {"}]}]},"package_id":"update 0.0.1 (path+file:///home/w0rp/Downloads/rust-by-example)","reason":"compiler-message","target":{"kind":["bin"],"name":"update","src_path":"/home/w0rp/Downloads/rust-by-example/src/main.rs"}}', + \ ]) |