]> git.madduck.net Git - etc/vim.git/blob - ale_linters/perl6/perl6.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] / ale_linters / perl6 / perl6.vim
1 " Author:Travis Gibson <https://github.com/Garland-g>
2 " Description: This file adds support for checking perl6 syntax
3
4 let g:ale_perl6_perl6_executable =
5 \   get(g:, 'ale_perl6_perl6_executable', 'perl6')
6
7 let g:ale_perl6_perl6_options =
8 \   get(g:, 'ale_perl6_perl6_options', '-c -Ilib')
9
10 let $PERL6_EXCEPTIONS_HANDLER = 'JSON'
11
12 let $RAKUDO_ERROR_COLOR = 0
13
14 function! ale_linters#perl6#perl6#GetExecutable(buffer) abort
15     return ale#Var(a:buffer, 'perl6_perl6_executable')
16 endfunction
17
18 function! ale_linters#perl6#perl6#GetCommand(buffer) abort
19     return ale_linters#perl6#perl6#GetExecutable(a:buffer)
20     \   . ' ' . ale#Var(a:buffer, 'perl6_perl6_options')
21     \   . ' %t'
22 endfunction
23
24 function! ale_linters#perl6#perl6#ExtractError(dict, item, type, buffer) abort
25     let l:file = ''
26     let l:line = 1
27     let l:column = ''
28     let l:text = ''
29     let l:pre = ''
30     let l:counter = 2
31     let l:end_line = ''
32     let l:linepatternmessage = 'at\s\+line\s\+\(\d\+\)'
33
34     if has_key(a:dict[a:item], 'filename') && !empty(a:dict[a:item]['filename'])
35         let l:file = a:dict[a:item]['filename']
36     endif
37
38     if has_key(a:dict[a:item], 'line') && !empty(a:dict[a:item]['line'])
39         let l:line = a:dict[a:item]['line']
40         let l:counter -= 1
41     endif
42
43     if has_key(a:dict[a:item], 'column') && !empty(a:dict[a:item]['column'])
44         let l:column = a:dict[a:item]['column']
45     endif
46
47     if has_key(a:dict[a:item], 'message') && !empty(a:dict[a:item]['message'])
48         let l:text = substitute(a:dict[a:item]['message'], '\s*\n\s*', ' ', 'g')
49         let l:counter -= 1
50     endif
51
52     if has_key(a:dict[a:item], 'line-real') && !empty(a:dict[a:item]['line-real'])
53         let l:end_line = l:line
54         let l:line = a:dict[a:item]['line-real']
55     endif
56
57     for l:match in ale#util#GetMatches(l:text, l:linepatternmessage)
58         let l:line = l:match[1]
59         let l:counter -= 1
60     endfor
61
62 " Currently, filenames and line numbers are not always given in the error output
63     if l:counter < 2
64     \&& ( ale#path#IsBufferPath(a:buffer, l:file) || l:file is# '' )
65         return {
66         \   'lnum': '' . l:line,
67         \   'text': l:text,
68         \   'type': a:type,
69         \   'col': l:column,
70         \   'end_lnum': l:end_line,
71         \   'code': a:item,
72         \}
73     endif
74
75     return ''
76 endfunction
77
78 function! ale_linters#perl6#perl6#Handle(buffer, lines) abort
79     let l:output = []
80
81     if empty(a:lines)
82         return l:output
83     endif
84
85     if a:lines[0] is# 'Syntax OK'
86         return l:output
87     endif
88
89     try
90         let l:json = json_decode(join(a:lines, ''))
91     catch /E474\|E491/
92         call add(l:output, {
93         \   'lnum': '1',
94         \   'text': 'Received output in the default Perl6 error format. See :ALEDetail for details',
95         \   'detail': join(a:lines, "\n"),
96         \   'type': 'W',
97         \   })
98
99         return l:output
100     endtry
101
102     if type(l:json) is v:t_dict
103         for l:key in keys(l:json)
104             if has_key(l:json[l:key], 'sorrows')
105             \&& has_key(l:json[l:key], 'worries')
106                 if !empty(l:json[l:key]['sorrows'])
107                     for l:dictionary in get(l:json[l:key], 'sorrows')
108                         for l:item in keys(l:dictionary)
109                             let l:result =
110                             \   ale_linters#perl6#perl6#ExtractError(
111                             \       l:dictionary,
112                             \       l:item,
113                             \       'E',
114                             \       a:buffer,
115                             \   )
116
117                             if l:result isnot# ''
118                                 call add(l:output, l:result)
119                             endif
120                         endfor
121                     endfor
122                 endif
123
124                 if !empty(l:json[l:key]['worries'])
125                     for l:dictionary in get(l:json[l:key], 'worries')
126                         for l:item in keys(l:dictionary)
127                             let l:result =
128                             \   ale_linters#perl6#perl6#ExtractError(
129                             \       l:dictionary,
130                             \       l:item,
131                             \       'W',
132                             \       a:buffer,
133                             \   )
134
135                             if l:result isnot# ''
136                                 call add(l:output, l:result)
137                             endif
138                         endfor
139                     endfor
140                 endif
141             else
142                 let l:result = ale_linters#perl6#perl6#ExtractError(
143                 \     l:json,
144                 \     l:key,
145                 \     'E',
146                 \     a:buffer,
147                 \   )
148
149                 if l:result isnot# ''
150                     call add(l:output, l:result)
151                 endif
152             endif
153         endfor
154     endif
155
156     return l:output
157 endfunction
158
159 call ale#linter#Define('perl6', {
160 \   'name': 'perl6',
161 \   'executable': function('ale_linters#perl6#perl6#GetExecutable'),
162 \   'output_stream': 'both',
163 \   'command': function('ale_linters#perl6#perl6#GetCommand'),
164 \   'callback': 'ale_linters#perl6#perl6#Handle',
165 \})
166