Registry: cleaner handling of checker redirections.

Redirected checkers no longer need to add
"syntax_checkers/<filetype>/*.vim" to &runtimepath.
Parameters "exec" and "enable" to CreateAndRegisterChecker() are now
inherited from the source checker, but can be overridden in the target
if needed.
This commit is contained in:
LCD 47 2015-12-05 01:54:40 +02:00
parent 4725c8616c
commit e60555de70
22 changed files with 35 additions and 50 deletions

View File

@ -19,7 +19,7 @@ if has('reltime')
lockvar! g:_SYNTASTIC_START lockvar! g:_SYNTASTIC_START
endif endif
let g:_SYNTASTIC_VERSION = '3.7.0-53' let g:_SYNTASTIC_VERSION = '3.7.0-54'
lockvar g:_SYNTASTIC_VERSION lockvar g:_SYNTASTIC_VERSION
" Sanity checks {{{1 " Sanity checks {{{1

View File

@ -7,26 +7,36 @@ let g:SyntasticChecker = {}
" Public methods {{{1 " Public methods {{{1
function! g:SyntasticChecker.New(args) abort " {{{2 function! g:SyntasticChecker.New(args, ...) abort " {{{2
let newObj = copy(self) let newObj = copy(self)
let newObj._filetype = a:args['filetype'] let newObj._filetype = a:args['filetype']
let newObj._name = a:args['name'] let newObj._name = a:args['name']
let newObj._exec = get(a:args, 'exec', newObj._name)
if has_key(a:args, 'redirect') if a:0
let [filetype, name] = split(a:args['redirect'], '/') " redirected checker
let newObj._exec = get(a:args, 'exec', a:1['_exec'])
let filetype = a:1['_filetype']
let name = a:1['_name']
let prefix = 'SyntaxCheckers_' . filetype . '_' . name . '_' let prefix = 'SyntaxCheckers_' . filetype . '_' . name . '_'
if exists('g:syntastic_' . filetype . '_' . name . '_sort') && !exists('g:syntastic_' . newObj._filetype . '_' . newObj._name . '_sort') if exists('g:syntastic_' . filetype . '_' . name . '_sort') && !exists('g:syntastic_' . newObj._filetype . '_' . newObj._name . '_sort')
let g:syntastic_{newObj._filetype}_{newObj._name}_sort = g:syntastic_{filetype}_{name}_sort let g:syntastic_{newObj._filetype}_{newObj._name}_sort = g:syntastic_{filetype}_{name}_sort
endif endif
else
let prefix = 'SyntaxCheckers_' . newObj._filetype . '_' . newObj._name . '_'
endif
if has_key(a:args, 'enable') if has_key(a:args, 'enable')
let newObj._enable = a:args['enable'] let newObj._enable = a:args['enable']
elseif has_key(a:1, '_enable')
let newObj._enable = a:1['_enable']
endif
else
let newObj._exec = get(a:args, 'exec', newObj._name)
let prefix = 'SyntaxCheckers_' . newObj._filetype . '_' . newObj._name . '_'
if has_key(a:args, 'enable')
let newObj._enable = a:args['enable']
endif
endif endif
let newObj._locListFunc = function(prefix . 'GetLocList') let newObj._locListFunc = function(prefix . 'GetLocList')

View File

@ -159,8 +159,21 @@ function! g:SyntasticRegistry.Instance() abort " {{{2
endfunction " }}}2 endfunction " }}}2
function! g:SyntasticRegistry.CreateAndRegisterChecker(args) abort " {{{2 function! g:SyntasticRegistry.CreateAndRegisterChecker(args) abort " {{{2
let checker = g:SyntasticChecker.New(a:args)
let registry = g:SyntasticRegistry.Instance() let registry = g:SyntasticRegistry.Instance()
if has_key(a:args, 'redirect')
let [ft, name] = split(a:args['redirect'], '/')
call registry._loadCheckersFor(ft)
let clone = get(registry._checkerMap[ft], name, {})
if empty(clone)
throw 'Syntastic: Checker ' . a:args['redirect'] . ' redirects to unregistered checker ' . ft . '/' . name
endif
let checker = g:SyntasticChecker.New(a:args, clone)
else
let checker = g:SyntasticChecker.New(a:args)
endif
call registry._registerChecker(checker) call registry._registerChecker(checker)
endfunction " }}}2 endfunction " }}}2
@ -195,7 +208,7 @@ function! g:SyntasticRegistry.getCheckersAvailable(ftalias, hints_list) abort "
return filter(self.getCheckers(a:ftalias, a:hints_list), 'v:val.isAvailable()') return filter(self.getCheckers(a:ftalias, a:hints_list), 'v:val.isAvailable()')
endfunction " }}}2 endfunction " }}}2
" Same as getCheckers(), but keep only the checkers tyhat are available and " Same as getCheckers(), but keep only the checkers that are available and
" disabled. This runs the corresponding IsAvailable() functions for all checkers. " disabled. This runs the corresponding IsAvailable() functions for all checkers.
function! g:SyntasticRegistry.getCheckersDisabled(ftalias, hints_list) abort " {{{2 function! g:SyntasticRegistry.getCheckersDisabled(ftalias, hints_list) abort " {{{2
return filter(self.getCheckers(a:ftalias, a:hints_list), 'v:val.isDisabled() && v:val.isAvailable()') return filter(self.getCheckers(a:ftalias, a:hints_list), 'v:val.isDisabled() && v:val.isAvailable()')

View File

@ -14,8 +14,6 @@ if exists('g:loaded_syntastic_cpp_clang_check_checker')
endif endif
let g:loaded_syntastic_cpp_clang_check_checker = 1 let g:loaded_syntastic_cpp_clang_check_checker = 1
runtime! syntax_checkers/c/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'cpp', \ 'filetype': 'cpp',
\ 'name': 'clang_check', \ 'name': 'clang_check',

View File

@ -14,8 +14,6 @@ if exists('g:loaded_syntastic_cpp_clang_tidy_checker')
endif endif
let g:loaded_syntastic_cpp_clang_tidy_checker = 1 let g:loaded_syntastic_cpp_clang_tidy_checker = 1
runtime! syntax_checkers/c/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'cpp', \ 'filetype': 'cpp',
\ 'name': 'clang_tidy', \ 'name': 'clang_tidy',

View File

@ -14,8 +14,6 @@ if exists('g:loaded_syntastic_cpp_cppcheck_checker')
endif endif
let g:loaded_syntastic_cpp_cppcheck_checker = 1 let g:loaded_syntastic_cpp_cppcheck_checker = 1
runtime! syntax_checkers/c/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'cpp', \ 'filetype': 'cpp',
\ 'name': 'cppcheck', \ 'name': 'cppcheck',

View File

@ -14,8 +14,6 @@ if exists('g:loaded_syntastic_cpp_oclint_checker')
endif endif
let g:loaded_syntastic_cpp_oclint_checker = 1 let g:loaded_syntastic_cpp_oclint_checker = 1
runtime! syntax_checkers/c/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'cpp', \ 'filetype': 'cpp',
\ 'name': 'oclint', \ 'name': 'oclint',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_cpp_pc_lint_checker')
endif endif
let g:loaded_syntastic_cpp_pc_lint_checker = 1 let g:loaded_syntastic_cpp_pc_lint_checker = 1
runtime! syntax_checkers/c/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'cpp', \ 'filetype': 'cpp',
\ 'name': 'pc_lint', \ 'name': 'pc_lint',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_css_phpcs_checker')
endif endif
let g:loaded_syntastic_css_phpcs_checker = 1 let g:loaded_syntastic_css_phpcs_checker = 1
runtime! syntax_checkers/php/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'css', \ 'filetype': 'css',
\ 'name': 'phpcs', \ 'name': 'phpcs',

View File

@ -16,8 +16,6 @@ if exists('g:loaded_syntastic_css_recess_checker')
endif endif
let g:loaded_syntastic_css_recess_checker = 1 let g:loaded_syntastic_css_recess_checker = 1
runtime! syntax_checkers/less/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'css', \ 'filetype': 'css',
\ 'name': 'recess', \ 'name': 'recess',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_docbk_xmllint_checker')
endif endif
let g:loaded_syntastic_docbk_xmllint_checker = 1 let g:loaded_syntastic_docbk_xmllint_checker = 1
runtime! syntax_checkers/xml/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'docbk', \ 'filetype': 'docbk',
\ 'name': 'xmllint', \ 'name': 'xmllint',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_nroff_igor_checker')
endif endif
let g:loaded_syntastic_nroff_igor_checker = 1 let g:loaded_syntastic_nroff_igor_checker = 1
runtime! syntax_checkers/docbk/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'nroff', \ 'filetype': 'nroff',
\ 'name': 'igor', \ 'name': 'igor',

View File

@ -14,8 +14,6 @@ if exists('g:loaded_syntastic_objc_oclint_checker')
endif endif
let g:loaded_syntastic_objc_oclint_checker = 1 let g:loaded_syntastic_objc_oclint_checker = 1
runtime! syntax_checkers/c/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'objc', \ 'filetype': 'objc',
\ 'name': 'oclint', \ 'name': 'oclint',

View File

@ -14,8 +14,6 @@ if exists('g:loaded_syntastic_objcpp_oclint_checker')
endif endif
let g:loaded_syntastic_objcpp_oclint_checker = 1 let g:loaded_syntastic_objcpp_oclint_checker = 1
runtime! syntax_checkers/c/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'objcpp', \ 'filetype': 'objcpp',
\ 'name': 'oclint', \ 'name': 'oclint',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_perl_podchecker_checker')
endif endif
let g:loaded_syntastic_perl_podchecker_checker = 1 let g:loaded_syntastic_perl_podchecker_checker = 1
runtime! syntax_checkers/pod/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'perl', \ 'filetype': 'perl',
\ 'name': 'podchecker', \ 'name': 'podchecker',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_rmd_lintr_checker')
endif endif
let g:loaded_syntastic_rmd_lintr_checker = 1 let g:loaded_syntastic_rmd_lintr_checker = 1
runtime! syntax_checkers/r/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'rmd', \ 'filetype': 'rmd',
\ 'name': 'lintr', \ 'name': 'lintr',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_scss_sass_checker')
endif endif
let g:loaded_syntastic_scss_sass_checker = 1 let g:loaded_syntastic_scss_sass_checker = 1
runtime! syntax_checkers/sass/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'scss', \ 'filetype': 'scss',
\ 'name': 'sass', \ 'name': 'sass',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_scss_sassc_checker')
endif endif
let g:loaded_syntastic_scss_sassc_checker = 1 let g:loaded_syntastic_scss_sassc_checker = 1
runtime! syntax_checkers/sass/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'scss', \ 'filetype': 'scss',
\ 'name': 'sassc', \ 'name': 'sassc',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_text_igor_checker')
endif endif
let g:loaded_syntastic_text_igor_checker = 1 let g:loaded_syntastic_text_igor_checker = 1
runtime! syntax_checkers/docbk/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'text', \ 'filetype': 'text',
\ 'name': 'igor', \ 'name': 'igor',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_typescript_eslint_checker')
endif endif
let g:loaded_syntastic_typescript_eslint_checker = 1 let g:loaded_syntastic_typescript_eslint_checker = 1
runtime! syntax_checkers/javascript/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'typescript', \ 'filetype': 'typescript',
\ 'name': 'eslint', \ 'name': 'eslint',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_xhtml_jshint_checker')
endif endif
let g:loaded_syntastic_xhtml_jshint_checker = 1 let g:loaded_syntastic_xhtml_jshint_checker = 1
runtime! syntax_checkers/html/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'xhtml', \ 'filetype': 'xhtml',
\ 'name': 'jshint', \ 'name': 'jshint',

View File

@ -15,8 +15,6 @@ if exists('g:loaded_syntastic_xslt_xmllint_checker')
endif endif
let g:loaded_syntastic_xslt_xmllint_checker = 1 let g:loaded_syntastic_xslt_xmllint_checker = 1
runtime! syntax_checkers/xml/*.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'xslt', \ 'filetype': 'xslt',
\ 'name': 'xmllint', \ 'name': 'xmllint',