All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Daniel Schemala <istjanichtzufassen@gmail.com>,
2 " w0rp <devw0rp@gmail.com>
4 " Description: This file implements handlers specific to Rust.
6 if !exists('g:ale_rust_ignore_error_codes')
7 let g:ale_rust_ignore_error_codes = []
10 if !exists('g:ale_rust_ignore_secondary_spans')
11 let g:ale_rust_ignore_secondary_spans = 0
14 function! s:FindSpan(buffer, span) abort
15 if ale#path#IsBufferPath(a:buffer, a:span.file_name) || a:span.file_name is# '<anon>'
19 " Search inside the expansion of an error, as the problem for this buffer
20 " could lie inside a nested object.
21 if !empty(get(a:span, 'expansion', v:null))
22 return s:FindSpan(a:buffer, a:span.expansion.span)
28 function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort
31 for l:errorline in a:lines
32 " ignore everything that is not JSON
33 if l:errorline !~# '^{'
37 let l:error = json_decode(l:errorline)
39 if has_key(l:error, 'message') && type(l:error.message) is v:t_dict
40 let l:error = l:error.message
43 if !has_key(l:error, 'code')
47 if !empty(l:error.code) && index(g:ale_rust_ignore_error_codes, l:error.code.code) > -1
51 for l:root_span in l:error.spans
52 let l:span = s:FindSpan(a:buffer, l:root_span)
54 if ale#Var(a:buffer, 'rust_ignore_secondary_spans') && !get(l:span, 'is_primary', 1)
60 \ 'lnum': l:span.line_start,
61 \ 'end_lnum': l:span.line_end,
62 \ 'col': l:span.column_start,
63 \ 'end_col': l:span.column_end-1,
64 \ 'text': empty(l:span.label) ? l:error.message : printf('%s: %s', l:error.message, l:span.label),
65 \ 'type': toupper(l:error.level[0]),
68 if has_key(l:error, 'rendered') && !empty(l:error.rendered)
69 let l:output_line.detail = l:error.rendered
72 call add(l:output, l:output_line)