summaryrefslogtreecommitdiff
path: root/ale_linters/rust
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-02-07 21:17:03 +0000
committerw0rp <devw0rp@gmail.com>2017-02-07 21:17:10 +0000
commitc3ebe7bd9eb70952cdbdf8a0a8127533c493fe34 (patch)
tree91e706ee6dbf29dc9040ff01875aa2ef6d8d1344 /ale_linters/rust
parent472631573ed46f8750fd07906068ccf14d341c9b (diff)
downloadale-c3ebe7bd9eb70952cdbdf8a0a8127533c493fe34.zip
Cover the Rust handler with some tests
Diffstat (limited to 'ale_linters/rust')
-rw-r--r--ale_linters/rust/cargo.vim3
-rw-r--r--ale_linters/rust/rustc.vim83
2 files changed, 2 insertions, 84 deletions
diff --git a/ale_linters/rust/cargo.vim b/ale_linters/rust/cargo.vim
index 8c782656..7f821d2c 100644
--- a/ale_linters/rust/cargo.vim
+++ b/ale_linters/rust/cargo.vim
@@ -1,7 +1,6 @@
" Author: Daniel Schemala <istjanichtzufassen@gmail.com>
" Description: rustc invoked by cargo for rust files
-
function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
if ale#util#FindNearestFile(a:bufnr, 'Cargo.toml') !=# ''
return 'cargo'
@@ -16,6 +15,6 @@ call ale#linter#Define('rust', {
\ 'name': 'cargo',
\ 'executable_callback': 'ale_linters#rust#cargo#GetCargoExecutable',
\ 'command': 'cargo build --message-format=json -q',
-\ 'callback': 'ale_linters#rust#rustc#HandleRustcErrors',
+\ 'callback': 'ale#handlers#rust#HandleRustErrors',
\ 'output_stream': 'stdout',
\})
diff --git a/ale_linters/rust/rustc.vim b/ale_linters/rust/rustc.vim
index 97d5d0bb..1d080b98 100644
--- a/ale_linters/rust/rustc.vim
+++ b/ale_linters/rust/rustc.vim
@@ -1,86 +1,6 @@
" Author: Daniel Schemala <istjanichtzufassen@gmail.com>
" Description: rustc for rust files
-if !exists('g:ale_rust_ignore_error_codes')
- let g:ale_rust_ignore_error_codes = []
-endif
-
-
-function! ale_linters#rust#rustc#HandleRustcErrors(buffer_number, errorlines) abort
- let l:file_name = fnamemodify(bufname(a:buffer_number), ':t')
- let l:output = []
-
- for l:errorline in a:errorlines
- " ignore everything that is not Json
- if l:errorline !~# '^{'
- continue
- endif
-
- let l:error = json_decode(l:errorline)
-
- if has_key(l:error, 'message') && type(l:error.message) == type({})
- let l:error = l:error.message
- endif
-
- if !has_key(l:error, 'code')
- continue
- endif
-
- if !empty(l:error.code) && index(g:ale_rust_ignore_error_codes, l:error.code.code) > -1
- continue
- endif
-
- for l:span in l:error.spans
- let l:span.file_name = fnamemodify(l:span.file_name, ':t')
- if l:span.is_primary &&
- \ (l:span.file_name ==# l:file_name || l:span.file_name ==# '<anon>')
- call add(l:output, {
- \ 'bufnr': a:buffer_number,
- \ 'lnum': l:span.line_start,
- \ 'vcol': 0,
- \ 'col': l:span.byte_start,
- \ 'nr': -1,
- \ 'text': l:error.message,
- \ 'type': toupper(l:error.level[0]),
- \})
- else
- " when the error is caused in the expansion of a macro, we have
- " to bury deeper
- let l:root_cause = s:FindErrorInExpansion(l:span, l:file_name)
-
- if !empty(l:root_cause)
- call add(l:output, {
- \ 'bufnr': a:buffer_number,
- \ 'lnum': l:root_cause[0],
- \ 'vcol': 0,
- \ 'col': l:root_cause[1],
- \ 'nr': -1,
- \ 'text': l:error.message,
- \ 'type': toupper(l:error.level[0]),
- \})
- endif
- endif
- endfor
- endfor
-
- return l:output
-endfunction
-
-
-" returns: a list [lnum, col] with the location of the error or []
-function! s:FindErrorInExpansion(span, file_name) abort
- if a:span.file_name ==# a:file_name
- return [a:span.line_start, a:span.byte_start]
- endif
-
- if !empty(a:span.expansion)
- return s:FindErrorInExpansion(a:span.expansion.span, a:file_name)
- endif
-
- return []
-endfunction
-
-
function! ale_linters#rust#rustc#RustcCommand(buffer_number) abort
" Try to guess the library search path. If the project is managed by cargo,
" it's usually <project root>/target/debug/deps/ or
@@ -98,11 +18,10 @@ function! ale_linters#rust#rustc#RustcCommand(buffer_number) abort
return 'rustc --error-format=json -Z no-trans ' . l:dependencies . ' -'
endfunction
-
call ale#linter#Define('rust', {
\ 'name': 'rustc',
\ 'executable': 'rustc',
\ 'command_callback': 'ale_linters#rust#rustc#RustcCommand',
-\ 'callback': 'ale_linters#rust#rustc#HandleRustcErrors',
+\ 'callback': 'ale#handlers#rust#HandleRustErrors',
\ 'output_stream': 'stderr',
\})