]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/idris/idris.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:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / idris / idris.vim
1 " Author: Scott Bonds <scott@ggr.com>
2 " Description: default Idris compiler
3
4 call ale#Set('idris_idris_executable', 'idris')
5 call ale#Set('idris_idris_options', '--total --warnpartial --warnreach --warnipkg')
6
7 function! ale_linters#idris#idris#GetCommand(buffer) abort
8     let l:options = ale#Var(a:buffer, 'idris_idris_options')
9
10     return '%e' . ale#Pad(l:options) . ' --check %s'
11 endfunction
12
13 function! ale_linters#idris#idris#Handle(buffer, lines) abort
14     " This was copied almost verbatim from ale#handlers#haskell#HandleGHCFormat
15     "
16     " Look for lines like the following:
17     " foo.idr:2:6:When checking right hand side of main with expected type
18     " bar.idr:11:11-13:
19     let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)(-\d+)?:(.*)?$'
20     let l:output = []
21
22     let l:corrected_lines = []
23
24     for l:line in a:lines
25         if len(matchlist(l:line, l:pattern)) > 0
26             call add(l:corrected_lines, l:line)
27         elseif len(l:corrected_lines) > 0
28             if l:line is# ''
29                 let l:corrected_lines[-1] .= ' ' " turn a blank line into a space
30             else
31                 let l:corrected_lines[-1] .= l:line
32             endif
33
34             let l:corrected_lines[-1] = substitute(l:corrected_lines[-1], '\s\+', ' ', 'g')
35         endif
36     endfor
37
38     for l:line in l:corrected_lines
39         let l:match = matchlist(l:line, l:pattern)
40
41         if len(l:match) == 0
42             continue
43         endif
44
45         if !ale#path#IsBufferPath(a:buffer, l:match[1])
46             continue
47         endif
48
49         let l:errors = matchlist(l:match[5], '\v([wW]arning|[eE]rror) - ?(.*)')
50
51         if len(l:errors) > 0
52             let l:ghc_type = l:errors[1]
53             let l:text = l:errors[2]
54         else
55             let l:ghc_type = ''
56             let l:text = l:match[5][:0] is# ' ' ? l:match[5][1:] : l:match[5]
57         endif
58
59         if l:ghc_type is? 'Warning'
60             let l:type = 'W'
61         else
62             let l:type = 'E'
63         endif
64
65         call add(l:output, {
66         \   'lnum': l:match[2] + 0,
67         \   'col': l:match[3] + 0,
68         \   'text': l:text,
69         \   'type': l:type,
70         \})
71     endfor
72
73     return l:output
74 endfunction
75
76 call ale#linter#Define('idris', {
77 \   'name': 'idris',
78 \   'executable': {b -> ale#Var(b, 'idris_idris_executable')},
79 \   'command': function('ale_linters#idris#idris#GetCommand'),
80 \   'callback': 'ale_linters#idris#idris#Handle',
81 \})