mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-09 22:14:44 +08:00
Rust checker: allow secondary spans to be ignored (#1696)
* Rust checker: allow secondary spans to be ignored * test/handler/test_rust_handler.vader: Add tests for g:ale_rust_ignore_secondary_spans
This commit is contained in:
@@ -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': '<anon>',
|
||||
\ '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': '<anon>',
|
||||
\ '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': []
|
||||
\ },
|
||||
\ }),
|
||||
\ ])
|
||||
|
||||
Reference in New Issue
Block a user