aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-22 10:55:03 +0000
committerAleksey Kladov <[email protected]>2019-11-22 10:57:25 +0000
commit2c48fa087b6cc79ebfd81af9daf4a07d8019fd67 (patch)
treed2d9cfb6f56cfe83b801d6e118e03051207f75a5 /crates/ra_ide_api/src
parent5be7bd605a09fafbc2bb91ebc3c4c3e35cf24110 (diff)
Add support for environment to CrateGraph
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/lib.rs4
-rw-r--r--crates/ra_ide_api/src/mock_analysis.rs12
-rw-r--r--crates/ra_ide_api/src/parent_module.rs11
3 files changed, 20 insertions, 7 deletions
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;
54use ra_cfg::CfgOptions; 54use ra_cfg::CfgOptions;
55use ra_db::{ 55use ra_db::{
56 salsa::{self, ParallelDatabase}, 56 salsa::{self, ParallelDatabase},
57 CheckCanceled, FileLoader, SourceDatabase, 57 CheckCanceled, Env, FileLoader, SourceDatabase,
58}; 58};
59use ra_syntax::{SourceFile, TextRange, TextUnit}; 59use ra_syntax::{SourceFile, TextRange, TextUnit};
60 60
@@ -240,7 +240,7 @@ impl Analysis {
240 // Default to enable test for single file. 240 // Default to enable test for single file.
241 let mut cfg_options = CfgOptions::default(); 241 let mut cfg_options = CfgOptions::default();
242 cfg_options.insert_atom("test".into()); 242 cfg_options.insert_atom("test".into());
243 crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); 243 crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options, Env::default());
244 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); 244 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text));
245 change.set_crate_graph(crate_graph); 245 change.set_crate_graph(crate_graph);
246 host.apply_change(change); 246 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 @@
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_cfg::CfgOptions; 5use ra_cfg::CfgOptions;
6use ra_db::RelativePathBuf; 6use ra_db::{Env, RelativePathBuf};
7use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; 7use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER};
8 8
9use crate::{ 9use crate::{
@@ -96,9 +96,15 @@ impl MockAnalysis {
96 let file_id = FileId(i as u32 + 1); 96 let file_id = FileId(i as u32 + 1);
97 let cfg_options = CfgOptions::default(); 97 let cfg_options = CfgOptions::default();
98 if path == "/lib.rs" || path == "/main.rs" { 98 if path == "/lib.rs" || path == "/main.rs" {
99 root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018, cfg_options)); 99 root_crate = Some(crate_graph.add_crate_root(
100 file_id,
101 Edition2018,
102 cfg_options,
103 Env::default(),
104 ));
100 } else if path.ends_with("/lib.rs") { 105 } else if path.ends_with("/lib.rs") {
101 let other_crate = crate_graph.add_crate_root(file_id, Edition2018, cfg_options); 106 let other_crate =
107 crate_graph.add_crate_root(file_id, Edition2018, cfg_options, Env::default());
102 let crate_name = path.parent().unwrap().file_name().unwrap(); 108 let crate_name = path.parent().unwrap().file_name().unwrap();
103 if let Some(root_crate) = root_crate { 109 if let Some(root_crate) = root_crate {
104 crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap(); 110 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<CrateId> {
34 34
35#[cfg(test)] 35#[cfg(test)]
36mod tests { 36mod tests {
37 use ra_cfg::CfgOptions;
38 use ra_db::Env;
39
37 use crate::{ 40 use crate::{
38 mock_analysis::{analysis_and_position, MockAnalysis}, 41 mock_analysis::{analysis_and_position, MockAnalysis},
39 AnalysisChange, CrateGraph, 42 AnalysisChange, CrateGraph,
40 Edition::Edition2018, 43 Edition::Edition2018,
41 }; 44 };
42 use ra_cfg::CfgOptions;
43 45
44 #[test] 46 #[test]
45 fn test_resolve_parent_module() { 47 fn test_resolve_parent_module() {
@@ -87,7 +89,12 @@ mod tests {
87 assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); 89 assert!(host.analysis().crate_for(mod_file).unwrap().is_empty());
88 90
89 let mut crate_graph = CrateGraph::default(); 91 let mut crate_graph = CrateGraph::default();
90 let crate_id = crate_graph.add_crate_root(root_file, Edition2018, CfgOptions::default()); 92 let crate_id = crate_graph.add_crate_root(
93 root_file,
94 Edition2018,
95 CfgOptions::default(),
96 Env::default(),
97 );
91 let mut change = AnalysisChange::new(); 98 let mut change = AnalysisChange::new();
92 change.set_crate_graph(crate_graph); 99 change.set_crate_graph(crate_graph);
93 host.apply_change(change); 100 host.apply_change(change);