valac.vim 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "============================================================================
  2. "File: vala.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Konstantin Stepanov (me@kstep.me)
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. "============================================================================
  12. if exists('g:loaded_syntastic_vala_valac_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_vala_valac_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. function! SyntaxCheckers_vala_valac_GetHighlightRegex(pos) " {{{1
  19. let length = strlen(matchstr(a:pos['text'], '\m\^\+$'))
  20. return '\%>' . (a:pos['col'] - 1) . 'c\%<' . (a:pos['col'] + length) . 'c'
  21. endfunction " }}}1
  22. function! SyntaxCheckers_vala_valac_GetLocList() dict " {{{1
  23. let vala_pkg_args = join(map(s:GetValaModules(), '"--pkg ".v:val'), ' ')
  24. let vala_vapi_args = join(map(s:GetValaVapiDirs(), '"--vapidir ".v:val'), ' ')
  25. let makeprg = self.makeprgBuild({ 'args': '-C ' . vala_pkg_args . ' ' . vala_vapi_args })
  26. let errorformat =
  27. \ '%A%f:%l.%c-%\d%\+.%\d%\+: %t%[a-z]%\+: %m,'.
  28. \ '%C%m,'.
  29. \ '%Z%m'
  30. return SyntasticMake({
  31. \ 'makeprg': makeprg,
  32. \ 'errorformat': errorformat })
  33. endfunction " }}}1
  34. " Utilities {{{1
  35. function! s:GetValaModules() " {{{2
  36. if exists('g:syntastic_vala_modules') || exists('b:syntastic_vala_modules')
  37. let modules = syntastic#util#var('vala_modules')
  38. if type(modules) == type('')
  39. return split(modules, '\m\s\+')
  40. elseif type(modules) == type([])
  41. return copy(modules)
  42. else
  43. echoerr 'syntastic_vala_modules must be either list or string: fallback to in file modules string'
  44. endif
  45. endif
  46. let modules_line = search('^// modules: ', 'n')
  47. let modules_str = getline(modules_line)
  48. return split(strpart(modules_str, 12), '\m\s\+')
  49. endfunction " }}}2
  50. function! s:GetValaVapiDirs() " {{{2
  51. if exists('g:syntastic_vala_vapi_dirs') || exists('b:syntastic_vala_vapi_dirs')
  52. let vapi_dirs = syntastic#util#var('vala_vapi_dirs')
  53. if type(vapi_dirs) == type('')
  54. return split(vapi_dirs, '\m\s\+')
  55. elseif type(vapi_dirs) == type([])
  56. return copy(vapi_dirs)
  57. else
  58. echoerr 'syntastic_vala_vapi_dirs must be either a list, or a string: fallback to in-file modules string'
  59. endif
  60. endif
  61. let vapi_line = search('^//\s*vapidirs:\s*','n')
  62. let vapi_str = getline(vapi_line)
  63. return split( substitute( vapi_str, '\m^//\s*vapidirs:\s*', '', 'g' ), '\m\s\+' )
  64. endfunction " }}}2
  65. " }}}1
  66. call g:SyntasticRegistry.CreateAndRegisterChecker({
  67. \ 'filetype': 'vala',
  68. \ 'name': 'valac'})
  69. let &cpo = s:save_cpo
  70. unlet s:save_cpo
  71. " vim: set sw=4 sts=4 et fdm=marker: