mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Add new_source_root meta to test fixtures
This commit is contained in:
parent
e97cd709cd
commit
75fafd6fcc
3 changed files with 28 additions and 7 deletions
|
@ -57,7 +57,7 @@
|
||||||
//! fn insert_source_code_here() {}
|
//! fn insert_source_code_here() {}
|
||||||
//! "
|
//! "
|
||||||
//! ```
|
//! ```
|
||||||
use std::{str::FromStr, sync::Arc};
|
use std::{mem, str::FromStr, sync::Arc};
|
||||||
|
|
||||||
use cfg::CfgOptions;
|
use cfg::CfgOptions;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
@ -148,6 +148,7 @@ impl ChangeFixture {
|
||||||
let mut file_set = FileSet::default();
|
let mut file_set = FileSet::default();
|
||||||
let source_root_prefix = "/".to_string();
|
let source_root_prefix = "/".to_string();
|
||||||
let mut file_id = FileId(0);
|
let mut file_id = FileId(0);
|
||||||
|
let mut roots = Vec::new();
|
||||||
|
|
||||||
let mut file_position = None;
|
let mut file_position = None;
|
||||||
|
|
||||||
|
@ -168,6 +169,10 @@ impl ChangeFixture {
|
||||||
let meta = FileMeta::from(entry);
|
let meta = FileMeta::from(entry);
|
||||||
assert!(meta.path.starts_with(&source_root_prefix));
|
assert!(meta.path.starts_with(&source_root_prefix));
|
||||||
|
|
||||||
|
if meta.introduce_new_source_root {
|
||||||
|
roots.push(SourceRoot::new_local(mem::take(&mut file_set)));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(krate) = meta.krate {
|
if let Some(krate) = meta.krate {
|
||||||
let crate_name = CrateName::normalize_dashes(&krate);
|
let crate_name = CrateName::normalize_dashes(&krate);
|
||||||
let crate_id = crate_graph.add_crate_root(
|
let crate_id = crate_graph.add_crate_root(
|
||||||
|
@ -215,7 +220,8 @@ impl ChangeFixture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
change.set_roots(vec![SourceRoot::new_local(file_set)]);
|
roots.push(SourceRoot::new_local(mem::take(&mut file_set)));
|
||||||
|
change.set_roots(roots);
|
||||||
change.set_crate_graph(crate_graph);
|
change.set_crate_graph(crate_graph);
|
||||||
|
|
||||||
ChangeFixture { file_position, files, change }
|
ChangeFixture { file_position, files, change }
|
||||||
|
@ -229,6 +235,7 @@ struct FileMeta {
|
||||||
cfg: CfgOptions,
|
cfg: CfgOptions,
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
env: Env,
|
env: Env,
|
||||||
|
introduce_new_source_root: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Fixture> for FileMeta {
|
impl From<Fixture> for FileMeta {
|
||||||
|
@ -247,6 +254,7 @@ impl From<Fixture> for FileMeta {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()),
|
.map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()),
|
||||||
env: f.env.into_iter().collect(),
|
env: f.env.into_iter().collect(),
|
||||||
|
introduce_new_source_root: f.introduce_new_source_root,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1275,13 +1275,13 @@ fn foo(_: bool) -> bo$0ol { true }
|
||||||
fn test_transitive() {
|
fn test_transitive() {
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
//- /level3/level3.rs crate:level3
|
//- /level3.rs new_source_root: crate:level3
|
||||||
pub struct Fo$0o;
|
pub struct Fo$0o;
|
||||||
//- /level2/level2.rs crate:level2 deps:level3
|
//- /level2.rs new_source_root: crate:level2 deps:level3
|
||||||
pub use level3::Foo;
|
pub use level3::Foo;
|
||||||
//- /level1/level1.rs crate:level1 deps:level2
|
//- /level1.rs new_source_root: crate:level1 deps:level2
|
||||||
pub use level2::Foo;
|
pub use level2::Foo;
|
||||||
//- /level0/level0.rs crate:level0 deps:level1
|
//- /level0.rs new_source_root: crate:level0 deps:level1
|
||||||
pub use level1::Foo;
|
pub use level1::Foo;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub struct Fixture {
|
||||||
pub cfg_key_values: Vec<(String, String)>,
|
pub cfg_key_values: Vec<(String, String)>,
|
||||||
pub edition: Option<String>,
|
pub edition: Option<String>,
|
||||||
pub env: FxHashMap<String, String>,
|
pub env: FxHashMap<String, String>,
|
||||||
|
pub introduce_new_source_root: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fixture {
|
impl Fixture {
|
||||||
|
@ -70,6 +71,7 @@ impl Fixture {
|
||||||
let mut cfg_atoms = Vec::new();
|
let mut cfg_atoms = Vec::new();
|
||||||
let mut cfg_key_values = Vec::new();
|
let mut cfg_key_values = Vec::new();
|
||||||
let mut env = FxHashMap::default();
|
let mut env = FxHashMap::default();
|
||||||
|
let mut introduce_new_source_root = false;
|
||||||
for component in components[1..].iter() {
|
for component in components[1..].iter() {
|
||||||
let (key, value) = split_once(component, ':').unwrap();
|
let (key, value) = split_once(component, ':').unwrap();
|
||||||
match key {
|
match key {
|
||||||
|
@ -91,11 +93,22 @@ impl Fixture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"new_source_root" => introduce_new_source_root = true,
|
||||||
_ => panic!("bad component: {:?}", component),
|
_ => panic!("bad component: {:?}", component),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Fixture { path, text: String::new(), krate, deps, cfg_atoms, cfg_key_values, edition, env }
|
Fixture {
|
||||||
|
path,
|
||||||
|
text: String::new(),
|
||||||
|
krate,
|
||||||
|
deps,
|
||||||
|
cfg_atoms,
|
||||||
|
cfg_key_values,
|
||||||
|
edition,
|
||||||
|
env,
|
||||||
|
introduce_new_source_root,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue