Skip to content

Commit

Permalink
Some improvements to the Cargo compiler file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien Radtke committed Sep 24, 2014
1 parent 59e750f commit 1e2e2ac
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/etc/vim/compiler/cargo.vim
@@ -1,7 +1,7 @@
" Vim compiler file
" Compiler: Cargo Compiler
" Maintainer: Damien Radtke <damienradtke@gmail.com>
" Latest Revision: 2014 Sep 18
" Latest Revision: 2014 Sep 24

if exists("current_compiler")
finish
Expand All @@ -12,18 +12,18 @@ if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif

CompilerSet errorformat&
CompilerSet errorformat=%A%f:%l:%c:\ %m,%-Z%p^,%-C%.%#
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'
if !exists('g:cargo_manifest_name')
let g:cargo_manifest_name = 'Cargo.toml'
endif

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

if s:toml_dir != ''
if s:local_manifest != ''
augroup cargo
au!
au QuickfixCmdPost make call s:FixPaths()
Expand All @@ -33,15 +33,25 @@ if s:toml_dir != ''
" to be relative to the current directory instead of Cargo.toml.
function! s:FixPaths()
let qflist = getqflist()
let manifest = s:local_manifest
for qf in qflist
if !qf['valid']
let m = matchlist(qf['text'], '\v.*\(file://(.*)\)$')
if len(m) > 0
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
continue
endif
let filename = bufname(qf['bufnr'])
if stridx(filename, s:toml_dir) == -1
let filename = s:toml_dir.filename
if filereadable(filename)
continue
endif
let qf['filename'] = simplify(s:toml_dir.bufname(qf['bufnr']))
let qf['filename'] = simplify(manifest.filename)
call remove(qf, 'bufnr')
endfor
call setqflist(qflist, 'r')
Expand Down

0 comments on commit 1e2e2ac

Please sign in to comment.