diff options
author | Aleksey Kladov <[email protected]> | 2018-10-24 16:37:25 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-24 16:37:25 +0100 |
commit | 69d07df201307fb7c539cdb20b8f1c1c12840386 (patch) | |
tree | 08cccd64582510ce2c82ceec729504a80e33f5b1 /crates/ra_syntax/src/ast/mod.rs | |
parent | 9a7db8fa009c612168ef16f6ed72315b5406ed09 (diff) |
Complete crate:: paths
Diffstat (limited to 'crates/ra_syntax/src/ast/mod.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/mod.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index 900426a8a..c033263a1 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs | |||
@@ -232,6 +232,36 @@ impl<'a> IfExpr<'a> { | |||
232 | } | 232 | } |
233 | } | 233 | } |
234 | 234 | ||
235 | |||
236 | #[derive(Debug, Clone, Copy)] | ||
237 | pub enum PathSegmentKind<'a> { | ||
238 | Name(NameRef<'a>), | ||
239 | SelfKw, | ||
240 | SuperKw, | ||
241 | CrateKw, | ||
242 | } | ||
243 | |||
244 | impl<'a> PathSegment<'a> { | ||
245 | pub fn parent_path(self) -> Path<'a> { | ||
246 | self.syntax().parent().and_then(Path::cast) | ||
247 | .expect("segments are always nested in paths") | ||
248 | } | ||
249 | |||
250 | pub fn kind(self) -> Option<PathSegmentKind<'a>> { | ||
251 | let res = if let Some(name_ref) = self.name_ref() { | ||
252 | PathSegmentKind::Name(name_ref) | ||
253 | } else { | ||
254 | match self.syntax().first_child()?.kind() { | ||
255 | SELF_KW => PathSegmentKind::SelfKw, | ||
256 | SUPER_KW => PathSegmentKind::SuperKw, | ||
257 | CRATE_KW => PathSegmentKind::CrateKw, | ||
258 | _ => return None, | ||
259 | } | ||
260 | }; | ||
261 | Some(res) | ||
262 | } | ||
263 | } | ||
264 | |||
235 | fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { | 265 | fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { |
236 | children(parent).next() | 266 | children(parent).next() |
237 | } | 267 | } |