Skip to content

Add cargo.vim compiler file. #17459

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

Merged
merged 1 commit into from
Sep 24, 2014
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
49 changes: 49 additions & 0 deletions src/etc/vim/compiler/cargo.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
" Vim compiler file
" Compiler: Cargo Compiler
" Maintainer: Damien Radtke <[email protected]>
" Latest Revision: 2014 Sep 18

if exists("current_compiler")
finish
endif
let current_compiler = "cargo"

if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif

CompilerSet errorformat&
CompilerSet makeprg=cargo\ $*

" Allow a configurable global Cargo.toml name. This makes it easy to
" support variations like 'cargo.toml'.
if !exists('g:cargo_toml_name')
let g:cargo_toml_name = 'Cargo.toml'
endif

let s:toml_dir = fnamemodify(findfile(g:cargo_toml_name, '.;'), ':p:h').'/'

if s:toml_dir != ''
augroup cargo
au!
au QuickfixCmdPost make call s:FixPaths()
augroup END

" FixPaths() is run after Cargo, and is used to change the file paths
" to be relative to the current directory instead of Cargo.toml.
function! s:FixPaths()
let qflist = getqflist()
for qf in qflist
if !qf['valid']
continue
endif
let filename = bufname(qf['bufnr'])
if stridx(filename, s:toml_dir) == -1
let filename = s:toml_dir.filename
endif
let qf['filename'] = simplify(s:toml_dir.bufname(qf['bufnr']))
call remove(qf, 'bufnr')
endfor
call setqflist(qflist, 'r')
endfunction
endif