summaryrefslogtreecommitdiff
path: root/ale_linters/rust/cargo.vim
diff options
context:
space:
mode:
authorDan Aloni <alonid@gmail.com>2018-06-28 00:36:02 +0300
committerw0rp <w0rp@users.noreply.github.com>2018-06-27 22:36:02 +0100
commitd9e139ae2384b04af05ce9343aa0d0a5bae5449b (patch)
tree4298b157ed7eb253f55f616b7a54e2e6b72aed96 /ale_linters/rust/cargo.vim
parent980aa35566f1a5c66c7b9939bb07ec68deebccb2 (diff)
downloadale-d9e139ae2384b04af05ce9343aa0d0a5bae5449b.zip
Rust Cargo linter: Improve workspace support (#1679)
* Rust Cargo linter: Improve workspace support When using Cargo workspaces [1], there is a 'Cargo.toml' directory in a top level directory, listing all the crates in the project. If we are currently editing one of the crates, 'cargo build' should execute in that directory for that crate's separate `Cargo.toml`, otherwise Cargo may spend more time possibly rebuilding the entire workspace, and maybe failing on one of the other crates, instead of succeeding on the current. [1] https://doc.rust-lang.org/book/second-edition/ch14-03-cargo-workspaces.html
Diffstat (limited to 'ale_linters/rust/cargo.vim')
-rw-r--r--ale_linters/rust/cargo.vim15
1 files changed, 14 insertions, 1 deletions
diff --git a/ale_linters/rust/cargo.vim b/ale_linters/rust/cargo.vim
index ef0c3bd1..e6c3870a 100644
--- a/ale_linters/rust/cargo.vim
+++ b/ale_linters/rust/cargo.vim
@@ -6,6 +6,7 @@ call ale#Set('rust_cargo_use_check', 1)
call ale#Set('rust_cargo_check_all_targets', 0)
call ale#Set('rust_cargo_check_examples', 0)
call ale#Set('rust_cargo_check_tests', 0)
+call ale#Set('rust_cargo_avoid_whole_workspace', 1)
call ale#Set('rust_cargo_default_feature_behavior', 'default')
call ale#Set('rust_cargo_include_features', '')
@@ -45,6 +46,18 @@ function! ale_linters#rust#cargo#GetCommand(buffer, version_output) abort
let l:include_features = ' --features ' . ale#Escape(l:include_features)
endif
+ let l:avoid_whole_workspace = ale#Var(a:buffer, 'rust_cargo_avoid_whole_workspace')
+ let l:nearest_cargo_prefix = ''
+
+ if l:avoid_whole_workspace
+ let l:nearest_cargo = ale#path#FindNearestFile(a:buffer, 'Cargo.toml')
+ let l:nearest_cargo_dir = fnamemodify(l:nearest_cargo, ':h')
+
+ if l:nearest_cargo_dir isnot# '.'
+ let l:nearest_cargo_prefix = 'cd '. ale#Escape(l:nearest_cargo_dir) .' && '
+ endif
+ endif
+
let l:default_feature_behavior = ale#Var(a:buffer, 'rust_cargo_default_feature_behavior')
if l:default_feature_behavior is# 'all'
let l:include_features = ''
@@ -55,7 +68,7 @@ function! ale_linters#rust#cargo#GetCommand(buffer, version_output) abort
let l:default_feature = ''
endif
- return 'cargo '
+ return l:nearest_cargo_prefix . 'cargo '
\ . (l:use_check ? 'check' : 'build')
\ . (l:use_all_targets ? ' --all-targets' : '')
\ . (l:use_examples ? ' --examples' : '')