rebase on 2015
[Vimrc.git] / bundle / syntastic-3.4.0 / syntax_checkers / vala / valac.vim
blobe6c1b88dba0b2bb98709b9e5287b3e76e5757181
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 "             Add another special comment line into your vala file starting
10 "             with "// vapidirs: " followed by a space delimited list of
11 "             the vapi directories so this script can build with the correct
12 "             --vapidir arguments
13 "             Alternatively you can set the g:syntastic_vala_modules array
14 "             and/or the g:syntastic_vala_vapidirs array
15 "             in your .vimrc or .lvimrc with localvimrc plugin
16 "             (http://www.vim.org/scripts/script.php?script_id=441).
17 "             Valac compiler is not the fastest thing in the world, so you
18 "             may want to disable this plugin with
19 "             let g:syntastic_vala_check_disabled = 1 command in your .vimrc or
20 "             command line. Unlet this variable to set it to 0 to reenable
21 "             this checker.
22 "License:     This program is free software. It comes without any warranty,
23 "             to the extent permitted by applicable law. You can redistribute
24 "             it and/or modify it under the terms of the Do What The Fuck You
25 "             Want To Public License, Version 2, as published by Sam Hocevar.
26 "             See http://sam.zoy.org/wtfpl/COPYING for more details.
28 "============================================================================
30 if exists("g:loaded_syntastic_vala_valac_checker")
31     finish
32 endif
33 let g:loaded_syntastic_vala_valac_checker = 1
35 let s:save_cpo = &cpo
36 set cpo&vim
38 function! SyntaxCheckers_vala_valac_GetHighlightRegex(pos)
39     let length = strlen(matchstr(a:pos['text'], '\m\^\+$'))
40     return '\%>' . (a:pos['col'] - 1) . 'c.*\%<' . (a:pos['col'] + length + 1) . 'c'
41 endfunction
43 function! s:GetValaModules()
44     if exists('g:syntastic_vala_modules')
45         if type(g:syntastic_vala_modules) == type('')
46             return split(g:syntastic_vala_modules, '\s\+')
47         elseif type(g:syntastic_vala_modules) == type([])
48             return copy(g:syntastic_vala_modules)
49         else
50             echoerr 'g:syntastic_vala_modules must be either list or string: fallback to in file modules string'
51         endif
52     endif
54     let modules_line = search('^// modules: ', 'n')
55     let modules_str = getline(modules_line)
56     return split(strpart(modules_str, 12), '\s\+')
57 endfunction
59 function! s:GetValaVapiDirs()
60     if exists('g:syntastic_vala_vapi_dirs')
61         if type(g:syntastic_vala_vapi_dirs) == type('')
62             return split(g:syntastic_vala_vapi_dirs, '\s\+')
63         elseif type(g:syntastic_vala_vapi_dirs) == type([])
64             return copy(g:syntastic_vala_vapi_dirs)
65         else
66             echoerr 'g:syntastic_vala_vapi_dirs must be either list or string: fallback to in file modules string'
67         endif
68     endif
70     let vapi_line = search('^//\s*vapidirs:\s*','n')
71     let vapi_str = getline(vapi_line)
72     return split( substitute( vapi_str, '^//\s*vapidirs:\s*', '', 'g' ), '\s\+' )
73 endfunction
75 function! SyntaxCheckers_vala_valac_GetLocList() dict
76     let vala_pkg_args = join(map(s:GetValaModules(), '"--pkg ".v:val'), ' ')
77     let vala_vapi_args = join(map(s:GetValaVapiDirs(), '"--vapidir ".v:val'), ' ')
78     let makeprg = self.makeprgBuild({ 'args': '-C ' . vala_pkg_args . " " . vala_vapi_args })
80     let errorformat =
81         \ '%A%f:%l.%c-%\d%\+.%\d%\+: %t%[a-z]%\+: %m,'.
82         \ '%C%m,'.
83         \ '%Z%m'
85     return SyntasticMake({
86         \ 'makeprg': makeprg,
87         \ 'errorformat': errorformat })
88 endfunction
90 call g:SyntasticRegistry.CreateAndRegisterChecker({
91     \ 'filetype': 'vala',
92     \ 'name': 'valac'})
94 let &cpo = s:save_cpo
95 unlet s:save_cpo
97 " vim: set et sts=4 sw=4: