mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-19 08:40:24 +00:00
Propogate fixture meta to AnalysisHost
Except crate name.
This commit is contained in:
parent
2dde9b1994
commit
2c00bd8c6a
5 changed files with 113 additions and 16 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue