Skip to content

Commit 8296808

Browse files
committed
auto merge of #17513 : dradtke/rust/master, r=kballard
Looks like I made my previous PR a little too hastily. =) This PR fixes a couple issues that I discovered with my previous revision: 1. Updated the errorformat to ignore "pointer lines" so that they don't show up in the output (with quickfix jumping, they're redundant and unnecessary). 2. Renamed a couple variables to be more in line with Cargo's terminology (`g:cargo_toml_name` should now be `g:cargo_manifest_name`). 3. Added support for errors reported with absolute paths (looks to be the case when compiling an executable instead of a library). 4. Most importantly, added support for errors reported while compiling a dependency. When building a Cargo package with local dependencies, if one of those dependencies failed to compile, the quickfix would be completely broken as it assumed that all errors were relative to the local manifest, or the closest Cargo.toml. With this update, it now pays attention to lines that end with `(file://<path>)`, and from then on adjusts all errors to be relative to `<path>`. As a side note, that `<path>` output is somewhat broken on Windows. While `file:///home/damien/...` on *Nix is a valid URI, `file:///C:/Users/damien/...` on Windows is not, because `C:/` (or whatever the drive is) should take the place of the third slash which is *Nix's root, not be appended to it. I added a workaround for this in my script, but I figured I'd mention it to see if this is a bug in how Rust formats paths.
2 parents 2a4c010 + 75e4d95 commit 8296808

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

src/etc/vim/compiler/cargo.vim

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
" Vim compiler file
22
" Compiler: Cargo Compiler
33
" Maintainer: Damien Radtke <[email protected]>
4-
" Latest Revision: 2014 Sep 18
4+
" Latest Revision: 2014 Sep 24
55

6-
if exists("current_compiler")
6+
if exists('current_compiler')
77
finish
88
endif
9+
runtime compiler/rustc.vim
910
let current_compiler = "cargo"
1011

11-
if exists(":CompilerSet") != 2
12+
if exists(':CompilerSet') != 2
1213
command -nargs=* CompilerSet setlocal <args>
1314
endif
1415

15-
CompilerSet errorformat&
16-
CompilerSet makeprg=cargo\ $*
16+
if exists('g:cargo_makeprg_params')
17+
execute 'CompilerSet makeprg=cargo\ '.escape(g:cargo_makeprg_params, ' \|"').'\ $*'
18+
else
19+
CompilerSet makeprg=cargo\ $*
20+
endif
1721

1822
" Allow a configurable global Cargo.toml name. This makes it easy to
1923
" support variations like 'cargo.toml'.
20-
if !exists('g:cargo_toml_name')
21-
let g:cargo_toml_name = 'Cargo.toml'
22-
endif
24+
let s:cargo_manifest_name = get(g:, 'cargo_manifest_name', 'Cargo.toml')
2325

24-
let s:toml_dir = fnamemodify(findfile(g:cargo_toml_name, '.;'), ':p:h').'/'
26+
function! s:is_absolute(path)
27+
return a:path[0] == '/' || a:path =~ '[A-Z]\+:'
28+
endfunction
2529

26-
if s:toml_dir != ''
30+
let s:local_manifest = findfile(s:cargo_manifest_name, '.;')
31+
if s:local_manifest != ''
32+
let s:local_manifest = fnamemodify(s:local_manifest, ':p:h').'/'
2733
augroup cargo
2834
au!
2935
au QuickfixCmdPost make call s:FixPaths()
@@ -33,15 +39,25 @@ if s:toml_dir != ''
3339
" to be relative to the current directory instead of Cargo.toml.
3440
function! s:FixPaths()
3541
let qflist = getqflist()
42+
let manifest = s:local_manifest
3643
for qf in qflist
37-
if !qf['valid']
44+
if !qf.valid
45+
let m = matchlist(qf.text, '(file://\(.*\))$')
46+
if !empty(m)
47+
let manifest = m[1].'/'
48+
" Manually strip another slash if needed; usually just an
49+
" issue on Windows.
50+
if manifest =~ '^/[A-Z]\+:/'
51+
let manifest = manifest[1:]
52+
endif
53+
endif
3854
continue
3955
endif
40-
let filename = bufname(qf['bufnr'])
41-
if stridx(filename, s:toml_dir) == -1
42-
let filename = s:toml_dir.filename
56+
let filename = bufname(qf.bufnr)
57+
if s:is_absolute(filename)
58+
continue
4359
endif
44-
let qf['filename'] = simplify(s:toml_dir.bufname(qf['bufnr']))
60+
let qf.filename = simplify(manifest.filename)
4561
call remove(qf, 'bufnr')
4662
endfor
4763
call setqflist(qflist, 'r')

src/etc/vim/doc/rust.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ g:ftplugin_rust_source_path~
8888
let g:ftplugin_rust_source_path = $HOME.'/dev/rust'
8989
<
9090

91+
*g:cargo_manifest_name*
92+
g:cargo_manifest_name~
93+
Set this option to the name of the manifest file for your projects. If
94+
not specified it defaults to 'Cargo.toml' : >
95+
let g:cargo_manifest_name = 'Cargo.toml'
96+
<
97+
9198
==============================================================================
9299
COMMANDS *rust-commands*
93100

0 commit comments

Comments
 (0)