From 15c5426b54412134d3c5f2992e58e852266fc22e Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Sat, 11 Jan 2020 00:06:31 +0100 Subject: Use hir .path() and .name() to differentiate macro call and macro definition --- crates/ra_hir/src/lib.rs | 3 ++- crates/ra_ide/src/display/structure.rs | 46 ++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 3d13978d4..94da70cca 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -58,6 +58,7 @@ pub use hir_def::{ type_ref::Mutability, }; pub use hir_expand::{ - name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin, + name::name, name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, + MacroFile, Origin, }; pub use hir_ty::{display::HirDisplay, CallableDef}; diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs index 8bdb971fe..fdd589648 100644 --- a/crates/ra_ide/src/display/structure.rs +++ b/crates/ra_ide/src/display/structure.rs @@ -2,6 +2,7 @@ use crate::TextRange; +use hir::{name, AsName, Path}; use ra_syntax::{ ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, @@ -151,25 +152,12 @@ fn structure_node(node: &SyntaxNode) -> Option { Some(node) }, ast::MacroCall(it) => { - let macro_name = it.syntax() - .children() - .find(|c| - ![ - SyntaxKind::COMMENT, - SyntaxKind::WHITESPACE, - SyntaxKind::ATTR - ].iter() - .any(|&k| k == c.kind()) - ); - - match macro_name { - None => return None, - Some(n) => if n.first_token().unwrap().text().as_str() != "macro_rules" { - return None; - } + match it.path().and_then(|p| Path::from_ast(p)) { + Some(path) if path.mod_path().segments.as_slice() == [name![macro_rules]] + && it.name().map(|n| n.as_name()).is_some() + => decl(it), + _ => None, } - - decl(it) }, _ => None, } @@ -217,6 +205,11 @@ macro_rules! mcexp { () => {} } +/// Doc comment +macro_rules! mcexp { + () => {} +} + #[deprecated] fn obsolete() {} @@ -400,11 +393,20 @@ fn very_obsolete() {} detail: None, deprecated: false, }, + StructureNode { + parent: None, + label: "mcexp", + navigation_range: [387; 392), + node_range: [358; 409), + kind: MACRO_CALL, + detail: None, + deprecated: false, + }, StructureNode { parent: None, label: "obsolete", - navigation_range: [375; 383), - node_range: [358; 388), + navigation_range: [428; 436), + node_range: [411; 441), kind: FN_DEF, detail: Some( "fn()", @@ -414,8 +416,8 @@ fn very_obsolete() {} StructureNode { parent: None, label: "very_obsolete", - navigation_range: [428; 441), - node_range: [390; 446), + navigation_range: [481; 494), + node_range: [443; 499), kind: FN_DEF, detail: Some( "fn()", -- cgit v1.2.3