2019-11-16 11:14:34 -05:00
|
|
|
" Vim syntastic plugin
|
|
|
|
" Language: Rust
|
|
|
|
" Maintainer: Julien Levesy <jlevesy@gmail.com>
|
|
|
|
"
|
|
|
|
" See for details on how to add an external Syntastic checker:
|
|
|
|
" https://github.com/scrooloose/syntastic/wiki/Syntax-Checker-Guide#external
|
|
|
|
|
|
|
|
if exists("g:loaded_syntastic_rust_cargo_checker")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
let g:loaded_syntastic_rust_cargo_checker = 1
|
|
|
|
|
|
|
|
" Force syntastic to call cargo without a specific file name
|
|
|
|
let g:syntastic_rust_cargo_fname = ""
|
|
|
|
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
function! SyntaxCheckers_rust_cargo_IsAvailable() dict
|
2019-11-16 12:43:18 -05:00
|
|
|
if exists("*syntastic#util#getVersion")
|
|
|
|
echom "rust.vim: version of Syntastic is too old. Needs to be at least 3.7.0."
|
|
|
|
return v:false
|
|
|
|
endif
|
|
|
|
|
|
|
|
return executable(self.getExec()) &&
|
|
|
|
\ syntastic#util#versionIsAtLeast(self.getVersion(), [0, 16, 0])
|
2019-11-16 11:14:34 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! SyntaxCheckers_rust_cargo_GetLocList() dict
|
|
|
|
let makeprg = self.makeprgBuild({ "args": "check" })
|
2019-11-16 12:43:18 -05:00
|
|
|
let l:root_cargo_toml = cargo#nearestRootCargo(0)
|
|
|
|
let l:nearest_cargo_toml = cargo#nearestCargo(0)
|
|
|
|
let b:rust_recent_root_cargo_toml = l:root_cargo_toml
|
|
|
|
let b:rust_recent_nearest_cargo_toml = l:nearest_cargo_toml
|
|
|
|
|
|
|
|
" All pathname prints are relative to the Cargo.toml of the workspace, if
|
|
|
|
" there is a workspace, otherwise they are relative to the Cargo.toml of
|
|
|
|
" the single crate. Where to actually execute under these varying
|
|
|
|
" circumtances 'cargo' is determined here, and controlled by
|
|
|
|
" configuration.
|
|
|
|
|
|
|
|
if rust#GetConfigVar('rust_cargo_avoid_whole_workspace', 1)
|
|
|
|
if l:root_cargo_toml !=# l:nearest_cargo_toml
|
|
|
|
let makeprg = "cd " . fnamemodify(l:nearest_cargo_toml, ":p:h")
|
|
|
|
\ . " && " . makeprg
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let makeprg = "cd " . fnamemodify(l:root_cargo_toml, ":p:h")
|
|
|
|
\ . " && " . makeprg
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:check_all_targets = rust#GetConfigVar('rust_cargo_check_all_targets', 0)
|
|
|
|
let l:check_all_features = rust#GetConfigVar('rust_cargo_check_all_features', 0)
|
|
|
|
let l:check_examples = rust#GetConfigVar('rust_cargo_check_examples', 0)
|
|
|
|
let l:check_tests = rust#GetConfigVar('rust_cargo_check_tests', 0)
|
|
|
|
let l:check_benches = rust#GetConfigVar('rust_cargo_check_benches', 0)
|
|
|
|
|
|
|
|
let makeprg = makeprg. ' '
|
|
|
|
\ . (l:check_all_targets ? ' --all-targets' : '')
|
|
|
|
\ . (l:check_all_features ? ' --all-features' : '')
|
|
|
|
\ . (l:check_benches ? ' --benches' : '')
|
|
|
|
\ . (l:check_examples ? ' --examples' : '')
|
|
|
|
\ . (l:check_tests ? ' --tests' : '')
|
2019-11-16 11:14:34 -05:00
|
|
|
|
|
|
|
" Ignored patterns, and blank lines
|
|
|
|
let errorformat =
|
2019-11-16 12:43:18 -05:00
|
|
|
\ '%-G,' .
|
|
|
|
\ '%-Gerror: aborting %.%#,' .
|
|
|
|
\ '%-Gerror: Could not compile %.%#,'
|
2019-11-16 11:14:34 -05:00
|
|
|
|
|
|
|
" Meaningful lines (errors, notes, warnings, contextual information)
|
|
|
|
let errorformat .=
|
2019-11-16 12:43:18 -05:00
|
|
|
\ '%Eerror: %m,' .
|
|
|
|
\ '%Eerror[E%n]: %m,' .
|
|
|
|
\ '%Wwarning: %m,' .
|
|
|
|
\ '%Inote: %m,' .
|
|
|
|
\ '%C %#--> %f:%l:%c'
|
2019-11-16 11:14:34 -05:00
|
|
|
|
|
|
|
return SyntasticMake({
|
2019-11-16 12:43:18 -05:00
|
|
|
\ 'makeprg': makeprg,
|
|
|
|
\ 'cwd': fnamemodify(l:root_cargo_toml, ":p:h:."),
|
|
|
|
\ 'errorformat': errorformat })
|
2019-11-16 11:14:34 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
2019-11-16 12:43:18 -05:00
|
|
|
\ 'filetype': 'rust',
|
|
|
|
\ 'name': 'cargo'})
|
2019-11-16 11:14:34 -05:00
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
2019-11-16 12:43:18 -05:00
|
|
|
|
|
|
|
" vim: set et sw=4 sts=4 ts=8:
|