From 1e2e2ac5550d4f1d89c4958ef35860ffff9ab6ef Mon Sep 17 00:00:00 2001 From: Damien Radtke Date: Wed, 24 Sep 2014 10:25:36 -0500 Subject: [PATCH 1/4] Some improvements to the Cargo compiler file. --- src/etc/vim/compiler/cargo.vim | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/etc/vim/compiler/cargo.vim b/src/etc/vim/compiler/cargo.vim index 89c1cff110e..d707ae82869 100644 --- a/src/etc/vim/compiler/cargo.vim +++ b/src/etc/vim/compiler/cargo.vim @@ -1,7 +1,7 @@ " Vim compiler file " Compiler: Cargo Compiler " Maintainer: Damien Radtke -" Latest Revision: 2014 Sep 18 +" Latest Revision: 2014 Sep 24 if exists("current_compiler") finish @@ -12,18 +12,18 @@ if exists(":CompilerSet") != 2 command -nargs=* CompilerSet setlocal 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() @@ -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') From 83f6a29f12c0e8231606d56b6a20df0dd0a78464 Mon Sep 17 00:00:00 2001 From: Damien Radtke Date: Tue, 7 Oct 2014 13:57:10 -0500 Subject: [PATCH 2/4] Use rustc's errorformat and add option to specify permanent parameters. --- src/etc/vim/compiler/cargo.vim | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/etc/vim/compiler/cargo.vim b/src/etc/vim/compiler/cargo.vim index d707ae82869..4b8212511cb 100644 --- a/src/etc/vim/compiler/cargo.vim +++ b/src/etc/vim/compiler/cargo.vim @@ -3,17 +3,28 @@ " Maintainer: Damien Radtke " Latest Revision: 2014 Sep 24 -if exists("current_compiler") +if exists('current_compiler') finish endif let current_compiler = "cargo" -if exists(":CompilerSet") != 2 +if exists(':CompilerSet') != 2 command -nargs=* CompilerSet setlocal endif -CompilerSet errorformat=%A%f:%l:%c:\ %m,%-Z%p^,%-C%.%# -CompilerSet makeprg=cargo\ $* +if exists('g:cargo_makeprg_params') + execute 'CompilerSet makeprg=cargo\ '.g:cargo_makeprg_params.'\ $*' +else + CompilerSet makeprg=cargo\ $* +endif + +CompilerSet errorformat= + \%f:%l:%c:\ %t%*[^:]:\ %m, + \%f:%l:%c:\ %*\\d:%*\\d\ %t%*[^:]:\ %m, + \%-G%f:%l\ %s, + \%-G%*[\ ]^, + \%-G%*[\ ]^%*[~], + \%-G%*[\ ]... " Allow a configurable global Cargo.toml name. This makes it easy to " support variations like 'cargo.toml'. From 0207e25d70b1a5733b170ac9f16a9702db8ee8ed Mon Sep 17 00:00:00 2001 From: Damien Radtke Date: Fri, 24 Oct 2014 18:14:45 -0500 Subject: [PATCH 3/4] Updates based on kballard's feedback. --- src/etc/vim/compiler/cargo.vim | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/etc/vim/compiler/cargo.vim b/src/etc/vim/compiler/cargo.vim index 4b8212511cb..8b646595c6a 100644 --- a/src/etc/vim/compiler/cargo.vim +++ b/src/etc/vim/compiler/cargo.vim @@ -6,6 +6,7 @@ if exists('current_compiler') finish endif +runtime compiler/rustc.vim let current_compiler = "cargo" if exists(':CompilerSet') != 2 @@ -13,28 +14,18 @@ if exists(':CompilerSet') != 2 endif if exists('g:cargo_makeprg_params') - execute 'CompilerSet makeprg=cargo\ '.g:cargo_makeprg_params.'\ $*' + execute 'CompilerSet makeprg=cargo\ '.escape(g:cargo_makeprg_params, ' \|"').'\ $*' else CompilerSet makeprg=cargo\ $* endif -CompilerSet errorformat= - \%f:%l:%c:\ %t%*[^:]:\ %m, - \%f:%l:%c:\ %*\\d:%*\\d\ %t%*[^:]:\ %m, - \%-G%f:%l\ %s, - \%-G%*[\ ]^, - \%-G%*[\ ]^%*[~], - \%-G%*[\ ]... - " Allow a configurable global Cargo.toml name. This makes it easy to " support variations like 'cargo.toml'. -if !exists('g:cargo_manifest_name') - let g:cargo_manifest_name = 'Cargo.toml' -endif - -let s:local_manifest = fnamemodify(findfile(g:cargo_manifest_name, '.;'), ':p:h').'/' +let s:cargo_manifest_name = get(g:, 'cargo_manifest_name', 'Cargo.toml') +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() @@ -46,23 +37,23 @@ if s:local_manifest != '' 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 + 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]*:/' + if manifest =~ '^/[A-Z]:/' let manifest = manifest[1:] endif endif continue endif - let filename = bufname(qf['bufnr']) + let filename = bufname(qf.bufnr) if filereadable(filename) continue endif - let qf['filename'] = simplify(manifest.filename) + let qf.filename = simplify(manifest.filename) call remove(qf, 'bufnr') endfor call setqflist(qflist, 'r') From 75e4d9583832c158a9c0927cdb087e4555434993 Mon Sep 17 00:00:00 2001 From: Damien Radtke Date: Tue, 4 Nov 2014 14:08:57 -0600 Subject: [PATCH 4/4] Added check for absolute file path, removed hard tab, and added documentation for new option. --- src/etc/vim/compiler/cargo.vim | 10 +++++++--- src/etc/vim/doc/rust.txt | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/etc/vim/compiler/cargo.vim b/src/etc/vim/compiler/cargo.vim index 8b646595c6a..ed487a308e1 100644 --- a/src/etc/vim/compiler/cargo.vim +++ b/src/etc/vim/compiler/cargo.vim @@ -23,9 +23,13 @@ endif " support variations like 'cargo.toml'. let s:cargo_manifest_name = get(g:, 'cargo_manifest_name', 'Cargo.toml') +function! s:is_absolute(path) + return a:path[0] == '/' || a:path =~ '[A-Z]\+:' +endfunction + let s:local_manifest = findfile(s:cargo_manifest_name, '.;') if s:local_manifest != '' - let s:local_manifest = fnamemodify(s:local_manifest, ':p:h').'/' + let s:local_manifest = fnamemodify(s:local_manifest, ':p:h').'/' augroup cargo au! au QuickfixCmdPost make call s:FixPaths() @@ -43,14 +47,14 @@ if s:local_manifest != '' let manifest = m[1].'/' " Manually strip another slash if needed; usually just an " issue on Windows. - if manifest =~ '^/[A-Z]:/' + if manifest =~ '^/[A-Z]\+:/' let manifest = manifest[1:] endif endif continue endif let filename = bufname(qf.bufnr) - if filereadable(filename) + if s:is_absolute(filename) continue endif let qf.filename = simplify(manifest.filename) diff --git a/src/etc/vim/doc/rust.txt b/src/etc/vim/doc/rust.txt index 80f8c3ca5e1..1693714f215 100644 --- a/src/etc/vim/doc/rust.txt +++ b/src/etc/vim/doc/rust.txt @@ -79,6 +79,13 @@ g:ftplugin_rust_source_path~ let g:ftplugin_rust_source_path = $HOME.'/dev/rust' < + *g:cargo_manifest_name* +g:cargo_manifest_name~ + Set this option to the name of the manifest file for your projects. If + not specified it defaults to 'Cargo.toml' : > + let g:cargo_manifest_name = 'Cargo.toml' +< + ============================================================================== COMMANDS *rust-commands*