diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-26 19:33:54 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-26 19:33:54 +0000 |
commit | 9c9376c4cffdd171375fbb21dd3d0f71a97a335e (patch) | |
tree | 3b33ed158d1a3d520a4ed85e2eab0213c9dd41b3 /crates/syntax/src/ast | |
parent | 77a447dcda82a9f0eb6e1f04bd4b1dd53a226c65 (diff) | |
parent | 1bbac9053decfe235949acf33f9bc574b0ad1575 (diff) |
Merge #8209
8209: Add TokenText r=lnicola a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 6d7db5fb2..2772d7364 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs | |||
@@ -8,23 +8,23 @@ use parser::SyntaxKind; | |||
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | ast::{self, support, AstNode, AstToken, AttrsOwner, NameOwner, SyntaxNode}, | 10 | ast::{self, support, AstNode, AstToken, AttrsOwner, NameOwner, SyntaxNode}, |
11 | SmolStr, SyntaxElement, SyntaxToken, T, | 11 | SmolStr, SyntaxElement, SyntaxToken, TokenText, T, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | impl ast::Lifetime { | 14 | impl ast::Lifetime { |
15 | pub fn text(&self) -> SmolStr { | 15 | pub fn text(&self) -> TokenText { |
16 | text_of_first_token(self.syntax()) | 16 | text_of_first_token(self.syntax()) |
17 | } | 17 | } |
18 | } | 18 | } |
19 | 19 | ||
20 | impl ast::Name { | 20 | impl ast::Name { |
21 | pub fn text(&self) -> SmolStr { | 21 | pub fn text(&self) -> TokenText { |
22 | text_of_first_token(self.syntax()) | 22 | text_of_first_token(self.syntax()) |
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | impl ast::NameRef { | 26 | impl ast::NameRef { |
27 | pub fn text(&self) -> SmolStr { | 27 | pub fn text(&self) -> TokenText { |
28 | text_of_first_token(self.syntax()) | 28 | text_of_first_token(self.syntax()) |
29 | } | 29 | } |
30 | 30 | ||
@@ -33,8 +33,11 @@ impl ast::NameRef { | |||
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | fn text_of_first_token(node: &SyntaxNode) -> SmolStr { | 36 | fn text_of_first_token(node: &SyntaxNode) -> TokenText { |
37 | node.green().children().next().and_then(|it| it.into_token()).unwrap().text().into() | 37 | let first_token = |
38 | node.green().children().next().and_then(|it| it.into_token()).unwrap().to_owned(); | ||
39 | |||
40 | TokenText(first_token) | ||
38 | } | 41 | } |
39 | 42 | ||
40 | pub enum Macro { | 43 | pub enum Macro { |
@@ -376,7 +379,7 @@ impl fmt::Display for NameOrNameRef { | |||
376 | } | 379 | } |
377 | 380 | ||
378 | impl NameOrNameRef { | 381 | impl NameOrNameRef { |
379 | pub fn text(&self) -> SmolStr { | 382 | pub fn text(&self) -> TokenText { |
380 | match self { | 383 | match self { |
381 | NameOrNameRef::Name(name) => name.text(), | 384 | NameOrNameRef::Name(name) => name.text(), |
382 | NameOrNameRef::NameRef(name_ref) => name_ref.text(), | 385 | NameOrNameRef::NameRef(name_ref) => name_ref.text(), |