summaryrefslogtreecommitdiff
path: root/ale_linters/thrift/thriftcheck.vim
blob: 7b8cbee1f3f50fcca544d417294a722783a260cb (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
42
43
44
45
46
" Author: Jon Parise <jon@indelible.org>

call ale#Set('thrift_thriftcheck_executable', 'thriftcheck')
call ale#Set('thrift_thriftcheck_options', '')

function! ale_linters#thrift#thriftcheck#GetCommand(buffer) abort
    return '%e'
    \   . ale#Pad(ale#Var(a:buffer, 'thrift_thriftcheck_options'))
    \   . ' --stdin-filename %s'
    \   . ' %t'
endfunction

function! ale_linters#thrift#thriftcheck#Handle(buffer, lines) abort
    " Matches lines like the following:
    "
    " file.thrift:1:1:error: "py" namespace must match "^idl\\." (namespace.pattern)
    " file.thrift:3:5:warning: 64-bit integer constant -2147483649 may not work in all languages (int.64bit)
    let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+):(\l+): (.*) \((.*)\)$'

    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        if l:match[3] is# 'warning'
            let l:type = 'W'
        else
            let l:type = 'E'
        endif

        call add(l:output, {
        \   'lnum': l:match[1] + 0,
        \   'col': l:match[2] + 0,
        \   'type': l:type,
        \   'text': l:match[4],
        \   'code': l:match[5],
        \})
    endfor

    return l:output
endfunction

call ale#linter#Define('thrift', {
\   'name': 'thriftcheck',
\   'executable': {b -> ale#Var(b, 'thrift_thriftcheck_executable')},
\   'command': function('ale_linters#thrift#thriftcheck#GetCommand'),
\   'callback': 'ale_linters#thrift#thriftcheck#Handle',
\})