|
| 1 | +" Vim compiler file |
| 2 | +" Compiler: Cargo Compiler |
| 3 | +" Maintainer: Damien Radtke <[email protected]> |
| 4 | +" Latest Revision: 2014 Sep 18 |
| 5 | + |
| 6 | +if exists("current_compiler") |
| 7 | + finish |
| 8 | +endif |
| 9 | +let current_compiler = "cargo" |
| 10 | + |
| 11 | +if exists(":CompilerSet") != 2 |
| 12 | + command -nargs=* CompilerSet setlocal <args> |
| 13 | +endif |
| 14 | + |
| 15 | +CompilerSet errorformat& |
| 16 | +CompilerSet makeprg=cargo\ $* |
| 17 | + |
| 18 | +" Allow a configurable global Cargo.toml name. This makes it easy to |
| 19 | +" support variations like 'cargo.toml'. |
| 20 | +if !exists('g:cargo_toml_name') |
| 21 | + let g:cargo_toml_name = 'Cargo.toml' |
| 22 | +endif |
| 23 | + |
| 24 | +let s:toml_dir = fnamemodify(findfile(g:cargo_toml_name, '.;'), ':p:h').'/' |
| 25 | + |
| 26 | +if s:toml_dir != '' |
| 27 | + augroup cargo |
| 28 | + au! |
| 29 | + au QuickfixCmdPost make call s:FixPaths() |
| 30 | + augroup END |
| 31 | + |
| 32 | + " FixPaths() is run after Cargo, and is used to change the file paths |
| 33 | + " to be relative to the current directory instead of Cargo.toml. |
| 34 | + function! s:FixPaths() |
| 35 | + let qflist = getqflist() |
| 36 | + for qf in qflist |
| 37 | + if !qf['valid'] |
| 38 | + continue |
| 39 | + endif |
| 40 | + let filename = bufname(qf['bufnr']) |
| 41 | + if stridx(filename, s:toml_dir) == -1 |
| 42 | + let filename = s:toml_dir.filename |
| 43 | + endif |
| 44 | + let qf['filename'] = simplify(s:toml_dir.bufname(qf['bufnr'])) |
| 45 | + call remove(qf, 'bufnr') |
| 46 | + endfor |
| 47 | + call setqflist(qflist, 'r') |
| 48 | + endfunction |
| 49 | +endif |
0 commit comments