Skip to content
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

Add a cargo checker for syntastic #132

Merged
merged 3 commits into from
Aug 14, 2017
Merged
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
53 changes: 53 additions & 0 deletions syntax_checkers/rust/cargo.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
" Vim syntastic plugin
" Language: Rust
" Maintainer: Julien Levesy <jlevesy@gmail.com>
"
" 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" })

" Ignored patterns, and blank lines
let errorformat =
\ '%-G,' .
\ '%-Gerror: aborting %.%#,' .
\ '%-Gerror: Could not compile %.%#,'

" 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,
Copy link
Contributor

@hcpl hcpl Jun 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlevesy apparently, 'cwd': expand('%:p:h') here is what solved the problem for @hasufell (taken from https://github.com/mckinnsb/rust.vim/blob/master/syntax_checkers/rust/cargo.vim#L40).

The current version doesn't work if you open a file from outside of the project it resides, because:

  • cargo check needs to be called within the project,
  • but Syntastic inherits vim environment when SyntasticMake is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thank you for the review.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that works

\ 'cwd': expand('%:p:h'),
\ 'errorformat': errorformat })
endfunction

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

let &cpo = s:save_cpo
unlet s:save_cpo