]> git.madduck.net Git - etc/vim.git/blob - ale_linters/thrift/thrift.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 / thrift / thrift.vim
1 " Author: Jon Parise <jon@indelible.org>
2
3 call ale#Set('thrift_thrift_executable', 'thrift')
4 call ale#Set('thrift_thrift_generators', ['cpp'])
5 call ale#Set('thrift_thrift_includes', ['.'])
6 call ale#Set('thrift_thrift_options', '-strict')
7
8 function! ale_linters#thrift#thrift#GetCommand(buffer) abort
9     let l:generators = ale#Var(a:buffer, 'thrift_thrift_generators')
10     let l:includes = ale#Var(a:buffer, 'thrift_thrift_includes')
11
12     " The thrift compiler requires at least one generator. If none are set,
13     " fall back to our default value to avoid silently failing. We could also
14     " `throw` here, but that seems even less helpful.
15     if empty(l:generators)
16         let l:generators = ['cpp']
17     endif
18
19     let l:output_dir = ale#command#CreateDirectory(a:buffer)
20
21     return '%e'
22     \   . ale#Pad(join(map(copy(l:generators), "'--gen ' . v:val")))
23     \   . ale#Pad(join(map(copy(l:includes), "'-I ' . v:val")))
24     \   . ale#Pad(ale#Var(a:buffer, 'thrift_thrift_options'))
25     \   . ' -out ' . ale#Escape(l:output_dir)
26     \   . ' %t'
27 endfunction
28
29 function! ale_linters#thrift#thrift#Handle(buffer, lines) abort
30     " Matches lines like the following:
31     "
32     " [SEVERITY:/path/filename.thrift:31] Message text
33     " [ERROR:/path/filename.thrift:31] (last token was ';')
34     let l:pattern = '\v^\[(\u+):(.*):(\d+)\] (.*)$'
35
36     let l:index = 0
37     let l:output = []
38
39     " Roll our own output-matching loop instead of using ale#util#GetMatches
40     " because we need to support error messages that span multiple lines.
41     while l:index < len(a:lines)
42         let l:line = a:lines[l:index]
43
44         let l:match = matchlist(l:line, l:pattern)
45
46         if empty(l:match)
47             let l:index += 1
48             continue
49         endif
50
51         let l:severity = l:match[1]
52
53         if l:severity is# 'WARNING'
54             let l:type = 'W'
55         else
56             let l:type = 'E'
57         endif
58
59         " If our text looks like "(last token was ';')", the *next* line
60         " should contain a more descriptive error message.
61         let l:text = l:match[4]
62
63         if l:text =~# '\(last token was .*\)'
64             let l:index += 1
65             let l:text = get(a:lines, l:index, 'Unknown error ' . l:text)
66         endif
67
68         call add(l:output, {
69         \   'lnum': l:match[3] + 0,
70         \   'col': 0,
71         \   'type': l:type,
72         \   'text': l:text,
73         \})
74
75         let l:index += 1
76     endwhile
77
78     return l:output
79 endfunction
80
81 call ale#linter#Define('thrift', {
82 \   'name': 'thrift',
83 \   'output_stream': 'both',
84 \   'executable': {b -> ale#Var(b, 'thrift_thrift_executable')},
85 \   'command': function('ale_linters#thrift#thrift#GetCommand'),
86 \   'callback': 'ale_linters#thrift#thrift#Handle',
87 \})