58ba8d3161
Add 2 classes: SyntasticChecker and SyntasticRegistry. SyntasticChecker represents a checker. It holds funcrefs to the checker func, the highlight regex func and a new `isAvailable()` func (that essentially just checks if the checker exe is installed) SyntasticRegistry is responsible for: * loading checkers * storing checkers * fetching the checkers to use according to availability and the users settings Motivation/benefits: * in the current system only one checker can be loaded per filetype * syntax checkers cant be "chained" together * the system is hard to add features to since fundamental concepts like syntax checkers and location lists arent represented explicitly Things left to do: * add a call to g:SyntasticRegistry.CreateAndRegisterChecker() to all checkers * add an `isAvailable` function to all checkers * move all checkers into `syntax_checkers/filetype/checkername.vim` - g:SyntasticRegistry assumes this layout, and its a good idea anyway for consistency and it makes it easier for users to add their own checkers Things to do after all of the above: * add a LocationList class and move all the filtering functions onto it * possibly add an Error class that wraps up each item in a loc list Random notes: * with the new system you can select the checkers to use with e.g. `let g:syntastic_python_checkers=['flake8', 'pylint']` This will try flake8 first, and if no errors are detected it will move onto pylint.
37 lines
1.3 KiB
VimL
37 lines
1.3 KiB
VimL
"============================================================================
|
|
"File: python.vim
|
|
"Description: Syntax checking plugin for syntastic.vim
|
|
"Author: Artem Nezvigin <artem at artnez dot com>
|
|
"
|
|
" `errorformat` derived from:
|
|
" http://www.vim.org/scripts/download_script.php?src_id=1392
|
|
"
|
|
"============================================================================
|
|
function! SyntaxCheckers_python_pyflakes_IsAvailable()
|
|
return executable('python')
|
|
endfunction
|
|
|
|
function! SyntaxCheckers_python_pyflakes_GetLocList()
|
|
let l:path = shellescape(expand('%'))
|
|
let l:cmd = "compile(open(" . l:path . ").read(), " . l:path . ", 'exec')"
|
|
let l:makeprg = 'python -c "' . l:cmd . '"'
|
|
|
|
let l:errorformat =
|
|
\ "\%A\ \ File\ \"%f\"\\\,\ line\ %l\\\,%m," .
|
|
\ "\%C\ \ \ \ %.%#," .
|
|
\ "\%+Z%.%#Error\:\ %.%#," .
|
|
\ "\%A\ \ File\ \"%f\"\\\,\ line\ %l," .
|
|
\ "\%+C\ \ %.%#," .
|
|
\ "\%-C%p^," .
|
|
\ "\%Z%m," .
|
|
\ "\%-G%.%#"
|
|
|
|
return SyntasticMake({ 'makeprg': l:makeprg, 'errorformat': l:errorformat })
|
|
endfunction
|
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
\ 'loclistFunc': function('SyntaxCheckers_python_pyflakes_GetLocList'),
|
|
\ 'filetype': 'python',
|
|
\ 'name': 'python',
|
|
\ 'isAvailableFunc': function('SyntaxCheckers_python_pyflakes_IsAvailable')} )
|