From 08b0c92105fc9a0139a30f8215c7ca44e55ac7b0 Mon Sep 17 00:00:00 2001 From: btwotwo <10519967+btwotwo@users.noreply.github.com> Date: Thu, 6 Oct 2022 16:26:49 +0200 Subject: [PATCH] Add helper method to get a macro name from passed string --- crates/ide-db/src/syntax_helpers/node_ext.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/ide-db/src/syntax_helpers/node_ext.rs b/crates/ide-db/src/syntax_helpers/node_ext.rs index b890e2b58d..78d6bd008a 100644 --- a/crates/ide-db/src/syntax_helpers/node_ext.rs +++ b/crates/ide-db/src/syntax_helpers/node_ext.rs @@ -2,8 +2,8 @@ use itertools::Itertools; use parser::T; use syntax::{ - ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind}, - AstNode, Preorder, RustLanguage, WalkEvent, + ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind, NameRef}, + AstNode, Preorder, RustLanguage, WalkEvent, AstToken, }; pub fn expr_as_name_ref(expr: &ast::Expr) -> Option { @@ -457,3 +457,10 @@ pub fn parse_tt_as_comma_sep_paths(input: ast::TokenTree) -> Option Option { + let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?; + let name = macro_call.path()?.segment()?.name_ref()?; + + Some(name) +} \ No newline at end of file