//! See `CargoTargetSpec`
-use cfg::CfgExpr;
+use cfg::{CfgAtom, CfgExpr};
use ide::{FileId, RunnableKind, TestId};
-use project_model::{self, TargetKind};
+use project_model::{self, ManifestPath, TargetKind};
use vfs::AbsPathBuf;
use crate::{global_state::GlobalStateSnapshot, Result};
#[derive(Clone)]
pub(crate) struct CargoTargetSpec {
pub(crate) workspace_root: AbsPathBuf,
+ pub(crate) cargo_toml: ManifestPath,
pub(crate) package: String,
pub(crate) target: String,
pub(crate) target_kind: TargetKind,
snap: &GlobalStateSnapshot,
spec: Option<CargoTargetSpec>,
kind: &RunnableKind,
- cfgs: &[CfgExpr],
+ cfg: &Option<CfgExpr>,
) -> Result<(Vec<String>, Vec<String>)> {
let mut args = Vec::new();
let mut extra_args = Vec::new();
}
}
- if snap.config.cargo.all_features {
+ let cargo_config = snap.config.cargo();
+ if cargo_config.all_features {
args.push("--all-features".to_string());
} else {
let mut features = Vec::new();
- for cfg in cfgs {
+ if let Some(cfg) = cfg.as_ref() {
required_features(cfg, &mut features);
}
- for feature in &snap.config.cargo.features {
+ for feature in cargo_config.features {
features.push(feature.clone());
}
features.dedup();
Some(it) => it,
None => return Ok(None),
};
+
+ let target_data = &cargo_ws[target];
+ let package_data = &cargo_ws[target_data.package];
let res = CargoTargetSpec {
workspace_root: cargo_ws.workspace_root().to_path_buf(),
- package: cargo_ws.package_flag(&cargo_ws[cargo_ws[target].package]),
- target: cargo_ws[target].name.clone(),
- target_kind: cargo_ws[target].kind,
+ cargo_toml: package_data.manifest.clone(),
+ package: cargo_ws.package_flag(package_data),
+ target: target_data.name.clone(),
+ target_kind: target_data.kind,
};
+
Ok(Some(res))
}
TargetKind::Lib => {
buf.push("--lib".to_string());
}
- TargetKind::Other => (),
+ TargetKind::Other | TargetKind::BuildScript => (),
}
}
}
/// Fill minimal features needed
fn required_features(cfg_expr: &CfgExpr, features: &mut Vec<String>) {
match cfg_expr {
- CfgExpr::KeyValue { key, value } if key == "feature" => features.push(value.to_string()),
+ CfgExpr::Atom(CfgAtom::KeyValue { key, value }) if key == "feature" => {
+ features.push(value.to_string())
+ }
CfgExpr::All(preds) => {
preds.iter().for_each(|cfg| required_features(cfg, features));
}
use super::*;
use cfg::CfgExpr;
- use mbe::ast_to_token_tree;
+ use mbe::syntax_node_to_token_tree;
use syntax::{
ast::{self, AstNode},
SmolStr,
let cfg_expr = {
let source_file = ast::SourceFile::parse(cfg).ok().unwrap();
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
- let (tt, _) = ast_to_token_tree(&tt).unwrap();
+ let (tt, _) = syntax_node_to_token_tree(tt.syntax());
CfgExpr::parse(&tt)
};