make a few refactors

Add CurrentFiletypes function as this logic was getting used in a couple
of places and needed a home/name - mostly because of the bizarre
substitute call that needs explanation.

Move the code to get a syntax checker by name into SyntasticRegistry
This commit is contained in:
Martin Grenfell 2013-02-01 14:38:53 +00:00
parent 0b3e074f8c
commit c97951b601
2 changed files with 26 additions and 17 deletions

View File

@ -109,8 +109,7 @@ let s:registry = g:SyntasticRegistry.Instance()
function! s:CompleteCheckerName(argLead, cmdLine, cursorPos) function! s:CompleteCheckerName(argLead, cmdLine, cursorPos)
let checker_names = [] let checker_names = []
let fts = substitute(&ft, '-', '_', 'g') for ft in s:CurrentFiletypes()
for ft in split(fts, '\.')
for checker in s:registry.availableCheckersFor(ft) for checker in s:registry.availableCheckersFor(ft)
if index(checker_names, checker.name()) == -1 if index(checker_names, checker.name()) == -1
call add(checker_names, checker.name()) call add(checker_names, checker.name())
@ -207,30 +206,30 @@ function! s:ClearCache()
unlet! b:syntastic_loclist unlet! b:syntastic_loclist
endfunction endfunction
function! s:CurrentFiletypes()
"sub - for _ in filetypes otherwise we cant name syntax checker
"functions legally for filetypes like "gentoo-metadata"
let fts = substitute(&ft, '-', '_', 'g')
return split(fts, '\.')
endfunction
"detect and cache all syntax errors in this buffer "detect and cache all syntax errors in this buffer
"
"depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing
"elsewhere
function! s:CacheErrors(...) function! s:CacheErrors(...)
call s:ClearCache() call s:ClearCache()
let newLoclist = g:SyntasticLoclist.New([]) let newLoclist = g:SyntasticLoclist.New([])
if filereadable(expand("%")) if filereadable(expand("%"))
for ft in s:CurrentFiletypes()
"sub - for _ in filetypes otherwise we cant name syntax checker if a:0
"functions legally for filetypes like "gentoo-metadata" let checker = s:registry.getChecker(ft, a:1)
let fts = substitute(&ft, '-', '_', 'g') if !empty(checker)
for ft in split(fts, '\.') let checkers = [checker]
if a:0 >= 1 endif
let checkers = []
for checker in s:registry.availableCheckersFor(ft)
if checker.name() == a:1
call add(checkers, checker)
endif
endfor
else else
let checkers = s:registry.getActiveCheckers(ft) let checkers = s:registry.getActiveCheckers(ft)
endif endif
for checker in checkers for checker in checkers
let loclist = checker.getLocList() let loclist = checker.getLocList()

View File

@ -69,13 +69,23 @@ function! g:SyntasticRegistry.getActiveCheckers(filetype)
return [] return []
endfunction endfunction
" Private methods {{{1 function! g:SyntasticRegistry.getChecker(filetype, name)
for checker in self.availableCheckersFor(a:filetype)
if checker.name() == a:name
return checker
endif
endfor
return {}
endfunction
function! g:SyntasticRegistry.availableCheckersFor(filetype) function! g:SyntasticRegistry.availableCheckersFor(filetype)
let checkers = copy(self._allCheckersFor(a:filetype)) let checkers = copy(self._allCheckersFor(a:filetype))
return self._filterCheckersByAvailability(checkers) return self._filterCheckersByAvailability(checkers)
endfunction endfunction
" Private methods {{{1
function! g:SyntasticRegistry._allCheckersFor(filetype) function! g:SyntasticRegistry._allCheckersFor(filetype)
call self._loadCheckers(a:filetype) call self._loadCheckers(a:filetype)
if empty(self._checkerMap[a:filetype]) if empty(self._checkerMap[a:filetype])