From d2ea776b8fbb5286a04dde75a9a8f8b14f12bfe9 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Mon, 30 Sep 2019 07:38:16 +0800 Subject: Enable CfgOptions `test` for workspace crates --- crates/ra_ide_api/Cargo.toml | 1 + crates/ra_ide_api/src/lib.rs | 6 +++++- crates/ra_ide_api/src/mock_analysis.rs | 7 +++++-- crates/ra_ide_api/src/parent_module.rs | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml index 6bbf9d5dd..f919a2d61 100644 --- a/crates/ra_ide_api/Cargo.toml +++ b/crates/ra_ide_api/Cargo.toml @@ -23,6 +23,7 @@ rand = { version = "0.7.0", features = ["small_rng"] } ra_syntax = { path = "../ra_syntax" } ra_text_edit = { path = "../ra_text_edit" } ra_db = { path = "../ra_db" } +ra_cfg = { path = "../ra_cfg" } ra_fmt = { path = "../ra_fmt" } ra_prof = { path = "../ra_prof" } hir = { path = "../ra_hir", package = "ra_hir" } diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 44d1ec77b..24f1b91f6 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -49,6 +49,7 @@ mod test_utils; use std::sync::Arc; +use ra_cfg::CfgOptions; use ra_db::{ salsa::{self, ParallelDatabase}, CheckCanceled, SourceDatabase, @@ -322,7 +323,10 @@ impl Analysis { change.add_root(source_root, true); let mut crate_graph = CrateGraph::default(); let file_id = FileId(0); - crate_graph.add_crate_root(file_id, Edition::Edition2018); + // FIXME: cfg options + // Default to enable test for single file. + let cfg_options = CfgOptions::default().atom("test".into()); + crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); change.set_crate_graph(crate_graph); host.apply_change(change); diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs index 16870c7ae..13258b63d 100644 --- a/crates/ra_ide_api/src/mock_analysis.rs +++ b/crates/ra_ide_api/src/mock_analysis.rs @@ -2,6 +2,7 @@ use std::sync::Arc; +use ra_cfg::CfgOptions; use relative_path::RelativePathBuf; use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; @@ -93,10 +94,12 @@ impl MockAnalysis { assert!(path.starts_with('/')); let path = RelativePathBuf::from_path(&path[1..]).unwrap(); let file_id = FileId(i as u32 + 1); + // FIXME: cfg options + let cfg_options = CfgOptions::default(); if path == "/lib.rs" || path == "/main.rs" { - root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018)); + root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018, cfg_options)); } else if path.ends_with("/lib.rs") { - let other_crate = crate_graph.add_crate_root(file_id, Edition2018); + let other_crate = crate_graph.add_crate_root(file_id, Edition2018, cfg_options); let crate_name = path.parent().unwrap().file_name().unwrap(); if let Some(root_crate) = root_crate { crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap(); diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index c85f1d0d0..566509849 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs @@ -41,6 +41,7 @@ mod tests { AnalysisChange, CrateGraph, Edition::Edition2018, }; + use ra_cfg::CfgOptions; #[test] fn test_resolve_parent_module() { @@ -88,7 +89,7 @@ mod tests { assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); let mut crate_graph = CrateGraph::default(); - let crate_id = crate_graph.add_crate_root(root_file, Edition2018); + let crate_id = crate_graph.add_crate_root(root_file, Edition2018, CfgOptions::default()); let mut change = AnalysisChange::new(); change.set_crate_graph(crate_graph); host.apply_change(change); -- cgit v1.2.3