mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Merge #3677
3677: Add support for macro in symbol_index r=kjeremy a=edwin0cheng This PR allows macro showing up in `Open symbol` search:  Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
commit
9328aba706
@ -453,7 +453,7 @@ impl ExprCollector<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::Expr::MacroCall(e) => {
|
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 {
|
let mac = MacroDefId {
|
||||||
krate: Some(self.expander.module.krate),
|
krate: Some(self.expander.module.krate),
|
||||||
ast_id: Some(self.expander.ast_id(&e)),
|
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 {
|
impl From<ast::BinOp> for BinaryOp {
|
||||||
fn from(ast_op: ast::BinOp) -> Self {
|
fn from(ast_op: ast::BinOp) -> Self {
|
||||||
match ast_op {
|
match ast_op {
|
||||||
|
@ -362,6 +362,13 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
|
|||||||
ast::TypeAliasDef(it) => { decl(it) },
|
ast::TypeAliasDef(it) => { decl(it) },
|
||||||
ast::ConstDef(it) => { decl(it) },
|
ast::ConstDef(it) => { decl(it) },
|
||||||
ast::StaticDef(it) => { decl(it) },
|
ast::StaticDef(it) => { decl(it) },
|
||||||
|
ast::MacroCall(it) => {
|
||||||
|
if it.is_macro_rules().is_some() {
|
||||||
|
decl(it)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{self, child_opt, children, AstNode, AttrInput, SyntaxNode},
|
ast::{self, child_opt, children, AstNode, AttrInput, NameOwner, SyntaxNode},
|
||||||
SmolStr, SyntaxElement,
|
SmolStr, SyntaxElement,
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
SyntaxToken, T,
|
SyntaxToken, T,
|
||||||
@ -514,3 +514,14 @@ impl ast::Visibility {
|
|||||||
self.syntax().children_with_tokens().any(|it| it.kind() == T![super])
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user