From d4819b0279332bd831a690c449fd8593538ea024 Mon Sep 17 00:00:00 2001 From: cos Date: Fri, 18 Feb 2022 17:27:29 +0100 Subject: fixup, wip: Process spans and their expansions --- autoload/ale/handlers/rust.vim | 67 +++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim index 12a826e0..676e6c13 100644 --- a/autoload/ale/handlers/rust.vim +++ b/autoload/ale/handlers/rust.vim @@ -11,10 +11,41 @@ if !exists('g:ale_rust_ignore_secondary_spans') let g:ale_rust_ignore_secondary_spans = 0 endif +function! s:ProcessSpan(buffer, error, span) abort + if ale#Var(a:buffer, 'rust_ignore_secondary_spans') && !get(a:span, 'is_primary', 1) + return {} + endif + + if !empty(a:span) + " :help ale-loclist-format + let l:output_line = { + \ 'lnum': a:span.line_start, + \ 'end_lnum': a:span.line_end, + \ 'col': a:span.column_start, + \ 'end_col': a:span.column_end-1, + \ 'text': empty(a:span.label) ? a:error.message : printf('%s: %s', a:error.message, a:span.label), + \ 'type': toupper(a:error.level[0]), + \} + " When operating on stdin rustc (and possibly others) gives '' + " as the file_name. Leaving the filename property of the loclist + " unpopulated makes ale connect such errors with the linted buffer. + if a:span.file_name !=# '' + let l:output_line['filename'] = a:span.file_name + endif + + if has_key(a:error, 'rendered') && !empty(a:error.rendered) + let l:output_line.detail = a:error.rendered + endif + + return l:output_line + endif + return {} +endfunction + function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort let l:output = [] - " Format of JSON + " Format of JSON is documented at " rustc: https://doc.rust-lang.org/rustc/json.html " cargo: https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages for l:diagnosticsline in a:lines @@ -37,29 +68,23 @@ function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort continue endif - for l:root_span in l:diagnostics.spans - let l:span = l:root_span + let l:spans = [] - if ale#Var(a:buffer, 'rust_ignore_secondary_spans') && !get(l:span, 'is_primary', 1) - continue - endif + " FIXME One might also wish to loop over l:diagnostics.children and + " their spans. + for l:span in l:diagnostics.spans + call add(l:spans, l:span) - if !empty(l:span) - " :help ale-loclist-format - let l:output_line = { - \ 'filename': l:span.file_name, - \ 'lnum': l:span.line_start, - \ 'end_lnum': l:span.line_end, - \ 'col': l:span.column_start, - \ 'end_col': l:span.column_end-1, - \ 'text': empty(l:span.label) ? l:diagnostics.message : printf('%s: %s', l:diagnostics.message, l:span.label), - \ 'type': toupper(l:diagnostics.level[0]), - \} - - if has_key(l:diagnostics, 'rendered') && !empty(l:diagnostics.rendered) - let l:output_line.detail = l:diagnostics.rendered - endif + let l:expansion = l:span.expansion + if !empty(l:expansion) + let l:expansion_span = l:expansion.span + call add(l:spans, l:expansion_span) + endif + endfor + for l:span in l:spans + let l:output_line = s:ProcessSpan(a:buffer, l:diagnostics, l:span) + if !empty(l:output_line) call add(l:output, l:output_line) endif endfor -- cgit v1.2.3