Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions syntax_checkers/rust/rustc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ let s:save_cpo = &cpo
set cpo&vim

function! SyntaxCheckers_rust_rustc_GetLocList() dict
let makeprg = self.makeprgBuild({ 'args': '-Zparse-only' })
let cwd = '.' " Don't change cwd as default
let cargo_toml_path = findfile('Cargo.toml', '.;')
if empty(cargo_toml_path) " Plain rs file, not a crate
let makeprg = self.makeprgBuild({
\ 'exe': 'rustc',
\ 'args': '-Zno-trans' })
else " We are inside a crate
let makeprg = self.makeprgBuild({
\ 'exe': 'cargo',
\ 'args': 'rustc -Zno-trans',
\ 'fname': '' })
" Change cwd to the root of the crate
let cwd = fnamemodify( cargo_toml_path, ':p:h')
endif

let errorformat =
\ '%E%f:%l:%c: %\d%#:%\d%# %.%\{-}error:%.%\{-} %m,' .
Expand All @@ -24,12 +37,13 @@ function! SyntaxCheckers_rust_rustc_GetLocList() dict

return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
\ 'errorformat': errorformat,
\ 'cwd': cwd })
endfunction

call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'rust',
\ 'name': 'rustc'})
\ 'name': 'rustc' })

let &cpo = s:save_cpo
unlet s:save_cpo