Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 15c5426

Browse files
committed
Use hir .path() and .name() to differentiate
macro call and macro definition
1 parent c6655c6 commit 15c5426

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

crates/ra_hir/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub use hir_def::{
5858
type_ref::Mutability,
5959
};
6060
pub use hir_expand::{
61-
name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
61+
name::name, name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId,
62+
MacroFile, Origin,
6263
};
6364
pub use hir_ty::{display::HirDisplay, CallableDef};

crates/ra_ide/src/display/structure.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::TextRange;
44

5+
use hir::{name, AsName, Path};
56
use ra_syntax::{
67
ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner},
78
match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent,
@@ -151,25 +152,12 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
151152
Some(node)
152153
},
153154
ast::MacroCall(it) => {
154-
let macro_name = it.syntax()
155-
.children()
156-
.find(|c|
157-
![
158-
SyntaxKind::COMMENT,
159-
SyntaxKind::WHITESPACE,
160-
SyntaxKind::ATTR
161-
].iter()
162-
.any(|&k| k == c.kind())
163-
);
164-
165-
match macro_name {
166-
None => return None,
167-
Some(n) => if n.first_token().unwrap().text().as_str() != "macro_rules" {
168-
return None;
169-
}
155+
match it.path().and_then(|p| Path::from_ast(p)) {
156+
Some(path) if path.mod_path().segments.as_slice() == [name![macro_rules]]
157+
&& it.name().map(|n| n.as_name()).is_some()
158+
=> decl(it),
159+
_ => None,
170160
}
171-
172-
decl(it)
173161
},
174162
_ => None,
175163
}
@@ -217,6 +205,11 @@ macro_rules! mcexp {
217205
() => {}
218206
}
219207
208+
/// Doc comment
209+
macro_rules! mcexp {
210+
() => {}
211+
}
212+
220213
#[deprecated]
221214
fn obsolete() {}
222215
@@ -400,11 +393,20 @@ fn very_obsolete() {}
400393
detail: None,
401394
deprecated: false,
402395
},
396+
StructureNode {
397+
parent: None,
398+
label: "mcexp",
399+
navigation_range: [387; 392),
400+
node_range: [358; 409),
401+
kind: MACRO_CALL,
402+
detail: None,
403+
deprecated: false,
404+
},
403405
StructureNode {
404406
parent: None,
405407
label: "obsolete",
406-
navigation_range: [375; 383),
407-
node_range: [358; 388),
408+
navigation_range: [428; 436),
409+
node_range: [411; 441),
408410
kind: FN_DEF,
409411
detail: Some(
410412
"fn()",
@@ -414,8 +416,8 @@ fn very_obsolete() {}
414416
StructureNode {
415417
parent: None,
416418
label: "very_obsolete",
417-
navigation_range: [428; 441),
418-
node_range: [390; 446),
419+
navigation_range: [481; 494),
420+
node_range: [443; 499),
419421
kind: FN_DEF,
420422
detail: Some(
421423
"fn()",

0 commit comments

Comments
 (0)