summaryrefslogtreecommitdiff
path: root/ale_linters/crystal/crystal.vim
blob: 8f38a61b1b21ca0094bdb3ed2aa3d65f8e1adae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
" 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, '')

    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
    let l:crystal_cmd = 'crystal build -f json --no-codegen -o '
    let l:crystal_cmd .= ale#Escape(g:ale#util#nul_file)
    let l:crystal_cmd .= ' %s'

    return l:crystal_cmd
endfunction

call ale#linter#Define('crystal', {
\   'name': 'crystal',
\   'executable': 'crystal',
\   'output_stream': 'both',
\   'lint_file': 1,
\   'command_callback': 'ale_linters#crystal#crystal#GetCommand',
\   'callback': 'ale_linters#crystal#crystal#Handle',
\})