raku.vim 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. "============================================================================
  2. "File: raku.vim
  3. "Description: Syntax checking plugin for syntastic
  4. "Maintainer: Claudio Ramirez <pub.claudio at gmail dot com>
  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. "
  13. " Security:
  14. "
  15. " This checker runs 'raku -c' against your file, which in turn executes
  16. " any BEGIN and CHECK blocks in your file. This is probably fine if you
  17. " wrote the file yourself, but it can be a problem if you're trying to
  18. " check third party files. If you are 100% willing to let Vim run the code
  19. " in your file, set g:syntastic_enable_raku_checker to 1 in your vimrc
  20. " to enable this
  21. " checker:
  22. "
  23. " let g:syntastic_enable_raku_checker = 1
  24. "
  25. " Reference:
  26. "
  27. " - https://docs.raku.org/programs/03-environment-variables
  28. if exists('g:loaded_syntastic_raku_raku_checker')
  29. finish
  30. endif
  31. let g:loaded_syntastic_raku_raku_checker = 1
  32. if !exists('g:syntastic_raku_lib_path')
  33. let g:syntastic_raku_lib_path = []
  34. endif
  35. if !exists('g:syntastic_raku_raku_sort')
  36. let g:syntastic_raku_raku_sort = 1
  37. endif
  38. let s:save_cpo = &cpo
  39. set cpo&vim
  40. function! SyntaxCheckers_raku_raku_IsAvailable() dict " {{{1
  41. " don't call executable() here, to allow things like
  42. " let g:syntastic_raku_raku_exec = '/usr/bin/env raku'
  43. silent! call syntastic#util#system(self.getExecEscaped() . ' -e ' . syntastic#util#shescape('exit(0)'))
  44. return (v:shell_error == 0) && syntastic#util#versionIsAtLeast(self.getVersion(), [2017, 1])
  45. endfunction " }}}1
  46. function! SyntaxCheckers_raku_raku_GetHighlightRegex(item) " {{{1
  47. let term = matchstr(a:item['text'], '\m''\zs.\{-}\ze''')
  48. if term !=# ''
  49. return '\V' . escape(term, '\')
  50. endif
  51. let term = matchstr(a:item['text'], '\m^Undeclared .\+:\W\zs\S\+\ze')
  52. if term !=# ''
  53. return '\V' . escape(term, '\')
  54. endif
  55. let term = matchstr(a:item['text'], '\mCould not find \zs.\{-}\ze at')
  56. if term !=# ''
  57. return '\V' . escape(term, '\')
  58. endif
  59. let term = matchstr(a:item['text'], '\mCould not find \zs\S\+$')
  60. return term !=# '' ? '\V' . escape(term, '\') : ''
  61. endfunction " }}}1
  62. function! SyntaxCheckers_raku_raku_GetLocList() dict " {{{1
  63. if type(g:syntastic_raku_lib_path) == type('')
  64. call syntastic#log#oneTimeWarn('variable g:syntastic_raku_lib_path should be a list')
  65. let includes = split(g:syntastic_raku_lib_path, ',')
  66. else
  67. let includes = copy(syntastic#util#var('raku_lib_path', []))
  68. endif
  69. " support for RAKULIB environment variable
  70. if $RAKULIB !=# ''
  71. let includes += split($RAKULIB, ':')
  72. endif
  73. call map(includes, '"-I" . v:val')
  74. let errorformat =
  75. \ '%f:%l:%c:%m,' .
  76. \ ':%l:%c:%m'
  77. let makeprg = self.makeprgBuild({ 'args_before': ['-c'] + includes })
  78. return SyntasticMake({
  79. \ 'makeprg': makeprg,
  80. \ 'errorformat': errorformat,
  81. \ 'env': { 'RAKU_EXCEPTIONS_HANDLER': 'JSON' },
  82. \ 'defaults': { 'bufnr': bufnr(''), 'type': 'E' },
  83. \ 'returns': [0, 1],
  84. \ 'preprocess': 'raku',
  85. \ 'postprocess': ['guards', 'iconv'] })
  86. endfunction " }}}1
  87. call g:SyntasticRegistry.CreateAndRegisterChecker({
  88. \ 'filetype': 'raku',
  89. \ 'name': 'raku',
  90. \ 'enable': 'enable_raku_checker'})
  91. let &cpo = s:save_cpo
  92. unlet s:save_cpo
  93. " vim: set sw=4 sts=4 et fdm=marker: