summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/handlers/rust.vim8
-rw-r--r--autoload/ale/linter.vim3
-rw-r--r--doc/ale-rust.txt16
-rw-r--r--doc/ale.txt6
-rw-r--r--test/handler/test_rust_handler.vader145
-rw-r--r--test/test_linter_retrieval.vader11
6 files changed, 186 insertions, 3 deletions
diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim
index f12c53be..c6a4b670 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# '<anon>'
return a:span
@@ -47,6 +51,10 @@ 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
+
if !empty(l:span)
call add(l:output, {
\ 'lnum': l:span.line_start,
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index 7c1dc53e..dbf9f221 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -346,8 +346,9 @@ endfunction
function! s:GetAliasedFiletype(original_filetype) abort
let l:buffer_aliases = get(b:, 'ale_linter_aliases', {})
- " b:ale_linter_aliases can be set to a List.
+ " b:ale_linter_aliases can be set to a List or String.
if type(l:buffer_aliases) is v:t_list
+ \|| type(l:buffer_aliases) is v:t_string
return l:buffer_aliases
endif
diff --git a/doc/ale-rust.txt b/doc/ale-rust.txt
index ce5634ae..7510dfbd 100644
--- a/doc/ale-rust.txt
+++ b/doc/ale-rust.txt
@@ -198,6 +198,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*
diff --git a/doc/ale.txt b/doc/ale.txt
index 7e37d2dc..66ce8ab1 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -1310,10 +1310,12 @@ g:ale_linter_aliases *g:ale_linter_aliases*
ALE will first look for aliases for filetypes in the `b:ale_linter_aliases`
variable, then `g:ale_linter_aliases`, and then a default Dictionary.
- `b:ale_linter_aliases` can be set to a |List|, to tell ALE to load the
- linters for specific filetypes for a given buffer. >
+ `b:ale_linter_aliases` can be set to a |List| or a |String|, to tell ALE to
+ load the linters for specific filetypes for a given buffer. >
let b:ale_linter_aliases = ['html', 'javascript', 'css']
+ " OR, Alias a filetype to only a single filetype with a String.
+ let b:ale_linter_aliases = 'javascript'
<
No linters will be loaded when the buffer's filetype is empty.
diff --git a/test/handler/test_rust_handler.vader b/test/handler/test_rust_handler.vader
index e3ab3e86..4764e713 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': '<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': []
+ \ },
+ \ }),
+ \ ])
diff --git a/test/test_linter_retrieval.vader b/test/test_linter_retrieval.vader
index 6c402d54..a1c34622 100644
--- a/test/test_linter_retrieval.vader
+++ b/test/test_linter_retrieval.vader
@@ -130,6 +130,8 @@ Execute (The local alias option shouldn't completely replace the global one):
" global Dictionary.
let b:ale_linter_aliases = {'testft3': ['testft1']}
+ AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1')
+
Execute (Lists should be accepted for local aliases):
call ale#linter#Define('testft1', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2)
@@ -139,6 +141,15 @@ Execute (Lists should be accepted for local aliases):
AssertEqual [g:testlinter2], ale#linter#Get('anything.else')
+Execute (Strings should be accepted for local aliases):
+ call ale#linter#Define('testft1', g:testlinter1)
+ call ale#linter#Define('testft2', g:testlinter2)
+ let g:ale_linter_aliases = {'testft1': ['testft1', 'testft2']}
+ " We should load the testft2 linters for this buffer, with no duplicates.
+ let b:ale_linter_aliases = 'testft2'
+
+ AssertEqual [g:testlinter2], ale#linter#Get('anything.else')
+
Execute (Buffer-local overrides for aliases should be used):
call ale#linter#Define('testft1', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2)