diff --git a/doc/rust.txt b/doc/rust.txt index 5621e37c..d7f9c4f2 100644 --- a/doc/rust.txt +++ b/doc/rust.txt @@ -133,6 +133,31 @@ g:rust_shortener_url~ let g:rust_shortener_url = 'https://is.gd/' < + *g:rustc_syntax_only* +g:rustc_syntax_only~ + Set this option to control the syntastic linter. + You can choose between a simple syntax parser or a fuller compilation. + + The syntax parser is very fast, but won't catch any compilation + errors. This is the default. + We recommend you enable syntastic's active mode with this setting + (that's the default too). > + let g:rustc_syntax_only = 1 +< + + The fuller compilation performs a compilation of the entire project. + This makes it really slow on large projects. + If VIM becomes unusable, set syntastic passive mode for Rust. This + will make it so that the lint will only run on |:SyntasticCheck| (see + |syntastic_mode_map|). +> + let g:rustc_syntax_only = 0 + " Syntastic passive mode + let g:syntastic_mode_map = { + \ "mode": "active", + \ "active_filetypes": [], + \ "passive_filetypes": ["rust"] } +< ============================================================================== COMMANDS *rust-commands* diff --git a/syntax_checkers/rust/rustc.vim b/syntax_checkers/rust/rustc.vim index 5d196086..d7ade5ab 100644 --- a/syntax_checkers/rust/rustc.vim +++ b/syntax_checkers/rust/rustc.vim @@ -10,11 +10,29 @@ if exists("g:loaded_syntastic_rust_rustc_checker") endif let g:loaded_syntastic_rust_rustc_checker = 1 +if !exists('g:rustc_syntax_only') + let g:rustc_syntax_only = 1 "Keep the fast behaviour by default +endif + let s:save_cpo = &cpo set cpo&vim function! SyntaxCheckers_rust_rustc_GetLocList() dict - let makeprg = self.makeprgBuild({ 'args': '-Zparse-only' }) + let compiler_params = g:rustc_syntax_only ? '-Zparse-only' : '-Zno-trans' + 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': compiler_params}) + else " We are inside a crate + let makeprg = self.makeprgBuild({ + \ 'exe': 'cargo', + \ 'args': 'rustc ' . compiler_params, + \ '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,' . @@ -24,12 +42,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