Skip to content

Add cargo as a checker for syntastic #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

innerand
Copy link

Add let g:syntastic_rust_checkers = ['cargo'] to vimrc and syntastic uses cargo check for syntax checking.

@arrufat
Copy link

arrufat commented Jun 16, 2017

I just want to say that I have been using this for some months now without any issue. I hope it gets accepted

@ghost
Copy link

ghost commented Jan 5, 2018

Does this work correctly inside a workspace? (note: that #76 does not, for it finds the subproject Cargo.toml only, instead of workspace's Cargo.toml which is ../ relative to subproject, thus vim/syntastic won't know how to find the files reported in the errors since they are relative to workspace dir, not subproject(aka package?) dir)

@ghost
Copy link

ghost commented Jan 5, 2018

Looks like the file that this PR adds, already exists in the repo: https://github.com/rust-lang/rust.vim/blob/master/syntax_checkers/rust/cargo.vim
and it seems to do the same thing? although there are differences:

--- thisPR/cargo.vim	2018-01-05 04:16:42.279586031 +0100
+++ repo/cargo.vim	2018-01-02 22:00:32.568566104 +0100
@@ -1,47 +1,47 @@
 " Vim syntastic plugin
 " Language:     Rust
-" Maintainer:   Innerand  <[email protected]>
-"
-" Adapted version of the rustc plugin by Andrew Gallant
+" Maintainer:   Julien Levesy <[email protected]>
 "
 " 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
+  return executable(self.getExec()) &&
+    \ syntastic#util#versionIsAtLeast(self.getVersion(), [0, 16, 0])
+endfunction
+
 function! SyntaxCheckers_rust_cargo_GetLocList() dict
-    let makeprg = self.makeprgBuild({
-             \ 'args': 'check',
-             \ 'fname': '' })
+    let makeprg = self.makeprgBuild({ "args": "check" })
 
-    " Old errorformat (before nightly 2016/08/10)
+    " Ignored patterns, and blank lines
     let errorformat  =
-        \ '%E%f:%l:%c: %\d%#:%\d%# %.%\{-}error:%.%\{-} %m,'   .
-        \ '%W%f:%l:%c: %\d%#:%\d%# %.%\{-}warning:%.%\{-} %m,' .
-        \ '%C%f:%l %m'
-
-    " New errorformat (after nightly 2016/08/10)
-    let errorformat  .=
-        \ ',' .
         \ '%-G,' .
         \ '%-Gerror: aborting %.%#,' .
-        \ '%-Gerror: Could not compile %.%#,' .
+        \ '%-Gerror: Could not compile %.%#,'
+
+    " Meaningful lines (errors, notes, warnings, contextual information)
+    let errorformat .=
         \ '%Eerror: %m,' .
         \ '%Eerror[E%n]: %m,' .
-        \ '%-Gwarning: the option `Z` is unstable %.%#,' .
         \ '%Wwarning: %m,' .
         \ '%Inote: %m,' .
         \ '%C %#--> %f:%l:%c'
 
     return SyntasticMake({
         \ 'makeprg': makeprg,
+        \ 'cwd': expand('%:p:h'),
         \ 'errorformat': errorformat })
 endfunction
 

@innerand
Copy link
Author

innerand commented Jan 6, 2018

This PR is from 03/17, that file was added by a PR from 12/16 merged in 08/17.
#132
I should have checked open PRs before implementing.

@innerand innerand closed this Jan 6, 2018
@ghost
Copy link

ghost commented Jan 6, 2018

well, from what I tested, neither handle the case when cwd is src, like PR #76 does :)
ie. they assume I always do vim src/main.rs instead of cd src; vim main.rs and thus in the latter case, no errors will be shown in vim.

No matter though, I patched cargo, for my own use, to always pass absolute filenames to rustc, thus rustc-reported errors are always full paths, thus not needing any cwd changes for vim to show errors even in case of workspaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants