From 3e8161851107692ed268ff7f2f67ac000970fb9e Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Wed, 4 Jul 2018 09:58:42 +0300 Subject: [PATCH 1/5] Rust checker: allow to ignore secondary spans --- autoload/ale/handlers/rust.vim | 7 +++++++ doc/ale-rust.txt | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim index 537bc731e1..431f0cfc1a 100644 --- a/autoload/ale/handlers/rust.vim +++ b/autoload/ale/handlers/rust.vim @@ -7,6 +7,10 @@ if !exists('g:ale_rust_ignore_error_codes') let g:ale_rust_ignore_error_codes = [] endif +if !exists('g:ale_rust_ignore_secondary_spans') + let g:ale_rust_ignore_secondary_spans = 0 +endif + function! s:FindSpan(buffer, span) abort if ale#path#IsBufferPath(a:buffer, a:span.file_name) || a:span.file_name is# '' return a:span @@ -46,6 +50,9 @@ function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort for l:root_span in l:error.spans let l:span = s:FindSpan(a:buffer, l:root_span) + if g:ale_rust_ignore_secondary_spans && !l:span.is_primary + continue + endif if !empty(l:span) call add(l:output, { diff --git a/doc/ale-rust.txt b/doc/ale-rust.txt index d61e5b558f..ba7603d240 100644 --- a/doc/ale-rust.txt +++ b/doc/ale-rust.txt @@ -166,6 +166,22 @@ g:ale_rust_ignore_error_codes *g:ale_rust_ignore_error_codes* > let g:ale_rust_ignore_error_codes = ['E0432', 'E0433'] +g:ale_rust_ignore_secondary_spans *g:ale_rust_ignore_secondary_spans* + *b:ale_rust_ignore_secondary_spans* + Type: Number + Default: 0 + + When set to 1, instructs the Rust error repporting to ignore secondary + spans. The problem with secondary spans is that they sometimes appear in + error messages before the main cause of the error, for example: > + + 1 src/main.rs|98 col 5 error| this function takes 4 parameters but 5 + parameters were supplied: defined here + 2 src/main.rs|430 col 32 error| this function takes 4 parameters but 5 + parameters were supplied: expected 4 parameters +< + This is due to the sorting by line numbers. With this option set to 1, + the 'defined here' span will not be presented. =============================================================================== rustfmt *ale-rust-rustfmt* From c2ec49b170a9321bcaf5b2667c59dc58cfbf6e24 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Mon, 16 Jul 2018 00:26:51 +0300 Subject: [PATCH 2/5] rust: 'is_primary' doesn't always exist in JSON --- autoload/ale/handlers/rust.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim index 431f0cfc1a..7ed6aa4898 100644 --- a/autoload/ale/handlers/rust.vim +++ b/autoload/ale/handlers/rust.vim @@ -50,7 +50,7 @@ function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort for l:root_span in l:error.spans let l:span = s:FindSpan(a:buffer, l:root_span) - if g:ale_rust_ignore_secondary_spans && !l:span.is_primary + if g:ale_rust_ignore_secondary_spans && !get(l:span, 'is_primary', 1) continue endif From 6d7d1f88cf52f18ebc2cffe14a7dea9258cf2da2 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 7 Sep 2018 22:03:48 +0300 Subject: [PATCH 3/5] rust: Use ale#Var --- autoload/ale/handlers/rust.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim index 7ed6aa4898..15e54ad949 100644 --- a/autoload/ale/handlers/rust.vim +++ b/autoload/ale/handlers/rust.vim @@ -50,7 +50,7 @@ function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort for l:root_span in l:error.spans let l:span = s:FindSpan(a:buffer, l:root_span) - if g:ale_rust_ignore_secondary_spans && !get(l:span, 'is_primary', 1) + if ale#Var(a:buffer, 'rust_ignore_secondary_spans') && !get(l:span, 'is_primary', 1) continue endif From ed7a2ba8305d74bc87b4800ae80a76f54f894fbc Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 7 Sep 2018 22:47:29 +0300 Subject: [PATCH 4/5] rust: lint fix for a missing line --- autoload/ale/handlers/rust.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim index 15e54ad949..f1a144d7f6 100644 --- a/autoload/ale/handlers/rust.vim +++ b/autoload/ale/handlers/rust.vim @@ -50,6 +50,7 @@ function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort for l:root_span in l:error.spans let l:span = s:FindSpan(a:buffer, l:root_span) + if ale#Var(a:buffer, 'rust_ignore_secondary_spans') && !get(l:span, 'is_primary', 1) continue endif From 95e77a1b614a2197e3347c107b364e132dc465ff Mon Sep 17 00:00:00 2001 From: RyanSquared Date: Thu, 25 Oct 2018 14:05:37 -0500 Subject: [PATCH 5/5] test/handler/test_rust_handler.vader: Add tests for g:ale_rust_ignore_secondary_spans --- test/handler/test_rust_handler.vader | 145 +++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/test/handler/test_rust_handler.vader b/test/handler/test_rust_handler.vader index e3ab3e8671..4764e71348 100644 --- a/test/handler/test_rust_handler.vader +++ b/test/handler/test_rust_handler.vader @@ -285,3 +285,148 @@ Execute(The Rust handler should find correct files): \ }, \ }), \ ]) + +Execute(The Rust handler should remove secondary spans if set): + call ale#test#SetFilename('src/noerrors/mod.rs') + + let g:ale_rust_ignore_secondary_spans = 0 + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'end_lnum': 1, + \ 'type': 'E', + \ 'end_col': 21, + \ 'col': 1, + \ 'text': 'this function takes 1 parameter but 0 were supplied: defined here', + \ }, + \ { + \ 'lnum': 1, + \ 'end_lnum': 1, + \ 'type': 'E', + \ 'end_col': 46, + \ 'col': 40, + \ 'text': 'this function takes 1 parameter but 0 were supplied: expected 1 parameter', + \ }, + \ ], + \ ale#handlers#rust#HandleRustErrors(bufnr(''), [ + \ '', + \ 'fn test(x: u8) -> u8 { x } fn main() { x(); }', + \ json_encode({ + \ 'message': { + \ 'code': { + \ 'code': 'E0061', + \ 'explanation': 'Dummy explanation; not used' + \ }, + \ 'level': 'error', + \ 'message': 'this function takes 1 parameter but 0 were supplied', + \ 'spans': [ + \ { + \ 'byte_end': 20, + \ 'byte_start': 0, + \ 'column_end': 21, + \ 'column_start': 1, + \ 'file_name': 'src/noerrors/mod.rs', + \ 'is_primary': v:false, + \ 'label': 'defined here', + \ 'line_end': 1, + \ 'line_start': 1, + \ }, + \ { + \ 'byte_end': 45, + \ 'byte_start': 39, + \ 'column_end': 46, + \ 'column_start': 40, + \ 'file_name': '', + \ 'is_primary': v:true, + \ 'label': 'expected 1 parameter', + \ 'line_end': 1, + \ 'line_start': 1, + \ }, + \ ] + \ }, + \ }), + \ json_encode({ + \ 'message': { + \ 'code': v:null, + \ 'level': 'error', + \ 'message': 'aborting due to previous error', + \ 'spans': [] + \ }, + \ }), + \ json_encode({ + \ 'message': { + \ 'code': v:null, + \ 'level': 'error', + \ 'message': 'For more information about this error, try `rustc --explain E0061`.', + \ 'spans': [] + \ }, + \ }), + \ ]) + + let g:ale_rust_ignore_secondary_spans = 1 + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'end_lnum': 1, + \ 'type': 'E', + \ 'end_col': 46, + \ 'col': 40, + \ 'text': 'this function takes 1 parameter but 0 were supplied: expected 1 parameter', + \ }, + \ ], + \ ale#handlers#rust#HandleRustErrors(bufnr(''), [ + \ '', + \ 'fn test(x: u8) -> u8 { x } fn main() { x(); }', + \ json_encode({ + \ 'message': { + \ 'code': { + \ 'code': 'E0061', + \ 'explanation': 'Dummy explanation; not used' + \ }, + \ 'level': 'error', + \ 'message': 'this function takes 1 parameter but 0 were supplied', + \ 'spans': [ + \ { + \ 'byte_end': 20, + \ 'byte_start': 0, + \ 'column_end': 21, + \ 'column_start': 1, + \ 'file_name': 'src/noerrors/mod.rs', + \ 'is_primary': v:false, + \ 'label': 'defined here', + \ 'line_end': 1, + \ 'line_start': 1, + \ }, + \ { + \ 'byte_end': 45, + \ 'byte_start': 39, + \ 'column_end': 46, + \ 'column_start': 40, + \ 'file_name': '', + \ 'is_primary': v:true, + \ 'label': 'expected 1 parameter', + \ 'line_end': 1, + \ 'line_start': 1, + \ }, + \ ] + \ }, + \ }), + \ json_encode({ + \ 'message': { + \ 'code': v:null, + \ 'level': 'error', + \ 'message': 'aborting due to previous error', + \ 'spans': [] + \ }, + \ }), + \ json_encode({ + \ 'message': { + \ 'code': v:null, + \ 'level': 'error', + \ 'message': 'For more information about this error, try `rustc --explain E0061`.', + \ 'spans': [] + \ }, + \ }), + \ ])