2017-04-13 21:19:53 -04:00
|
|
|
" Author: Jordan Andree <https://github.com/jordanandree>
|
|
|
|
" Description: This file adds support for checking Crystal with crystal build
|
|
|
|
|
|
|
|
function! ale_linters#crystal#crystal#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
let l:lines = join(a:lines, '')
|
2017-04-15 07:52:08 -04:00
|
|
|
|
2017-04-13 21:19:53 -04:00
|
|
|
if !empty(l:lines)
|
|
|
|
let l:errors = json_decode(l:lines)
|
|
|
|
|
|
|
|
for l:error in l:errors
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'bufnr': a:buffer,
|
|
|
|
\ 'lnum': l:error.line + 0,
|
|
|
|
\ 'col': l:error.column + 0,
|
|
|
|
\ 'text': l:error.message,
|
|
|
|
\ 'type': 'E',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#crystal#crystal#GetCommand(buffer) abort
|
2017-04-15 07:52:08 -04:00
|
|
|
let l:crystal_cmd = 'crystal build -f json --no-codegen -o '
|
2017-05-12 04:20:16 -04:00
|
|
|
let l:crystal_cmd .= ale#Escape(g:ale#util#nul_file)
|
2017-04-15 10:37:32 -04:00
|
|
|
let l:crystal_cmd .= ' %s'
|
2017-04-13 21:19:53 -04:00
|
|
|
|
2017-04-15 07:52:08 -04:00
|
|
|
return l:crystal_cmd
|
2017-04-13 21:19:53 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('crystal', {
|
|
|
|
\ 'name': 'crystal',
|
|
|
|
\ 'executable': 'crystal',
|
|
|
|
\ 'output_stream': 'both',
|
2017-04-15 10:37:32 -04:00
|
|
|
\ 'lint_file': 1,
|
2017-04-13 21:19:53 -04:00
|
|
|
\ 'command_callback': 'ale_linters#crystal#crystal#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#crystal#crystal#Handle',
|
|
|
|
\})
|