]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/rust.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / handlers / rust.vim
1 " Author: Daniel Schemala <istjanichtzufassen@gmail.com>,
2 "   w0rp <devw0rp@gmail.com>
3 "
4 " Description: This file implements handlers specific to Rust.
5
6 if !exists('g:ale_rust_ignore_error_codes')
7     let g:ale_rust_ignore_error_codes = []
8 endif
9
10 if !exists('g:ale_rust_ignore_secondary_spans')
11     let g:ale_rust_ignore_secondary_spans = 0
12 endif
13
14 function! s:FindSpan(buffer, span) abort
15     if ale#path#IsBufferPath(a:buffer, a:span.file_name) || a:span.file_name is# '<anon>'
16         return a:span
17     endif
18
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)
23     endif
24
25     return {}
26 endfunction
27
28 function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort
29     let l:output = []
30
31     for l:errorline in a:lines
32         " ignore everything that is not JSON
33         if l:errorline !~# '^{'
34             continue
35         endif
36
37         let l:error = json_decode(l:errorline)
38
39         if has_key(l:error, 'message') && type(l:error.message) is v:t_dict
40             let l:error = l:error.message
41         endif
42
43         if !has_key(l:error, 'code')
44             continue
45         endif
46
47         if !empty(l:error.code) && index(g:ale_rust_ignore_error_codes, l:error.code.code) > -1
48             continue
49         endif
50
51         for l:root_span in l:error.spans
52             let l:span = s:FindSpan(a:buffer, l:root_span)
53
54             if ale#Var(a:buffer, 'rust_ignore_secondary_spans') && !get(l:span, 'is_primary', 1)
55                 continue
56             endif
57
58             if !empty(l:span)
59                 let l:output_line = {
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]),
66                 \}
67
68                 if has_key(l:error, 'rendered') && !empty(l:error.rendered)
69                     let l:output_line.detail = l:error.rendered
70                 endif
71
72                 call add(l:output, l:output_line)
73             endif
74         endfor
75     endfor
76
77     return l:output
78 endfunction