vim: rename `nitg` checker to `nitpick`
[nit.git] / misc / vim / syntax_checkers / nit / nitpick.vim
1 "============================================================================
2 "File:        nitpick.vim
3 "Description: Syntax checking plugin for syntastic.vim
4 "Maintainer:  Alexis Laferrière <alexis.laf@xymus.net>
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 "       g:syntastic_nitpick specifies custom path to `nitpick` tool
12 "       g:syntastic_nit_dir specifies the NIT_DIR env variable
13 "       g:syntastic_nit_args specifies extra arguments to call `nitpick`
14 "       g:syntastic_nit_include_dirs lists directories to include, must be a list
15 "       g:nit_main sets the main module to compile instead of the opened file
16 "============================================================================
17 if exists("loaded_syntastic_nit_nitpick_checker")
18         finish
19 endif
20 let loaded_syntastic_nit_nitpick_checker = 1
21
22 " check if nitpick is accessible
23 if exists('g:syntastic_nitpick')
24         let s:nitpick = g:syntastic_nitpick
25 else
26         let s:nitpick = "nitpick"
27 endif
28
29 if !executable(s:nitpick)
30         if exists('g:syntastic_nitpick')
31                 echo "Syntastic for Nit error: Custom tool cannot be found at: " . g:syntastic_nitpick
32         endif
33         finish
34 endif
35
36 function! SyntaxCheckers_nit_nitpick_IsAvailable()
37     return executable(expand(s:nitpick))
38 endfunction
39
40 function! SyntaxCheckers_nit_nitpick_GetLocList()
41         let makeprg = s:nitpick . " --no-color -W --vim-autocomplete "
42
43         " custom NIT_DIR
44         if exists('g:syntastic_nit_dir')
45                 let makeprg = "NIT_DIR=" . g:syntastic_nit_dir . " " . makeprg
46         endif
47
48         " custom options for nit compiler
49         if exists('g:syntastic_nit_options')
50                 let makeprg .= " " . g:syntastic_nit_options
51         endif
52
53         " custom dirs to include for compiler
54         if exists('g:syntastic_nit_include_dirs')
55                 for d in g:syntastic_nit_include_dirs
56                         let makeprg .= " -I " . d
57                 endfor
58         end
59
60         " alternative main module
61         if exists('g:nit_main')
62                 let makeprg .= " " . g:nit_main
63         else
64                 let makeprg .= " " . shellescape(expand("%"))
65         end
66
67         " pipe stderr
68         let makeprg .= " 2>&1 "
69
70         " possible combinations of error messages
71         let ef_start = [ '%f:%l\,%c--%*[0-9]:',
72                                    \ '%f:%l\,%c--%*[0-9]\,%*[0-9]:',
73                                    \ '%f:%l\,%c:' ]
74         let ef_type = [ ' %tarning: ',
75                                   \ ' %tocumentation warning: ',
76                                   \ '' ]
77
78         " generate errorformat from combinations
79         let errorformat = ""
80         for s in ef_start
81                 for t in ef_type
82                         let errorformat .= s . t . '%m,'
83                 endfor
84         endfor
85
86         let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'postprocess': ['guards'] })
87
88         for e in loclist
89                 if e['type'] ==? 'd' " is a documentation warning
90                         let e['type'] = 'w'
91                         let e['subtype'] = 'Style'
92                 endif
93         endfor
94
95         return loclist
96 endfunction
97
98 call g:SyntasticRegistry.CreateAndRegisterChecker({
99     \ 'filetype': 'nit',
100     \ 'name': 'nitpick'})