diff --git a/autoload/syntastic/util.vim b/autoload/syntastic/util.vim index 0a4d8cf1..85ec7c01 100644 --- a/autoload/syntastic/util.vim +++ b/autoload/syntastic/util.vim @@ -119,6 +119,28 @@ function! syntastic#util#bufIsActive(buffer) return 0 endfunction +" start in directory a:where and walk up the parent folders until it +" finds a file matching a:what; return path to that file +function! syntastic#util#findInParent(what, where) + let here = fnamemodify(a:where, ':p') + + while !empty(here) + let p = split(globpath(here, a:what), '\n') + + if !empty(p) + return fnamemodify(p[0], ':p') + elseif here == '/' + break + endif + + " we use ':h:h' rather than ':h' since ':p' adds a trailing '/' + " if 'here' is a directory + let here = fnamemodify(here, ':p:h:h') + endwhile + + return '' +endfunction + " Returns unique elements in a list function! syntastic#util#unique(list) let seen = {} diff --git a/syntax_checkers/haxe/haxe.vim b/syntax_checkers/haxe/haxe.vim index cffd5277..969a9369 100644 --- a/syntax_checkers/haxe/haxe.vim +++ b/syntax_checkers/haxe/haxe.vim @@ -19,35 +19,13 @@ function! SyntaxCheckers_haxe_haxe_IsAvailable() return executable('haxe') endfunction -" start in directory a:where and walk up the parent folders until it -" finds a file matching a:what; return path to that file -function! s:FindInParent(what, where) - let here = fnamemodify(a:where, ':p') - - while !empty(here) - let p = split(globpath(here, a:what), '\n') - - if !empty(p) - return fnamemodify(p[0], ':p') - elseif here == '/' - break - endif - - " we use ':h:h' rather than ':h' since ':p' adds a trailing '/' - " if 'here' is a directory - let here = fnamemodify(here, ':p:h:h') - endwhile - - return '' -endfunction - function! SyntaxCheckers_haxe_haxe_GetLocList() if exists('b:vaxe_hxml') let hxml = b:vaxe_hxml elseif exists('g:vaxe_hxml') let hxml = g:vaxe_hxml else - let hxml = s:FindInParent('*.hxml', expand('%:p:h')) + let hxml = syntastic#util#findInParent('*.hxml', expand('%:p:h')) endif let hxml = fnamemodify(hxml, ':p')