add support of feature flag for runnables #4464

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
Benjamin Coenen
2020-05-21 10:48:42 +02:00
parent ebaa05a447
commit c6143742bd
7 changed files with 212 additions and 19 deletions

View File

@@ -4,6 +4,7 @@ use ra_ide::{FileId, RunnableKind, TestId};
use ra_project_model::{self, ProjectWorkspace, TargetKind};
use crate::{world::WorldSnapshot, Result};
use ra_syntax::SmolStr;
/// Abstract representation of Cargo target.
///
@@ -20,6 +21,7 @@ impl CargoTargetSpec {
pub(crate) fn runnable_args(
spec: Option<CargoTargetSpec>,
kind: &RunnableKind,
features_needed: &Option<Vec<SmolStr>>,
) -> Result<(Vec<String>, Vec<String>)> {
let mut args = Vec::new();
let mut extra_args = Vec::new();
@@ -73,6 +75,13 @@ impl CargoTargetSpec {
}
}
}
if let Some(features_needed) = features_needed {
features_needed.iter().for_each(|feature| {
args.push("--features".to_string());
args.push(feature.to_string());
});
}
Ok((args, extra_args))
}

View File

@@ -1012,7 +1012,8 @@ fn to_lsp_runnable(
) -> Result<lsp_ext::Runnable> {
let spec = CargoTargetSpec::for_file(world, file_id)?;
let target = spec.as_ref().map(|s| s.target.clone());
let (args, extra_args) = CargoTargetSpec::runnable_args(spec, &runnable.kind)?;
let (args, extra_args) =
CargoTargetSpec::runnable_args(spec, &runnable.kind, &runnable.features_needed)?;
let line_index = world.analysis().file_line_index(file_id)?;
let label = match &runnable.kind {
RunnableKind::Test { test_id, .. } => format!("test {}", test_id),