DRY up the code that loads checkers when multiple exist
Javascript and json have multiple syntax checkers that can be loaded. Previously the logic to determine which checker to load was basically copied and pasted in both. The `go` checker will soon have more than one option too so remove the duplication by sticking the common code in the core.
This commit is contained in:
parent
111b012548
commit
fa1084cf8f
@ -413,6 +413,12 @@ function! s:EchoCurrentError()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"load the chosen checker for the current filetype - useful for filetypes like
|
||||
"javascript that have more than one syntax checker
|
||||
function! s:LoadChecker(checker)
|
||||
exec "runtime syntax_checkers/" . &ft . "/" . a:checker . ".vim"
|
||||
endfunction
|
||||
|
||||
"return a string representing the state of buffer according to
|
||||
"g:syntastic_stl_format
|
||||
"
|
||||
@ -559,4 +565,33 @@ function! SyntasticAddToErrors(errors, options)
|
||||
return a:errors
|
||||
endfunction
|
||||
|
||||
"take a list of syntax checkers for the current filetype and load the right
|
||||
"one based on the global settings and checker executable availabity
|
||||
"
|
||||
"a:checkers should be a list of syntax checker names. These names are assumed
|
||||
"to be the names of the vim syntax checker files that should be sourced, as
|
||||
"well as the names of the actual syntax checker executables. The checkers
|
||||
"should be listed in order of default preference.
|
||||
"
|
||||
"if a option called 'g:syntastic_[filetype]_checker' exists then attempt to
|
||||
"load the checker that it points to
|
||||
function! SyntasticLoadChecker(checkers)
|
||||
let opt_name = "g:syntastic_" . &ft . "_checker"
|
||||
|
||||
if exists(opt_name)
|
||||
let opt_val = {opt_name}
|
||||
if index(a:checkers, opt_val) != -1 && executable(opt_val)
|
||||
call s:LoadChecker(opt_val)
|
||||
else
|
||||
echoerr &ft . " syntax not supported or not installed."
|
||||
endif
|
||||
else
|
||||
for checker in a:checkers
|
||||
if executable(checker)
|
||||
return s:LoadChecker(checker)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" vim: set et sts=4 sw=4:
|
||||
|
@ -20,22 +20,4 @@ endif
|
||||
let loaded_javascript_syntax_checker = 1
|
||||
|
||||
let s:supported_checkers = ["gjslint", "jslint", "jsl", "jshint"]
|
||||
|
||||
function! s:load_checker(checker)
|
||||
exec "runtime syntax_checkers/javascript/" . a:checker . ".vim"
|
||||
endfunction
|
||||
|
||||
if exists("g:syntastic_javascript_checker")
|
||||
if index(s:supported_checkers, g:syntastic_javascript_checker) != -1 && executable(g:syntastic_javascript_checker)
|
||||
call s:load_checker(g:syntastic_javascript_checker)
|
||||
else
|
||||
echoerr "Javascript syntax not supported or not installed."
|
||||
endif
|
||||
else
|
||||
for checker in s:supported_checkers
|
||||
if executable(checker)
|
||||
call s:load_checker(checker)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
call SyntasticLoadChecker(s:supported_checkers)
|
||||
|
@ -20,22 +20,4 @@ endif
|
||||
let loaded_json_syntax_checker = 1
|
||||
|
||||
let s:supported_checkers = ["jsonlint", "jsonval"]
|
||||
|
||||
function! s:load_checker(checker)
|
||||
exec "runtime syntax_checkers/json/" . a:checker . ".vim"
|
||||
endfunction
|
||||
|
||||
if exists("g:syntastic_json_checker")
|
||||
if index(s:supported_checkers, g:syntastic_json_checker) != -1 && executable(g:syntastic_json_checker)
|
||||
call s:load_checker(g:syntastic_json_checker)
|
||||
else
|
||||
echoerr "JSON syntax not supported or not installed."
|
||||
endif
|
||||
else
|
||||
for checker in s:supported_checkers
|
||||
if executable(checker)
|
||||
call s:load_checker(checker)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
call SyntasticLoadChecker(s:supported_checkers)
|
||||
|
Loading…
Reference in New Issue
Block a user