mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 01:38:13 +00:00
implement path conversion
This commit is contained in:
parent
bcdcfa9df2
commit
8086107b6a
1 changed files with 44 additions and 1 deletions
|
@ -136,7 +136,50 @@ impl InputModuleItems {
|
|||
}
|
||||
|
||||
fn convert_path(prefix: Option<Path>, path: ast::Path) -> Option<Path> {
|
||||
prefix
|
||||
let prefix = if let Some(qual) = path.qualifier() {
|
||||
Some(convert_path(prefix, qual)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let segment = path.segment()?;
|
||||
let res = match segment.kind()? {
|
||||
ast::PathSegmentKind::Name(name) => {
|
||||
let mut res = prefix.unwrap_or_else(|| Path {
|
||||
kind: PathKind::Abs,
|
||||
segments: Vec::with_capacity(1),
|
||||
});
|
||||
res.segments.push(name.text());
|
||||
res
|
||||
}
|
||||
ast::PathSegmentKind::CrateKw => {
|
||||
if prefix.is_some() {
|
||||
return None;
|
||||
}
|
||||
Path {
|
||||
kind: PathKind::Crate,
|
||||
segments: Vec::new(),
|
||||
}
|
||||
}
|
||||
ast::PathSegmentKind::SelfKw => {
|
||||
if prefix.is_some() {
|
||||
return None;
|
||||
}
|
||||
Path {
|
||||
kind: PathKind::Self_,
|
||||
segments: Vec::new(),
|
||||
}
|
||||
}
|
||||
ast::PathSegmentKind::SuperKw => {
|
||||
if prefix.is_some() {
|
||||
return None;
|
||||
}
|
||||
Path {
|
||||
kind: PathKind::Super,
|
||||
segments: Vec::new(),
|
||||
}
|
||||
}
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
|
||||
impl ModuleItem {
|
||||
|
|
Loading…
Reference in a new issue