2012-06-02 10:00:37 -04:00
|
|
|
"============================================================================
|
|
|
|
"File: d.vim
|
|
|
|
"Description: Syntax checking plugin for syntastic.vim
|
|
|
|
"Maintainer: Alfredo Di Napoli <alfredo dot dinapoli at gmail dot com>
|
2012-06-02 10:11:59 -04:00
|
|
|
"License: Based on the original work of Gregor Uhlenheuer and his
|
|
|
|
" cpp.vim checker so credits are dued.
|
|
|
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
" OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
" HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
" WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
" OTHER DEALINGS IN THE SOFTWARE.
|
2012-06-02 10:00:37 -04:00
|
|
|
"
|
|
|
|
"============================================================================
|
|
|
|
|
2013-04-24 04:02:03 -04:00
|
|
|
if exists('g:loaded_syntastic_d_dmd_checker')
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_syntastic_d_dmd_checker = 1
|
|
|
|
|
2014-02-08 02:45:51 -05:00
|
|
|
if !exists('g:syntastic_d_compiler_options')
|
|
|
|
let g:syntastic_d_compiler_options = ''
|
2013-04-24 04:02:03 -04:00
|
|
|
endif
|
|
|
|
|
2016-04-10 12:54:40 -04:00
|
|
|
if !exists('g:syntastic_d_use_dub')
|
|
|
|
let g:syntastic_d_use_dub = 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:syntastic_d_dub_exec')
|
|
|
|
let g:syntastic_d_dub_exec = 'dub'
|
|
|
|
endif
|
|
|
|
|
2014-01-03 04:29:08 -05:00
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2016-04-10 12:54:40 -04:00
|
|
|
function! SyntaxCheckers_d_dmd_IsAvailable() dict " {{{1
|
2014-02-08 02:45:51 -05:00
|
|
|
if !exists('g:syntastic_d_compiler')
|
|
|
|
let g:syntastic_d_compiler = self.getExec()
|
|
|
|
endif
|
2014-10-06 15:15:44 -04:00
|
|
|
call self.log('g:syntastic_d_compiler =', g:syntastic_d_compiler)
|
2015-01-04 02:01:55 -05:00
|
|
|
return executable(expand(g:syntastic_d_compiler, 1))
|
2016-04-10 12:54:40 -04:00
|
|
|
endfunction " }}}1
|
2012-06-02 10:00:37 -04:00
|
|
|
|
2016-04-10 12:54:40 -04:00
|
|
|
function! SyntaxCheckers_d_dmd_GetLocList() dict " {{{1
|
2014-06-24 12:02:42 -04:00
|
|
|
if !exists('g:syntastic_d_include_dirs')
|
2016-04-10 12:54:40 -04:00
|
|
|
let g:syntastic_d_include_dirs = s:GetIncludes(self, expand('%:p:h'))
|
2014-06-24 12:02:42 -04:00
|
|
|
endif
|
|
|
|
|
2013-06-25 02:59:07 -04:00
|
|
|
return syntastic#c#GetLocList('d', 'dmd', {
|
2013-05-21 03:03:04 -04:00
|
|
|
\ 'errorformat':
|
|
|
|
\ '%-G%f:%s:,%f(%l): %m,' .
|
|
|
|
\ '%f:%l: %m',
|
2013-06-24 04:46:27 -04:00
|
|
|
\ 'main_flags': '-c -of' . syntastic#util#DevNull(),
|
2013-10-25 08:56:09 -04:00
|
|
|
\ 'header_names': '\m\.di$' })
|
2016-04-10 12:54:40 -04:00
|
|
|
endfunction " }}}1
|
|
|
|
|
|
|
|
" Utilities {{{1
|
|
|
|
|
|
|
|
function! s:GetIncludes(checker, base) " {{{2
|
|
|
|
let includes = []
|
|
|
|
|
|
|
|
if g:syntastic_d_use_dub && !exists('s:dub_ok')
|
|
|
|
let s:dub_ok = s:ValidateDub(a:checker)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if g:syntastic_d_use_dub && s:dub_ok
|
|
|
|
let where = escape(a:base, ' ') . ';'
|
|
|
|
|
|
|
|
let old_suffixesadd = &suffixesadd
|
|
|
|
let dirs = syntastic#util#unique(map(filter(
|
|
|
|
\ findfile('dub.json', where, -1) +
|
|
|
|
\ findfile('dub.sdl', where, -1) +
|
|
|
|
\ findfile('package.json', where, -1),
|
|
|
|
\ 'filereadable(v:val)'), 'fnamemodify(v:val, ":h")'))
|
|
|
|
let &suffixesadd = old_suffixesadd
|
|
|
|
call a:checker.log('using dub: looking for includes in', dirs)
|
|
|
|
|
|
|
|
for dir in dirs
|
|
|
|
try
|
|
|
|
execute 'silent lcd ' . fnameescape(dir)
|
|
|
|
let paths = split(syntastic#util#system(syntastic#util#shescape(g:syntastic_d_dub_exec) . ' describe --import-paths'), "\n")
|
|
|
|
silent lcd -
|
|
|
|
if v:shell_error == 0
|
|
|
|
call extend(includes, paths)
|
|
|
|
call a:checker.log('using dub: found includes', paths)
|
|
|
|
endif
|
|
|
|
catch /\m^Vim\%((\a\+)\)\=:E472/
|
|
|
|
" evil directory is evil
|
|
|
|
endtry
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
|
|
|
if empty(includes)
|
|
|
|
let includes = filter(glob($HOME . '/.dub/packages/*', 1, 1), 'isdirectory(v:val)')
|
|
|
|
call map(includes, 'isdirectory(v:val . "/source") ? v:val . "/source" : v:val')
|
|
|
|
call add(includes, './source')
|
|
|
|
endif
|
|
|
|
|
|
|
|
return syntastic#util#unique(includes)
|
|
|
|
endfunction " }}}2
|
|
|
|
|
|
|
|
function! s:ValidateDub(checker) " {{{2
|
|
|
|
let ok = 0
|
|
|
|
|
|
|
|
if executable(g:syntastic_d_dub_exec)
|
|
|
|
let command = syntastic#util#shescape(g:syntastic_d_dub_exec) . ' --version'
|
|
|
|
let version_output = syntastic#util#system(command)
|
|
|
|
call a:checker.log('getVersion: ' . string(command) . ': ' .
|
|
|
|
\ string(split(version_output, "\n", 1)) .
|
|
|
|
\ (v:shell_error ? ' (exit code ' . v:shell_error . ')' : '') )
|
|
|
|
let parsed_ver = syntastic#util#parseVersion(version_output)
|
|
|
|
call a:checker.log(g:syntastic_d_dub_exec . ' version =', parsed_ver)
|
|
|
|
if len(parsed_ver)
|
|
|
|
let ok = syntastic#util#versionIsAtLeast(parsed_ver, [0, 9, 24])
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ok
|
|
|
|
endfunction " }}}2
|
|
|
|
|
|
|
|
" }}}1
|
2012-06-02 10:00:37 -04:00
|
|
|
|
2013-01-27 15:08:30 -05:00
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'd',
|
2014-02-08 02:45:51 -05:00
|
|
|
\ 'name': 'dmd' })
|
2013-01-27 15:08:30 -05:00
|
|
|
|
2012-06-02 10:00:37 -04:00
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|