vim-polyglot/compiler/cargo.vim

70 lines
2.1 KiB
VimL
Raw Permalink Normal View History

if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
2014-11-10 20:37:21 -05:00
" Vim compiler file
" Compiler: Cargo Compiler
" Maintainer: Damien Radtke <damienradtke@gmail.com>
2014-12-09 17:09:20 -05:00
" Latest Revision: 2014 Sep 24
2014-11-10 20:37:21 -05:00
2014-12-09 17:09:20 -05:00
if exists('current_compiler')
2014-11-10 20:37:21 -05:00
finish
endif
2014-12-09 17:09:20 -05:00
runtime compiler/rustc.vim
2014-11-10 20:37:21 -05:00
let current_compiler = "cargo"
2014-12-09 17:09:20 -05:00
if exists(':CompilerSet') != 2
2014-11-10 20:37:21 -05:00
command -nargs=* CompilerSet setlocal <args>
endif
2014-12-09 17:09:20 -05:00
if exists('g:cargo_makeprg_params')
execute 'CompilerSet makeprg=cargo\ '.escape(g:cargo_makeprg_params, ' \|"').'\ $*'
else
CompilerSet makeprg=cargo\ $*
endif
2014-11-10 20:37:21 -05:00
" Allow a configurable global Cargo.toml name. This makes it easy to
" support variations like 'cargo.toml'.
2014-12-09 17:09:20 -05:00
let s:cargo_manifest_name = get(g:, 'cargo_manifest_name', 'Cargo.toml')
2014-11-10 20:37:21 -05:00
2014-12-09 17:09:20 -05:00
function! s:is_absolute(path)
return a:path[0] == '/' || a:path =~ '[A-Z]\+:'
endfunction
2014-11-10 20:37:21 -05:00
2014-12-09 17:09:20 -05:00
let s:local_manifest = findfile(s:cargo_manifest_name, '.;')
if s:local_manifest != ''
let s:local_manifest = fnamemodify(s:local_manifest, ':p:h').'/'
2014-11-10 20:37:21 -05:00
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()
2014-12-09 17:09:20 -05:00
let manifest = s:local_manifest
2014-11-10 20:37:21 -05:00
for qf in qflist
2014-12-09 17:09:20 -05:00
if !qf.valid
let m = matchlist(qf.text, '(file://\(.*\))$')
if !empty(m)
let manifest = m[1].'/'
" Manually strip another slash if needed; usually just an
" issue on Windows.
if manifest =~ '^/[A-Z]\+:/'
let manifest = manifest[1:]
endif
endif
2014-11-10 20:37:21 -05:00
continue
endif
2014-12-09 17:09:20 -05:00
let filename = bufname(qf.bufnr)
if s:is_absolute(filename)
continue
2014-11-10 20:37:21 -05:00
endif
2014-12-09 17:09:20 -05:00
let qf.filename = simplify(manifest.filename)
2014-11-10 20:37:21 -05:00
call remove(qf, 'bufnr')
endfor
call setqflist(qflist, 'r')
endfunction
endif
endif