mirror of https://github.com/dense-analysis/ale
Fix windows path check on rust linter (#736)
* Fix rust linter on windows * Add windows path test * Use ale#path#IsBufferPath to compare paths * Fix errors
This commit is contained in:
parent
d9a7364dae
commit
46225f3bb1
|
@ -8,13 +8,13 @@ if !exists('g:ale_rust_ignore_error_codes')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" returns: a list [lnum, col] with the location of the error or []
|
" returns: a list [lnum, col] with the location of the error or []
|
||||||
function! s:FindErrorInExpansion(span, file_name) abort
|
function! s:FindErrorInExpansion(span, buffer) abort
|
||||||
if a:span.file_name ==# a:file_name
|
if ale#path#IsBufferPath(a:buffer, a:span.file_name)
|
||||||
return [a:span.line_start, a:span.line_end, a:span.byte_start, a:span.byte_end]
|
return [a:span.line_start, a:span.line_end, a:span.byte_start, a:span.byte_end]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !empty(a:span.expansion)
|
if !empty(a:span.expansion)
|
||||||
return s:FindErrorInExpansion(a:span.expansion.span, a:file_name)
|
return s:FindErrorInExpansion(a:span.expansion.span, a:buffer)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
@ -22,7 +22,6 @@ endfunction
|
||||||
|
|
||||||
" A handler function which accepts a file name, to make unit testing easier.
|
" A handler function which accepts a file name, to make unit testing easier.
|
||||||
function! ale#handlers#rust#HandleRustErrorsForFile(buffer, full_filename, lines) abort
|
function! ale#handlers#rust#HandleRustErrorsForFile(buffer, full_filename, lines) abort
|
||||||
let l:filename = fnamemodify(a:full_filename, ':t')
|
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
for l:errorline in a:lines
|
for l:errorline in a:lines
|
||||||
|
@ -48,7 +47,7 @@ function! ale#handlers#rust#HandleRustErrorsForFile(buffer, full_filename, lines
|
||||||
for l:span in l:error.spans
|
for l:span in l:error.spans
|
||||||
if (
|
if (
|
||||||
\ l:span.is_primary
|
\ l:span.is_primary
|
||||||
\ && (a:full_filename =~ (l:span.file_name . '$') || l:span.file_name ==# '<anon>')
|
\ && (ale#path#IsBufferPath(a:buffer, l:span.file_name) || l:span.file_name ==# '<anon>')
|
||||||
\)
|
\)
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'lnum': l:span.line_start,
|
\ 'lnum': l:span.line_start,
|
||||||
|
@ -61,7 +60,7 @@ function! ale#handlers#rust#HandleRustErrorsForFile(buffer, full_filename, lines
|
||||||
else
|
else
|
||||||
" when the error is caused in the expansion of a macro, we have
|
" when the error is caused in the expansion of a macro, we have
|
||||||
" to bury deeper
|
" to bury deeper
|
||||||
let l:root_cause = s:FindErrorInExpansion(l:span, l:filename)
|
let l:root_cause = s:FindErrorInExpansion(l:span, a:buffer)
|
||||||
|
|
||||||
if !empty(l:root_cause)
|
if !empty(l:root_cause)
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
Execute(The Rust handler should handle rustc output):
|
Execute(The Rust handler should handle rustc output):
|
||||||
|
call ale#test#SetFilename('src/playpen.rs')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
\ {
|
\ {
|
||||||
|
@ -18,7 +20,7 @@ Execute(The Rust handler should handle rustc output):
|
||||||
\ 'text': 'no method named `wat` found for type `std::string::String` in the current scope',
|
\ 'text': 'no method named `wat` found for type `std::string::String` in the current scope',
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ ale#handlers#rust#HandleRustErrorsForFile(347, 'src/playpen.rs', [
|
\ ale#handlers#rust#HandleRustErrorsForFile(bufnr(''), 'src/playpen.rs', [
|
||||||
\ '',
|
\ '',
|
||||||
\ 'ignore this',
|
\ 'ignore this',
|
||||||
\ '{"message":"expected one of `.`, `;`, `?`, `}`, or an operator, found `for`","code":null,"level":"error","spans":[{"file_name":"<anon>","byte_start":418,"byte_end":421,"line_start":15,"line_end":15,"column_start":5,"column_end":8,"is_primary":true,"text":[{"text":" for chr in source.trim().chars() {","highlight_start":5,"highlight_end":8}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[],"rendered":null}',
|
\ '{"message":"expected one of `.`, `;`, `?`, `}`, or an operator, found `for`","code":null,"level":"error","spans":[{"file_name":"<anon>","byte_start":418,"byte_end":421,"line_start":15,"line_end":15,"column_start":5,"column_end":8,"is_primary":true,"text":[{"text":" for chr in source.trim().chars() {","highlight_start":5,"highlight_end":8}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[],"rendered":null}',
|
||||||
|
@ -28,6 +30,8 @@ Execute(The Rust handler should handle rustc output):
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
Execute(The Rust handler should handle cargo output):
|
Execute(The Rust handler should handle cargo output):
|
||||||
|
call ale#test#SetFilename('src/playpen.rs')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
\ {
|
\ {
|
||||||
|
@ -47,7 +51,7 @@ Execute(The Rust handler should handle cargo output):
|
||||||
\ 'text': 'no method named `wat` found for type `std::string::String` in the current scope',
|
\ 'text': 'no method named `wat` found for type `std::string::String` in the current scope',
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ ale#handlers#rust#HandleRustErrorsForFile(347, 'src/playpen.rs', [
|
\ ale#handlers#rust#HandleRustErrorsForFile(bufnr(''), 'src/playpen.rs', [
|
||||||
\ '',
|
\ '',
|
||||||
\ 'ignore this',
|
\ '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"}}',
|
\ '{"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"}}',
|
||||||
|
@ -55,7 +59,27 @@ Execute(The Rust handler should handle cargo output):
|
||||||
\ '{"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"}}',
|
\ '{"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 cargo output on Windows):
|
||||||
|
" call ale#test#SetFilename('src\nvim.rs')
|
||||||
|
"
|
||||||
|
" AssertEqual
|
||||||
|
" \ [
|
||||||
|
" \ {
|
||||||
|
" \ 'lnum': 467,
|
||||||
|
" \ 'end_lnum': 467,
|
||||||
|
" \ 'type': 'E',
|
||||||
|
" \ 'col': 43198,
|
||||||
|
" \ 'end_col': 43199,
|
||||||
|
" \ 'text': 'expected one of `!` or `::`, found `#`: unexpected token',
|
||||||
|
" \ },
|
||||||
|
" \ ],
|
||||||
|
" \ ale#handlers#rust#HandleRustErrorsForFile(bufnr(''), 'src\nvim.rs', [
|
||||||
|
" \ '{"message":{"children":[],"code":null,"level":"error","message":"expected one of `!` or `::`, found `#`","rendered":null,"spans":[{"byte_end":43199,"byte_start":43198,"column_end":2,"column_start":1,"expansion":null,"file_name":"src\\nvim.rs","is_primary":true,"label":"unexpected token","line_end":467,"line_start":467,"suggested_replacement":null,"text":[{"highlight_end":2,"highlight_start":1,"text":"#[cfg(test)]\r"}]}]},"package_id":"nvim-gtk 0.1.2 (path+file:///E:/daa/local/neovim-gtk)","reason":"compiler-message","target":{"crate_types":["bin"],"kind":["bin"],"name":"nvim-gtk","src_path":"E:\\daa\\local\\neovim-gtk\\src\\main.rs"}}',
|
||||||
|
" \ ])
|
||||||
|
|
||||||
Execute(The Rust handler should show detailed errors):
|
Execute(The Rust handler should show detailed errors):
|
||||||
|
call ale#test#SetFilename('src/playpen.rs')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
\ {
|
\ {
|
||||||
|
@ -67,7 +91,7 @@ Execute(The Rust handler should show detailed errors):
|
||||||
\ 'text': 'mismatched types: expected bool, found integral variable',
|
\ 'text': 'mismatched types: expected bool, found integral variable',
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ ale#handlers#rust#HandleRustErrorsForFile(347, 'src/playpen.rs', [
|
\ ale#handlers#rust#HandleRustErrorsForFile(bufnr(''), 'src/playpen.rs', [
|
||||||
\ '',
|
\ '',
|
||||||
\ 'ignore this',
|
\ 'ignore this',
|
||||||
\ '{"message":{"children":[],"code":null,"level":"error","message":"mismatched types","rendered":null,"spans":[{"byte_end":54,"byte_start":52,"column_end":23,"column_start":21,"expansion":null,"file_name":"src/playpen.rs","is_primary":true,"label":"expected bool, found integral variable","line_end":4,"line_start":4,"suggested_replacement":null,"text":[{"highlight_end":23,"highlight_start":21,"text":" let foo: bool = 42;"}]}]},"package_id":"ale-rust-details 0.1.1 (path+file:///home/jon/tmp/ale-rust-details)","reason":"compiler-message","target":{"crate_types":["bin"],"kind":["bin"],"name":"ale-rust-details","src_path":"/home/jon/tmp/ale-rust-details/src/main.rs"}}',
|
\ '{"message":{"children":[],"code":null,"level":"error","message":"mismatched types","rendered":null,"spans":[{"byte_end":54,"byte_start":52,"column_end":23,"column_start":21,"expansion":null,"file_name":"src/playpen.rs","is_primary":true,"label":"expected bool, found integral variable","line_end":4,"line_start":4,"suggested_replacement":null,"text":[{"highlight_end":23,"highlight_start":21,"text":" let foo: bool = 42;"}]}]},"package_id":"ale-rust-details 0.1.1 (path+file:///home/jon/tmp/ale-rust-details)","reason":"compiler-message","target":{"crate_types":["bin"],"kind":["bin"],"name":"ale-rust-details","src_path":"/home/jon/tmp/ale-rust-details/src/main.rs"}}',
|
||||||
|
@ -75,9 +99,11 @@ Execute(The Rust handler should show detailed errors):
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
Execute(The Rust handler should find correct files):
|
Execute(The Rust handler should find correct files):
|
||||||
|
call ale#test#SetFilename('src/noerrors/mod.rs')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [],
|
\ [],
|
||||||
\ ale#handlers#rust#HandleRustErrorsForFile(347, 'src/noerrors/mod.rs', [
|
\ ale#handlers#rust#HandleRustErrorsForFile(bufnr(''), 'src/noerrors/mod.rs', [
|
||||||
\ '',
|
\ '',
|
||||||
\ 'ignore this',
|
\ 'ignore this',
|
||||||
\ '{"message":{"children":[],"code":null,"level":"error","message":"unresolved import `Undefined`","rendered":null,"spans":[{"byte_end":103,"byte_start":94,"column_end":14,"column_start":5,"expansion":null,"file_name":"src/haserrors/mod.rs","is_primary":true,"label":"no `Undefined` in the root","line_end":1,"line_start":1,"suggested_replacement":null,"text":[{"highlight_end":14,"highlight_start":5,"text":"use Undefined;"}]}]},"package_id":"sample 0.1.0 (path+file:///private/tmp/sample)","reason":"compiler-message","target":{"crate_types":["lib"],"kind":["lib"],"name":"sample","src_path":"/private/tmp/sample/src/lib.rs"}}',
|
\ '{"message":{"children":[],"code":null,"level":"error","message":"unresolved import `Undefined`","rendered":null,"spans":[{"byte_end":103,"byte_start":94,"column_end":14,"column_start":5,"expansion":null,"file_name":"src/haserrors/mod.rs","is_primary":true,"label":"no `Undefined` in the root","line_end":1,"line_start":1,"suggested_replacement":null,"text":[{"highlight_end":14,"highlight_start":5,"text":"use Undefined;"}]}]},"package_id":"sample 0.1.0 (path+file:///private/tmp/sample)","reason":"compiler-message","target":{"crate_types":["lib"],"kind":["lib"],"name":"sample","src_path":"/private/tmp/sample/src/lib.rs"}}',
|
||||||
|
|
Loading…
Reference in New Issue