From 2c48fa087b6cc79ebfd81af9daf4a07d8019fd67 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 13:55:03 +0300 Subject: Add support for environment to CrateGraph --- crates/ra_ide_api/src/lib.rs | 4 ++-- crates/ra_ide_api/src/mock_analysis.rs | 12 +++++++++--- crates/ra_ide_api/src/parent_module.rs | 11 +++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 62ad996bc..cb6c24eaa 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -54,7 +54,7 @@ use std::sync::Arc; use ra_cfg::CfgOptions; use ra_db::{ salsa::{self, ParallelDatabase}, - CheckCanceled, FileLoader, SourceDatabase, + CheckCanceled, Env, FileLoader, SourceDatabase, }; use ra_syntax::{SourceFile, TextRange, TextUnit}; @@ -240,7 +240,7 @@ impl Analysis { // Default to enable test for single file. let mut cfg_options = CfgOptions::default(); cfg_options.insert_atom("test".into()); - crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); + crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options, Env::default()); 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 2b1c96dbf..bf8a54932 100644 --- a/crates/ra_ide_api/src/mock_analysis.rs +++ b/crates/ra_ide_api/src/mock_analysis.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use ra_cfg::CfgOptions; -use ra_db::RelativePathBuf; +use ra_db::{Env, RelativePathBuf}; use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; use crate::{ @@ -96,9 +96,15 @@ impl MockAnalysis { let file_id = FileId(i as u32 + 1); let cfg_options = CfgOptions::default(); if path == "/lib.rs" || path == "/main.rs" { - root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018, cfg_options)); + root_crate = Some(crate_graph.add_crate_root( + file_id, + Edition2018, + cfg_options, + Env::default(), + )); } else if path.ends_with("/lib.rs") { - let other_crate = crate_graph.add_crate_root(file_id, Edition2018, cfg_options); + let other_crate = + crate_graph.add_crate_root(file_id, Edition2018, cfg_options, Env::default()); 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 fa232a379..6027e7d54 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs @@ -34,12 +34,14 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec { #[cfg(test)] mod tests { + use ra_cfg::CfgOptions; + use ra_db::Env; + use crate::{ mock_analysis::{analysis_and_position, MockAnalysis}, AnalysisChange, CrateGraph, Edition::Edition2018, }; - use ra_cfg::CfgOptions; #[test] fn test_resolve_parent_module() { @@ -87,7 +89,12 @@ 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, CfgOptions::default()); + let crate_id = crate_graph.add_crate_root( + root_file, + Edition2018, + CfgOptions::default(), + Env::default(), + ); let mut change = AnalysisChange::new(); change.set_crate_graph(crate_graph); host.apply_change(change); -- cgit v1.2.3