mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Skip attrs in Literal::token
This commit is contained in:
parent
41c56c8a0d
commit
474a04615c
1 changed files with 17 additions and 2 deletions
|
@ -229,8 +229,11 @@ pub enum LiteralKind {
|
||||||
|
|
||||||
impl ast::Literal {
|
impl ast::Literal {
|
||||||
pub fn token(&self) -> SyntaxToken {
|
pub fn token(&self) -> SyntaxToken {
|
||||||
match self.syntax().first_child_or_token().unwrap() {
|
let elem = self.syntax()
|
||||||
SyntaxElement::Token(token) => token,
|
.children_with_tokens()
|
||||||
|
.find(|e| e.kind() != ATTR && !e.kind().is_trivia());
|
||||||
|
match elem {
|
||||||
|
Some(SyntaxElement::Token(token)) => token,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,6 +271,18 @@ impl ast::Literal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_literal_with_attr() {
|
||||||
|
let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#);
|
||||||
|
let lit = parse
|
||||||
|
.tree
|
||||||
|
.syntax()
|
||||||
|
.descendants()
|
||||||
|
.find_map(ast::Literal::cast)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(lit.token().text(), r#""Hello""#);
|
||||||
|
}
|
||||||
|
|
||||||
impl ast::NamedField {
|
impl ast::NamedField {
|
||||||
pub fn parent_struct_lit(&self) -> &ast::StructLit {
|
pub fn parent_struct_lit(&self) -> &ast::StructLit {
|
||||||
self.syntax().ancestors().find_map(ast::StructLit::cast).unwrap()
|
self.syntax().ancestors().find_map(ast::StructLit::cast).unwrap()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue