diff options
author | uHOOCCOOHu <[email protected]> | 2019-09-26 19:04:47 +0100 |
---|---|---|
committer | uHOOCCOOHu <[email protected]> | 2019-09-26 19:04:47 +0100 |
commit | 128dc5355b81b0217fede903ae79f75ba0124716 (patch) | |
tree | 7ded1337bc7a77c66098d4307a2d381cb9a1f3b2 /crates/ra_syntax | |
parent | 53a30d9e69ee5149e4fdb1c6fe4081281e879d0e (diff) |
Refactor `Name` ready for hygienic macro
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 10 |
1 files changed, 10 insertions, 0 deletions
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 { | |||
21 | pub fn text(&self) -> &SmolStr { | 21 | pub fn text(&self) -> &SmolStr { |
22 | text_of_first_token(self.syntax()) | 22 | text_of_first_token(self.syntax()) |
23 | } | 23 | } |
24 | |||
25 | pub fn as_tuple_field(&self) -> Option<usize> { | ||
26 | self.syntax().children_with_tokens().find_map(|c| { | ||
27 | if c.kind() == SyntaxKind::INT_NUMBER { | ||
28 | c.as_token().and_then(|tok| tok.text().as_str().parse().ok()) | ||
29 | } else { | ||
30 | None | ||
31 | } | ||
32 | }) | ||
33 | } | ||
24 | } | 34 | } |
25 | 35 | ||
26 | fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { | 36 | fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { |