mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Add helper method to get a macro name from passed string
This commit is contained in:
parent
07621ce096
commit
08b0c92105
1 changed files with 9 additions and 2 deletions
|
@ -2,8 +2,8 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use parser::T;
|
use parser::T;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind},
|
ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind, NameRef},
|
||||||
AstNode, Preorder, RustLanguage, WalkEvent,
|
AstNode, Preorder, RustLanguage, WalkEvent, AstToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn expr_as_name_ref(expr: &ast::Expr) -> Option<ast::NameRef> {
|
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
|
||||||
.collect();
|
.collect();
|
||||||
Some(paths)
|
Some(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_outer_macro_name(string: &ast::String) -> Option<NameRef> {
|
||||||
|
let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
|
||||||
|
let name = macro_call.path()?.segment()?.name_ref()?;
|
||||||
|
|
||||||
|
Some(name)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue