mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Complete crate:: paths
This commit is contained in:
parent
9a7db8fa00
commit
69d07df201
10 changed files with 152 additions and 21 deletions
|
@ -232,6 +232,36 @@ impl<'a> IfExpr<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum PathSegmentKind<'a> {
|
||||
Name(NameRef<'a>),
|
||||
SelfKw,
|
||||
SuperKw,
|
||||
CrateKw,
|
||||
}
|
||||
|
||||
impl<'a> PathSegment<'a> {
|
||||
pub fn parent_path(self) -> Path<'a> {
|
||||
self.syntax().parent().and_then(Path::cast)
|
||||
.expect("segments are always nested in paths")
|
||||
}
|
||||
|
||||
pub fn kind(self) -> Option<PathSegmentKind<'a>> {
|
||||
let res = if let Some(name_ref) = self.name_ref() {
|
||||
PathSegmentKind::Name(name_ref)
|
||||
} else {
|
||||
match self.syntax().first_child()?.kind() {
|
||||
SELF_KW => PathSegmentKind::SelfKw,
|
||||
SUPER_KW => PathSegmentKind::SuperKw,
|
||||
CRATE_KW => PathSegmentKind::CrateKw,
|
||||
_ => return None,
|
||||
}
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
}
|
||||
|
||||
fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> {
|
||||
children(parent).next()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue