Add support for environment to CrateGraph

This commit is contained in:
Aleksey Kladov 2019-11-22 13:55:03 +03:00
parent 5be7bd605a
commit 2c48fa087b
7 changed files with 79 additions and 28 deletions

View file

@ -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);

View file

@ -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();

View file

@ -34,12 +34,14 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
#[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);