about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDamien Radtke <dradtke@channeliq.com>2014-09-22 17:24:26 -0500
committerDamien Radtke <dradtke@channeliq.com>2014-09-22 17:24:26 -0500
commit59e750f198a31ef1222dd6048d873391a459abcf (patch)
treeae40f2ba2d317f1cd6aaa5ffbc1159925940f63a
parent437179ed8bf7f7672f84b19265df1ce569e70490 (diff)
downloadrust-59e750f198a31ef1222dd6048d873391a459abcf.tar.gz
rust-59e750f198a31ef1222dd6048d873391a459abcf.zip
Add cargo.vim compiler file.
-rw-r--r--src/etc/vim/compiler/cargo.vim49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/etc/vim/compiler/cargo.vim b/src/etc/vim/compiler/cargo.vim
new file mode 100644
index 00000000000..89c1cff110e
--- /dev/null
+++ b/src/etc/vim/compiler/cargo.vim
@@ -0,0 +1,49 @@
+" Vim compiler file
+" Compiler:         Cargo Compiler
+" Maintainer:       Damien Radtke <damienradtke@gmail.com>
+" 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