3677: Add support for macro in symbol_index r=kjeremy a=edwin0cheng

This PR allows macro showing up in `Open symbol` search:

![show_macro](https://user-images.githubusercontent.com/11014119/77244297-548d0b80-6c4e-11ea-8613-15926cc297b3.png)


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
bors[bot] 2020-03-22 14:50:42 +00:00 committed by GitHub
commit 9328aba706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 12 deletions

View File

@ -453,7 +453,7 @@ impl ExprCollector<'_> {
}
}
ast::Expr::MacroCall(e) => {
if let Some(name) = is_macro_rules(&e) {
if let Some(name) = e.is_macro_rules().map(|it| it.as_name()) {
let mac = MacroDefId {
krate: Some(self.expander.module.krate),
ast_id: Some(self.expander.ast_id(&e)),
@ -697,16 +697,6 @@ impl ExprCollector<'_> {
}
}
fn is_macro_rules(m: &ast::MacroCall) -> Option<Name> {
let name = m.path()?.segment()?.name_ref()?.as_name();
if name == name![macro_rules] {
Some(m.name()?.as_name())
} else {
None
}
}
impl From<ast::BinOp> for BinaryOp {
fn from(ast_op: ast::BinOp) -> Self {
match ast_op {

View File

@ -362,6 +362,13 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
ast::TypeAliasDef(it) => { decl(it) },
ast::ConstDef(it) => { decl(it) },
ast::StaticDef(it) => { decl(it) },
ast::MacroCall(it) => {
if it.is_macro_rules().is_some() {
decl(it)
} else {
None
}
},
_ => None,
}
}

View File

@ -4,7 +4,7 @@
use itertools::Itertools;
use crate::{
ast::{self, child_opt, children, AstNode, AttrInput, SyntaxNode},
ast::{self, child_opt, children, AstNode, AttrInput, NameOwner, SyntaxNode},
SmolStr, SyntaxElement,
SyntaxKind::*,
SyntaxToken, T,
@ -514,3 +514,14 @@ impl ast::Visibility {
self.syntax().children_with_tokens().any(|it| it.kind() == T![super])
}
}
impl ast::MacroCall {
pub fn is_macro_rules(&self) -> Option<ast::Name> {
let name_ref = self.path()?.segment()?.name_ref()?;
if name_ref.text() == "macro_rules" {
self.name()
} else {
None
}
}
}