summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-10-25 15:38:33 +0100
committerGitHub <noreply@github.com>2018-10-25 15:38:33 +0100
commit320c74ce1a28bfb4f2e10e1efcd2ca93701fc00e (patch)
tree72a2860d0a2660e8f32dd67a087973992508b0b6 /ale_linters
parent3e65e85178d144c464702570fc20b88fd5e2e20e (diff)
parentadad9a21ab3fa16b115c044de3c46d98b577f72b (diff)
downloadale-320c74ce1a28bfb4f2e10e1efcd2ca93701fc00e.zip
Merge pull request #1958 from Garland-g/perl6
Add Perl6 support via 'perl6 -c'
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/perl6/perl6.vim166
1 files changed, 166 insertions, 0 deletions
diff --git a/ale_linters/perl6/perl6.vim b/ale_linters/perl6/perl6.vim
new file mode 100644
index 00000000..b33a0c51
--- /dev/null
+++ b/ale_linters/perl6/perl6.vim
@@ -0,0 +1,166 @@
+" Author:Travis Gibson <https://github.com/Garland-g>
+" Description: This file adds support for checking perl6 syntax
+
+let g:ale_perl6_perl6_executable =
+\ get(g:, 'ale_perl6_perl6_executable', 'perl6')
+
+let g:ale_perl6_perl6_options =
+\ get(g:, 'ale_perl6_perl6_options', '-c -Ilib')
+
+let $PERL6_EXCEPTIONS_HANDLER = 'JSON'
+
+let $RAKUDO_ERROR_COLOR = 0
+
+function! ale_linters#perl6#perl6#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'perl6_perl6_executable')
+endfunction
+
+function! ale_linters#perl6#perl6#GetCommand(buffer) abort
+ return ale_linters#perl6#perl6#GetExecutable(a:buffer)
+ \ . ' ' . ale#Var(a:buffer, 'perl6_perl6_options')
+ \ . ' %t'
+endfunction
+
+function! ale_linters#perl6#perl6#ExtractError(dict, item, type, buffer) abort
+ let l:file = ''
+ let l:line = 1
+ let l:column = ''
+ let l:text = ''
+ let l:pre = ''
+ let l:counter = 2
+ let l:end_line = ''
+ let l:linepatternmessage = 'at\s\+line\s\+\(\d\+\)'
+
+ if has_key(a:dict[a:item], 'filename') && !empty(a:dict[a:item]['filename'])
+ let l:file = a:dict[a:item]['filename']
+ endif
+
+ if has_key(a:dict[a:item], 'line') && !empty(a:dict[a:item]['line'])
+ let l:line = a:dict[a:item]['line']
+ let l:counter -= 1
+ endif
+
+ if has_key(a:dict[a:item], 'column') && !empty(a:dict[a:item]['column'])
+ let l:column = a:dict[a:item]['column']
+ endif
+
+ if has_key(a:dict[a:item], 'message') && !empty(a:dict[a:item]['message'])
+ let l:text = substitute(a:dict[a:item]['message'], '\s*\n\s*', ' ', 'g')
+ let l:counter -= 1
+ endif
+
+ if has_key(a:dict[a:item], 'line-real') && !empty(a:dict[a:item]['line-real'])
+ let l:end_line = l:line
+ let l:line = a:dict[a:item]['line-real']
+ endif
+
+ for l:match in ale#util#GetMatches(l:text, l:linepatternmessage)
+ let l:line = l:match[1]
+ let l:counter -= 1
+ endfor
+
+" Currently, filenames and line numbers are not always given in the error output
+ if l:counter < 2
+ \&& ( ale#path#IsBufferPath(a:buffer, l:file) || l:file is# '' )
+ return {
+ \ 'lnum': '' . l:line,
+ \ 'text': l:text,
+ \ 'type': a:type,
+ \ 'col': l:column,
+ \ 'end_lnum': l:end_line,
+ \ 'code': a:item,
+ \}
+ endif
+
+ return ''
+endfunction
+
+function! ale_linters#perl6#perl6#Handle(buffer, lines) abort
+ let l:output = []
+
+ if empty(a:lines)
+ return l:output
+ endif
+
+ if a:lines[0] is# 'Syntax OK'
+ return l:output
+ endif
+
+ try
+ let l:json = json_decode(join(a:lines, ''))
+ catch /E474/
+ call add(l:output, {
+ \ 'lnum': '1',
+ \ 'text': 'Received output in the default Perl6 error format. See :ALEDetail for details',
+ \ 'detail': join(a:lines, "\n"),
+ \ 'type': 'W',
+ \ })
+
+ return l:output
+ endtry
+
+ if type(l:json) is v:t_dict
+ for l:key in keys(l:json)
+ if has_key(l:json[l:key], 'sorrows') &&
+ \ has_key(l:json[l:key], 'worries')
+ if !empty(l:json[l:key]['sorrows'])
+ for l:dictionary in get(l:json[l:key], 'sorrows')
+ for l:item in keys(l:dictionary)
+ let l:result =
+ \ ale_linters#perl6#perl6#ExtractError(
+ \ l:dictionary,
+ \ l:item,
+ \ 'E',
+ \ a:buffer,
+ \ )
+
+ if l:result isnot# ''
+ call add(l:output, l:result)
+ endif
+ endfor
+ endfor
+ endif
+
+ if !empty(l:json[l:key]['worries'])
+ for l:dictionary in get(l:json[l:key], 'worries')
+ for l:item in keys(l:dictionary)
+ let l:result =
+ \ ale_linters#perl6#perl6#ExtractError(
+ \ l:dictionary,
+ \ l:item,
+ \ 'W',
+ \ a:buffer,
+ \ )
+
+ if l:result isnot# ''
+ call add(l:output, l:result)
+ endif
+ endfor
+ endfor
+ endif
+ else
+ let l:result = ale_linters#perl6#perl6#ExtractError(
+ \ l:json,
+ \ l:key,
+ \ 'E',
+ \ a:buffer,
+ \ )
+
+ if l:result isnot# ''
+ call add(l:output, l:result)
+ endif
+ endif
+ endfor
+ endif
+
+ return l:output
+endfunction
+
+call ale#linter#Define('perl6', {
+\ 'name': 'perl6',
+\ 'executable_callback': 'ale_linters#perl6#perl6#GetExecutable',
+\ 'output_stream': 'both',
+\ 'command_callback': 'ale_linters#perl6#perl6#GetCommand',
+\ 'callback': 'ale_linters#perl6#perl6#Handle',
+\})
+