-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Some improvements to the Vim Cargo compiler file. #17513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1e2e2ac
83f6a29
0207e25
75e4d95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
" Vim compiler file | ||
" Compiler: Cargo Compiler | ||
" Maintainer: Damien Radtke <[email protected]> | ||
" Latest Revision: 2014 Sep 18 | ||
" Latest Revision: 2014 Sep 24 | ||
|
||
if exists("current_compiler") | ||
if exists('current_compiler') | ||
finish | ||
endif | ||
runtime compiler/rustc.vim | ||
let current_compiler = "cargo" | ||
|
||
if exists(":CompilerSet") != 2 | ||
if exists(':CompilerSet') != 2 | ||
command -nargs=* CompilerSet setlocal <args> | ||
endif | ||
|
||
CompilerSet errorformat& | ||
CompilerSet makeprg=cargo\ $* | ||
if exists('g:cargo_makeprg_params') | ||
execute 'CompilerSet makeprg=cargo\ '.escape(g:cargo_makeprg_params, ' \|"').'\ $*' | ||
else | ||
CompilerSet makeprg=cargo\ $* | ||
endif | ||
|
||
" 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:cargo_manifest_name = get(g:, 'cargo_manifest_name', 'Cargo.toml') | ||
|
||
let s:toml_dir = fnamemodify(findfile(g:cargo_toml_name, '.;'), ':p:h').'/' | ||
function! s:is_absolute(path) | ||
return a:path[0] == '/' || a:path =~ '[A-Z]\+:' | ||
endfunction | ||
|
||
if s:toml_dir != '' | ||
let s:local_manifest = findfile(s:cargo_manifest_name, '.;') | ||
if s:local_manifest != '' | ||
let s:local_manifest = fnamemodify(s:local_manifest, ':p:h').'/' | ||
augroup cargo | ||
au! | ||
au QuickfixCmdPost make call s:FixPaths() | ||
|
@@ -33,15 +39,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'] | ||
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 | ||
continue | ||
endif | ||
let filename = bufname(qf['bufnr']) | ||
if stridx(filename, s:toml_dir) == -1 | ||
let filename = s:toml_dir.filename | ||
let filename = bufname(qf.bufnr) | ||
if s:is_absolute(filename) | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are these two lines for? Can't we rely on the output from Cargo being relative to the manifest? The problem with having this conditional is if I have a directory structure like
and I am in I think instead what needs to be done is the filename needs to be tested to see if it's absolute. If it is absolute, then it can be left alone, but if it's relative then it needs to be appended to |
||
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') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if condition is doing nothing. The
fnamemodify()
will expand an empty string to the cwd, and even if that didn't, the.'/'
will also guarantee the string isn't empty.I'd recommend instead doing something like
(
s:cargo_manifest_name
coming from the previous suggested change)