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)
let checker_names = []
let fts = substitute(&ft, '-', '_', 'g')
for ft in split(fts, '\.')
for ft in s:CurrentFiletypes()
for checker in s:registry.availableCheckersFor(ft)
if index(checker_names, checker.name()) == -1
call add(checker_names, checker.name())
@ -207,30 +206,30 @@ function! s:ClearCache()
unlet! b:syntastic_loclist
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
"
"depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing
"elsewhere
function! s:CacheErrors(...)
call s:ClearCache()
let newLoclist = g:SyntasticLoclist.New([])
if filereadable(expand("%"))
for ft in s:CurrentFiletypes()
"sub - for _ in filetypes otherwise we cant name syntax checker
"functions legally for filetypes like "gentoo-metadata"
let fts = substitute(&ft, '-', '_', 'g')
for ft in split(fts, '\.')
if a:0 >= 1
let checkers = []
for checker in s:registry.availableCheckersFor(ft)
if checker.name() == a:1
call add(checkers, checker)
if a:0
let checker = s:registry.getChecker(ft, a:1)
if !empty(checker)
let checkers = [checker]
endif
endfor
else
let checkers = s:registry.getActiveCheckers(ft)
endif
for checker in checkers
let loclist = checker.getLocList()

View File

@ -69,13 +69,23 @@ function! g:SyntasticRegistry.getActiveCheckers(filetype)
return []
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)
let checkers = copy(self._allCheckersFor(a:filetype))
return self._filterCheckersByAvailability(checkers)
endfunction
" Private methods {{{1
function! g:SyntasticRegistry._allCheckersFor(filetype)
call self._loadCheckers(a:filetype)
if empty(self._checkerMap[a:filetype])