Skip to content

Commit bb22a4e

Browse files
committed
Add support for macro in symbo_index
1 parent 6fe9564 commit bb22a4e

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

crates/ra_hir_def/src/body/lower.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ impl ExprCollector<'_> {
453453
}
454454
}
455455
ast::Expr::MacroCall(e) => {
456-
if let Some(name) = is_macro_rules(&e) {
456+
if let Some(name) = e.is_macro_rules().map(|it| it.as_name()) {
457457
let mac = MacroDefId {
458458
krate: Some(self.expander.module.krate),
459459
ast_id: Some(self.expander.ast_id(&e)),
@@ -697,16 +697,6 @@ impl ExprCollector<'_> {
697697
}
698698
}
699699

700-
fn is_macro_rules(m: &ast::MacroCall) -> Option<Name> {
701-
let name = m.path()?.segment()?.name_ref()?.as_name();
702-
703-
if name == name![macro_rules] {
704-
Some(m.name()?.as_name())
705-
} else {
706-
None
707-
}
708-
}
709-
710700
impl From<ast::BinOp> for BinaryOp {
711701
fn from(ast_op: ast::BinOp) -> Self {
712702
match ast_op {

crates/ra_ide_db/src/symbol_index.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
362362
ast::TypeAliasDef(it) => { decl(it) },
363363
ast::ConstDef(it) => { decl(it) },
364364
ast::StaticDef(it) => { decl(it) },
365+
ast::MacroCall(it) => {
366+
if it.is_macro_rules().is_some() {
367+
decl(it)
368+
} else {
369+
None
370+
}
371+
},
365372
_ => None,
366373
}
367374
}

crates/ra_syntax/src/ast/extensions.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use itertools::Itertools;
55

66
use crate::{
7-
ast::{self, child_opt, children, AstNode, AttrInput, SyntaxNode},
7+
ast::{self, child_opt, children, AstNode, AttrInput, NameOwner, SyntaxNode},
88
SmolStr, SyntaxElement,
99
SyntaxKind::*,
1010
SyntaxToken, T,
@@ -514,3 +514,14 @@ impl ast::Visibility {
514514
self.syntax().children_with_tokens().any(|it| it.kind() == T![super])
515515
}
516516
}
517+
518+
impl ast::MacroCall {
519+
pub fn is_macro_rules(&self) -> Option<ast::Name> {
520+
let name_ref = self.path()?.segment()?.name_ref()?;
521+
if name_ref.text() == "macro_rules" {
522+
self.name()
523+
} else {
524+
None
525+
}
526+
}
527+
}

0 commit comments

Comments
 (0)