From 9c9c38b5da224d30cc3e9f523bb775c4b5374469 Mon Sep 17 00:00:00 2001 From: Julien Levesy Date: Wed, 28 Dec 2016 11:46:17 +0100 Subject: [PATCH 1/3] Add a cargo syntax checker --- syntax_checkers/rust/cargo.vim | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 syntax_checkers/rust/cargo.vim diff --git a/syntax_checkers/rust/cargo.vim b/syntax_checkers/rust/cargo.vim new file mode 100644 index 00000000..57873ffd --- /dev/null +++ b/syntax_checkers/rust/cargo.vim @@ -0,0 +1,50 @@ +" Vim syntastic plugin +" Language: Rust +" Maintainer: Julien Levesy +" +" 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 + +let g:syntastic_rust_cargo_fname = "" + +let s:save_cpo = &cpo +set cpo&vim + +function! SyntaxCheckers_rust_cargo_IsAvailable() dict + return executable(self.getExec()) +endfunction + +function! SyntaxCheckers_rust_cargo_GetLocList() dict + let makeprg = self.makeprgBuild({ "args": "check" }) + + " Ignored patterns, and blank lines + let errorformat = + \ '%-G,' . + \ '%-Gerror: aborting %.%#,' . + \ '%-Gerror: Could not compile %.%#,' . + \ '%-Gwarning: the option `Z` is unstable %.%#,' + + " Meaningful lines (errors, notes, warnings, contextual information) + let errorformat .= + \ '%Eerror: %m,' . + \ '%Eerror[E%n]: %m,' . + \ '%Wwarning: %m,' . + \ '%Inote: %m,' . + \ '%C %#--> %f:%l:%c' + + return SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat }) +endfunction + +call g:SyntasticRegistry.CreateAndRegisterChecker({ + \ 'filetype': 'rust', + \ 'name': 'cargo'}) + +let &cpo = s:save_cpo +unlet s:save_cpo From cf35cae28bc4b416f4dbbe850ecb0d757a7def2c Mon Sep 17 00:00:00 2001 From: Julien Levesy Date: Fri, 30 Dec 2016 14:05:19 +0100 Subject: [PATCH 2/3] require cargo version >= 0.16.0, fix style nits --- syntax_checkers/rust/cargo.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/syntax_checkers/rust/cargo.vim b/syntax_checkers/rust/cargo.vim index 57873ffd..a6222bd0 100644 --- a/syntax_checkers/rust/cargo.vim +++ b/syntax_checkers/rust/cargo.vim @@ -8,15 +8,18 @@ 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 - return executable(self.getExec()) + return executable(self.getExec()) && + \ syntastic#util#versionIsAtLeast(self.getVersion(), [0, 16, 0]) endfunction function! SyntaxCheckers_rust_cargo_GetLocList() dict @@ -26,8 +29,7 @@ function! SyntaxCheckers_rust_cargo_GetLocList() dict let errorformat = \ '%-G,' . \ '%-Gerror: aborting %.%#,' . - \ '%-Gerror: Could not compile %.%#,' . - \ '%-Gwarning: the option `Z` is unstable %.%#,' + \ '%-Gerror: Could not compile %.%#,' " Meaningful lines (errors, notes, warnings, contextual information) let errorformat .= From 29c61e17cd767098e096dd44d84b56e6ea9822f5 Mon Sep 17 00:00:00 2001 From: Julien Levesy Date: Wed, 9 Aug 2017 12:23:54 +0200 Subject: [PATCH 3/3] allow files to be opened and checked outside of project directory --- syntax_checkers/rust/cargo.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/syntax_checkers/rust/cargo.vim b/syntax_checkers/rust/cargo.vim index a6222bd0..f0645662 100644 --- a/syntax_checkers/rust/cargo.vim +++ b/syntax_checkers/rust/cargo.vim @@ -41,6 +41,7 @@ function! SyntaxCheckers_rust_cargo_GetLocList() dict return SyntasticMake({ \ 'makeprg': makeprg, + \ 'cwd': expand('%:p:h'), \ 'errorformat': errorformat }) endfunction