Merge pull request #2559 from nerdrew/rust-cargo-rendered-detail

show rendered cargo error in detail for clippy errors
This commit is contained in:
w0rp 2019-06-08 23:20:18 +01:00 committed by GitHub
commit d9931b9891
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 2 deletions

View file

@ -56,14 +56,20 @@ function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort
endif endif
if !empty(l:span) if !empty(l:span)
call add(l:output, { let l:output_line = {
\ 'lnum': l:span.line_start, \ 'lnum': l:span.line_start,
\ 'end_lnum': l:span.line_end, \ 'end_lnum': l:span.line_end,
\ 'col': l:span.column_start, \ 'col': l:span.column_start,
\ 'end_col': l:span.column_end-1, \ 'end_col': l:span.column_end-1,
\ 'text': empty(l:span.label) ? l:error.message : printf('%s: %s', l:error.message, l:span.label), \ 'text': empty(l:span.label) ? l:error.message : printf('%s: %s', l:error.message, l:span.label),
\ 'type': toupper(l:error.level[0]), \ 'type': toupper(l:error.level[0]),
\}) \}
if has_key(l:error, 'rendered') && !empty(l:error.rendered)
let l:output_line.detail = l:error.rendered
endif
call add(l:output, l:output_line)
endif endif
endfor endfor
endfor endfor

View file

@ -247,6 +247,57 @@ Execute(The Rust handler should show detailed errors):
\ }), \ }),
\ ]) \ ])
Execute(The Rust handler should show detailed clippy errors with rendered field if it's available):
call ale#test#SetFilename('src/playpen.rs')
AssertEqual
\ [
\ {
\ 'lnum': 4,
\ 'end_lnum': 4,
\ 'type': 'E',
\ 'col': 21,
\ 'end_col': 22,
\ 'text': 'mismatched types: expected bool, found integral variable',
\ 'detail': 'this is a detailed description',
\ },
\ ],
\ ale#handlers#rust#HandleRustErrors(bufnr(''), [
\ '',
\ 'ignore this',
\ json_encode({
\ 'message': {
\ 'code': v:null,
\ 'level': 'error',
\ 'message': 'mismatched types',
\ 'rendered': 'this is a detailed description',
\ 'spans': [
\ {
\ 'byte_end': 54,
\ 'byte_start': 52,
\ 'column_end': 23,
\ 'column_start': 21,
\ 'expansion': v:null,
\ 'file_name': ale#path#Simplify('src/playpen.rs'),
\ 'is_primary': v:true,
\ 'label': 'expected bool, found integral variable',
\ 'line_end': 4,
\ 'line_start': 4,
\ }
\ ]
\ },
\ }),
\ json_encode({
\ 'message': {
\ 'code': v:null,
\ 'level': 'error',
\ 'message': 'aborting due to previous error(s)',
\ 'spans': [
\ ]
\ },
\ }),
\ ])
Execute(The Rust handler should find correct files): Execute(The Rust handler should find correct files):
call ale#test#SetFilename('src/noerrors/mod.rs') call ale#test#SetFilename('src/noerrors/mod.rs')