File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,20 @@ let s:save_cpo = &cpo
1414set cpo &vim
1515
1616function ! SyntaxCheckers_rust_rustc_GetLocList () dict
17- let makeprg = self .makeprgBuild ({
18- \ ' args' : ' rustc -Zno-trans' ,
19- \ ' fname' : ' ' })
17+ let cwd = ' .' " Don't change cwd as default
18+ let cargo_toml_path = findfile (' Cargo.toml' , ' .;' )
19+ if empty (cargo_toml_path) " Plain rs file, not a crate
20+ let makeprg = self .makeprgBuild ({
21+ \ ' exe' : ' rustc' ,
22+ \ ' args' : ' -Zno-trans' })
23+ else " We are inside a crate
24+ let makeprg = self .makeprgBuild ({
25+ \ ' exe' : ' cargo' ,
26+ \ ' args' : ' rustc -Zno-trans' ,
27+ \ ' fname' : ' ' })
28+ " Change cwd to the root of the crate
29+ let cwd = fnamemodify ( cargo_toml_path, ' :p:h' )
30+ endif
2031
2132 let errorformat =
2233 \ ' %E%f:%l:%c: %\d%#:%\d%# %.%\{-}error:%.%\{-} %m,' .
@@ -26,13 +37,13 @@ function! SyntaxCheckers_rust_rustc_GetLocList() dict
2637
2738 return SyntasticMake ({
2839 \ ' makeprg' : makeprg ,
29- \ ' errorformat' : errorformat })
40+ \ ' errorformat' : errorformat ,
41+ \ ' cwd' : cwd })
3042endfunction
3143
3244call g: SyntasticRegistry .CreateAndRegisterChecker ({
33- \ ' exec' : ' cargo' ,
3445 \ ' filetype' : ' rust' ,
35- \ ' name' : ' rustc' })
46+ \ ' name' : ' rustc' })
3647
3748let &cpo = s: save_cpo
3849unlet s: save_cpo
You can’t perform that action at this time.
0 commit comments