mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Refactor Name
ready for hygienic macro
This commit is contained in:
parent
53a30d9e69
commit
128dc5355b
4 changed files with 95 additions and 85 deletions
|
@ -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<usize> {
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue