mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 03:33:59 +00:00
Propogate fixture meta to AnalysisHost
Except crate name.
This commit is contained in:
parent
2dde9b1994
commit
2c00bd8c6a
@ -254,20 +254,14 @@ impl From<&FixtureMeta> for ParsedMeta {
|
||||
}
|
||||
FixtureMeta::File(f) => Self::File(FileMeta {
|
||||
path: f.path.to_owned().into(),
|
||||
krate: f.krate.to_owned().into(),
|
||||
krate: f.crate_name.to_owned().into(),
|
||||
deps: f.deps.to_owned(),
|
||||
cfg: f.cfg.to_owned(),
|
||||
edition: f
|
||||
.edition
|
||||
.as_ref()
|
||||
.map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()),
|
||||
env: {
|
||||
let mut env = Env::default();
|
||||
for (k, v) in &f.env {
|
||||
env.set(&k, v.to_owned());
|
||||
}
|
||||
env
|
||||
},
|
||||
env: Env::from(f.env.iter()),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -311,6 +311,21 @@ impl fmt::Display for Edition {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> From<T> for Env
|
||||
where
|
||||
T: Iterator<Item = (&'a String, &'a String)>,
|
||||
{
|
||||
fn from(iter: T) -> Self {
|
||||
let mut result = Self::default();
|
||||
|
||||
for (k, v) in iter {
|
||||
result.entries.insert(k.to_owned(), v.to_owned());
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Env {
|
||||
pub fn set(&mut self, env: &str, value: String) {
|
||||
self.entries.insert(env.to_owned(), value);
|
||||
|
@ -245,6 +245,35 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_hierarchy_in_tests_mod() {
|
||||
check_hierarchy(
|
||||
r#"
|
||||
//- /lib.rs cfg:test
|
||||
fn callee() {}
|
||||
fn caller1() {
|
||||
call<|>ee();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_caller() {
|
||||
callee();
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"callee FN_DEF FileId(1) 0..14 3..9",
|
||||
&[
|
||||
"caller1 FN_DEF FileId(1) 15..45 18..25 : [34..40]",
|
||||
"test_caller FN_DEF FileId(1) 93..147 108..119 : [132..138]",
|
||||
],
|
||||
&[],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_call_hierarchy_in_different_files() {
|
||||
check_hierarchy(
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_cfg::CfgOptions;
|
||||
@ -7,8 +8,8 @@ use ra_db::{CrateName, Env, RelativePathBuf};
|
||||
use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER};
|
||||
|
||||
use crate::{
|
||||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition::Edition2018, FileId, FilePosition,
|
||||
FileRange, SourceRootId,
|
||||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange,
|
||||
SourceRootId,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -46,6 +47,22 @@ impl MockFileData {
|
||||
_ => CfgOptions::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn edition(&self) -> Edition {
|
||||
match self {
|
||||
MockFileData::Fixture(f) => {
|
||||
f.meta.edition().map_or(Edition::Edition2018, |v| Edition::from_str(v).unwrap())
|
||||
}
|
||||
_ => Edition::Edition2018,
|
||||
}
|
||||
}
|
||||
|
||||
fn env(&self) -> Env {
|
||||
match self {
|
||||
MockFileData::Fixture(f) => Env::from(f.meta.env()),
|
||||
_ => Env::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FixtureEntry> for MockFileData {
|
||||
@ -153,13 +170,15 @@ impl MockAnalysis {
|
||||
let path = RelativePathBuf::from_path(&path[1..]).unwrap();
|
||||
let cfg_options = data.cfg_options();
|
||||
let file_id = FileId(i as u32 + 1);
|
||||
let edition = data.edition();
|
||||
let env = data.env();
|
||||
if path == "/lib.rs" || path == "/main.rs" {
|
||||
root_crate = Some(crate_graph.add_crate_root(
|
||||
file_id,
|
||||
Edition2018,
|
||||
edition,
|
||||
None,
|
||||
cfg_options,
|
||||
Env::default(),
|
||||
env,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
));
|
||||
@ -167,10 +186,10 @@ impl MockAnalysis {
|
||||
let crate_name = path.parent().unwrap().file_name().unwrap();
|
||||
let other_crate = crate_graph.add_crate_root(
|
||||
file_id,
|
||||
Edition2018,
|
||||
edition,
|
||||
Some(CrateName::new(crate_name).unwrap()),
|
||||
cfg_options,
|
||||
Env::default(),
|
||||
env,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
|
@ -174,7 +174,7 @@ pub enum FixtureMeta {
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct FileMeta {
|
||||
pub path: RelativePathBuf,
|
||||
pub krate: Option<String>,
|
||||
pub crate_name: Option<String>,
|
||||
pub deps: Vec<String>,
|
||||
pub cfg: CfgOptions,
|
||||
pub edition: Option<String>,
|
||||
@ -189,12 +189,52 @@ impl FixtureMeta {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn crate_name(&self) -> Option<&String> {
|
||||
match self {
|
||||
FixtureMeta::File(f) => f.crate_name.as_ref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cfg_options(&self) -> Option<&CfgOptions> {
|
||||
match self {
|
||||
FixtureMeta::File(f) => Some(&f.cfg),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn edition(&self) -> Option<&String> {
|
||||
match self {
|
||||
FixtureMeta::File(f) => f.edition.as_ref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn env(&self) -> impl Iterator<Item = (&String, &String)> {
|
||||
struct EnvIter<'a> {
|
||||
iter: Option<std::collections::hash_map::Iter<'a, String, String>>,
|
||||
}
|
||||
|
||||
impl<'a> EnvIter<'a> {
|
||||
fn new(meta: &'a FixtureMeta) -> Self {
|
||||
Self {
|
||||
iter: match meta {
|
||||
FixtureMeta::File(f) => Some(f.env.iter()),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for EnvIter<'a> {
|
||||
type Item = (&'a String, &'a String);
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.as_mut().and_then(|i| i.next())
|
||||
}
|
||||
}
|
||||
|
||||
EnvIter::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses text which looks like this:
|
||||
@ -289,7 +329,7 @@ fn parse_meta(meta: &str) -> FixtureMeta {
|
||||
}
|
||||
}
|
||||
|
||||
FixtureMeta::File(FileMeta { path, krate, deps, edition, cfg, env })
|
||||
FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env })
|
||||
}
|
||||
|
||||
fn split1(haystack: &str, delim: char) -> Option<(&str, &str)> {
|
||||
|
Loading…
Reference in New Issue
Block a user