]> git.r.bdr.sh - rbdr/dotfiles/blame - vim/syntax_checkers/vala.vim
Update the stuff
[rbdr/dotfiles] / vim / syntax_checkers / vala.vim
CommitLineData
0d23b6e5
BB
1"============================================================================
2"File: vala.vim
3"Description: Syntax checking plugin for syntastic.vim
4"Maintainer: Konstantin Stepanov (me@kstep.me)
5"Notes: Add special comment line into your vala file starting with
6" "// modules: " and containing space delimited list of vala
7" modules, used by the file, so this script can build correct
8" --pkg arguments.
9" Valac compiler is not the fastest thing in the world, so you
10" may want to disable this plugin with
11" let g:syntastic_vala_check_disabled = 1 command in your .vimrc or
12" command line. Unlet this variable to set it to 0 to reenable
13" this checker.
14"License: This program is free software. It comes without any warranty,
15" to the extent permitted by applicable law. You can redistribute
16" it and/or modify it under the terms of the Do What The Fuck You
17" Want To Public License, Version 2, as published by Sam Hocevar.
18" See http://sam.zoy.org/wtfpl/COPYING for more details.
19"
20"============================================================================
21
22if exists('loaded_vala_syntax_checker')
23 finish
24endif
25let loaded_vala_syntax_checker = 1
26
27if !executable('valac')
28 finish
29endif
30
31if exists('g:syntastic_vala_check_disabled') && g:syntastic_vala_check_disabled
32 finish
33endif
34
35function! SyntaxCheckers_vala_Term(pos)
36 let strlength = strlen(matchstr(a:pos['text'], '\^\+$'))
37 return '\%>'.(a:pos.col-1).'c.*\%<'.(a:pos.col+strlength+1).'c'
38endfunction
39
40function! s:GetValaModules()
41 let modules_line = search('^// modules: ', 'n')
42 let modules_str = getline(modules_line)
43 let modules = split(strpart(modules_str, 12), '\s\+')
44 return modules
45endfunction
46
47function! SyntaxCheckers_vala_GetLocList()
48 let vala_pkg_args = join(map(s:GetValaModules(), '"--pkg ".v:val'), ' ')
49 let makeprg = 'valac -C ' . vala_pkg_args . ' ' .shellescape(expand('%'))
50 let errorformat = '%A%f:%l.%c-%\d%\+.%\d%\+: %t%[a-z]%\+: %m,%C%m,%Z%m'
51
52 let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
53 call SyntasticHighlightErrors(loclist, function("SyntaxCheckers_vala_Term"), 1)
54 return loclist
55endfunction
56