Skip to content

Commit 08b0c92

Browse files
committed
Add helper method to get a macro name from passed string
1 parent 07621ce commit 08b0c92

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

crates/ide-db/src/syntax_helpers/node_ext.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
use itertools::Itertools;
33
use parser::T;
44
use syntax::{
5-
ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind},
6-
AstNode, Preorder, RustLanguage, WalkEvent,
5+
ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind, NameRef},
6+
AstNode, Preorder, RustLanguage, WalkEvent, AstToken,
77
};
88

99
pub fn expr_as_name_ref(expr: &ast::Expr) -> Option<ast::NameRef> {
@@ -457,3 +457,10 @@ pub fn parse_tt_as_comma_sep_paths(input: ast::TokenTree) -> Option<Vec<ast::Pat
457457
.collect();
458458
Some(paths)
459459
}
460+
461+
pub fn get_outer_macro_name(string: &ast::String) -> Option<NameRef> {
462+
let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
463+
let name = macro_call.path()?.segment()?.name_ref()?;
464+
465+
Some(name)
466+
}

0 commit comments

Comments
 (0)