@@ -24,22 +24,28 @@ if !exists('g:syntastic_d_compiler_options')
24
24
let g: syntastic_d_compiler_options = ' '
25
25
endif
26
26
27
+ if ! exists (' g:syntastic_d_use_dub' )
28
+ let g: syntastic_d_use_dub = 1
29
+ endif
30
+
31
+ if ! exists (' g:syntastic_d_dub_exec' )
32
+ let g: syntastic_d_dub_exec = ' dub'
33
+ endif
34
+
27
35
let s: save_cpo = &cpo
28
36
set cpo &vim
29
37
30
- function ! SyntaxCheckers_d_dmd_IsAvailable () dict
38
+ function ! SyntaxCheckers_d_dmd_IsAvailable () dict " {{{1
31
39
if ! exists (' g:syntastic_d_compiler' )
32
40
let g: syntastic_d_compiler = self .getExec ()
33
41
endif
34
42
call self .log (' g:syntastic_d_compiler =' , g: syntastic_d_compiler )
35
43
return executable (expand (g: syntastic_d_compiler , 1 ))
36
- endfunction
44
+ endfunction " }}}1
37
45
38
- function ! SyntaxCheckers_d_dmd_GetLocList () dict
46
+ function ! SyntaxCheckers_d_dmd_GetLocList () dict " {{{1
39
47
if ! exists (' g:syntastic_d_include_dirs' )
40
- let g: syntastic_d_include_dirs = filter (glob ($HOME . ' /.dub/packages/*' , 1 , 1 ), ' isdirectory(v:val)' )
41
- call map (g: syntastic_d_include_dirs , ' isdirectory(v:val . "/source") ? v:val . "/source" : v:val' )
42
- call add (g: syntastic_d_include_dirs , ' ./source' )
48
+ let g: syntastic_d_include_dirs = s: GetIncludes (self , expand (' %:p:h' ))
43
49
endif
44
50
45
51
return syntastic#c#GetLocList (' d' , ' dmd' , {
@@ -48,7 +54,73 @@ function! SyntaxCheckers_d_dmd_GetLocList() dict
48
54
\ ' %f:%l: %m' ,
49
55
\ ' main_flags' : ' -c -of' . syntastic#util#DevNull (),
50
56
\ ' header_names' : ' \m\.di$' })
51
- endfunction
57
+ endfunction " }}}1
58
+
59
+ " Utilities {{{1
60
+
61
+ function ! s: GetIncludes (checker, base) " {{{2
62
+ let includes = []
63
+
64
+ if g: syntastic_d_use_dub && ! exists (' s:dub_ok' )
65
+ let s: dub_ok = s: ValidateDub (a: checker )
66
+ endif
67
+
68
+ if g: syntastic_d_use_dub && s: dub_ok
69
+ let where = escape (a: base , ' ' ) . ' ;'
70
+
71
+ let old_suffixesadd = &suffixesadd
72
+ let dirs = syntastic#util#unique (map (filter (
73
+ \ findfile (' dub.json' , where, -1 ) +
74
+ \ findfile (' dub.sdl' , where, -1 ) +
75
+ \ findfile (' package.json' , where, -1 ),
76
+ \ ' filereadable(v:val)' ), ' fnamemodify(v:val, ":h")' ))
77
+ let &suffixesadd = old_suffixesadd
78
+ call a: checker .log (' using dub: looking for includes in' , dirs)
79
+
80
+ for dir in dirs
81
+ try
82
+ execute ' silent lcd ' . fnameescape (dir )
83
+ let paths = split (syntastic#util#system (syntastic#util#shescape (g: syntastic_d_dub_exec ) . ' describe --import-paths' ), " \n " )
84
+ silent lcd -
85
+ if v: shell_error == 0
86
+ call extend (includes, paths)
87
+ call a: checker .log (' using dub: found includes' , paths)
88
+ endif
89
+ catch /\m^Vim\%((\a\+)\)\=:E472/
90
+ " evil directory is evil
91
+ endtry
92
+ endfor
93
+ endif
94
+
95
+ if empty (includes)
96
+ let includes = filter (glob ($HOME . ' /.dub/packages/*' , 1 , 1 ), ' isdirectory(v:val)' )
97
+ call map (includes, ' isdirectory(v:val . "/source") ? v:val . "/source" : v:val' )
98
+ call add (includes, ' ./source' )
99
+ endif
100
+
101
+ return syntastic#util#unique (includes)
102
+ endfunction " }}}2
103
+
104
+ function ! s: ValidateDub (checker) " {{{2
105
+ let ok = 0
106
+
107
+ if executable (g: syntastic_d_dub_exec )
108
+ let command = syntastic#util#shescape (g: syntastic_d_dub_exec ) . ' --version'
109
+ let version_output = syntastic#util#system (command )
110
+ call a: checker .log (' getVersion: ' . string (command ) . ' : ' .
111
+ \ string (split (version_output, " \n " , 1 )) .
112
+ \ (v: shell_error ? ' (exit code ' . v: shell_error . ' )' : ' ' ) )
113
+ let parsed_ver = syntastic#util#parseVersion (version_output)
114
+ call a: checker .log (g: syntastic_d_dub_exec . ' version =' , parsed_ver)
115
+ if len (parsed_ver)
116
+ let ok = syntastic#util#versionIsAtLeast (parsed_ver, [0 , 9 , 24 ])
117
+ endif
118
+ endif
119
+
120
+ return ok
121
+ endfunction " }}}2
122
+
123
+ " }}}1
52
124
53
125
call g: SyntasticRegistry .CreateAndRegisterChecker ({
54
126
\ ' filetype' : ' d' ,
0 commit comments