From 128dc5355b81b0217fede903ae79f75ba0124716 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Fri, 27 Sep 2019 02:04:47 +0800 Subject: Refactor `Name` ready for hygienic macro --- crates/ra_syntax/src/ast/extensions.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 5f7e9f5b1..0433edb84 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -21,6 +21,16 @@ impl ast::NameRef { pub fn text(&self) -> &SmolStr { text_of_first_token(self.syntax()) } + + pub fn as_tuple_field(&self) -> Option { + self.syntax().children_with_tokens().find_map(|c| { + if c.kind() == SyntaxKind::INT_NUMBER { + c.as_token().and_then(|tok| tok.text().as_str().parse().ok()) + } else { + None + } + }) + } } fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { -- cgit v1.2.3