From db151763d42c725685bb9e86a16fa2b6cb7a64c7 Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Fri, 10 Jan 2020 20:35:23 +0100 Subject: Fix file_structure() to recognize macro_rules! where first token != "macro_rules" --- crates/ra_ide/src/display/structure.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs index a80d65ac7..be21fa913 100644 --- a/crates/ra_ide/src/display/structure.rs +++ b/crates/ra_ide/src/display/structure.rs @@ -151,10 +151,24 @@ fn structure_node(node: &SyntaxNode) -> Option { Some(node) }, ast::MacroCall(it) => { - let first_token = it.syntax().first_token().unwrap(); - if first_token.text().as_str() != "macro_rules" { - return None; + 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; + } } + decl(it) }, _ => None, -- cgit v1.2.3 From c6655c67d2091b49a10512bfeab631d5f8a09d4b Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Fri, 10 Jan 2020 21:49:46 +0100 Subject: Added test for file_structure unidentified macro definition --- crates/ra_ide/src/display/structure.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs index be21fa913..8bdb971fe 100644 --- a/crates/ra_ide/src/display/structure.rs +++ b/crates/ra_ide/src/display/structure.rs @@ -212,6 +212,11 @@ macro_rules! mc { () => {} } +#[macro_export] +macro_rules! mcexp { + () => {} +} + #[deprecated] fn obsolete() {} @@ -386,11 +391,20 @@ fn very_obsolete() {} detail: None, deprecated: false, }, + StructureNode { + parent: None, + label: "mcexp", + navigation_range: [334; 339), + node_range: [305; 356), + kind: MACRO_CALL, + detail: None, + deprecated: false, + }, StructureNode { parent: None, label: "obsolete", - navigation_range: [322; 330), - node_range: [305; 335), + navigation_range: [375; 383), + node_range: [358; 388), kind: FN_DEF, detail: Some( "fn()", @@ -400,8 +414,8 @@ fn very_obsolete() {} StructureNode { parent: None, label: "very_obsolete", - navigation_range: [375; 388), - node_range: [337; 393), + navigation_range: [428; 441), + node_range: [390; 446), kind: FN_DEF, detail: Some( "fn()", -- cgit v1.2.3 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(-) (limited to 'crates') 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 From 20b8d283ae7d18faaa8aec86e029a573e755a1dd Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Sun, 12 Jan 2020 15:23:04 +0100 Subject: Remove hir usage from macro_rules! detection in structure_node() --- crates/ra_hir/src/lib.rs | 3 +-- crates/ra_ide/src/display/structure.rs | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 94da70cca..3d13978d4 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -58,7 +58,6 @@ pub use hir_def::{ type_ref::Mutability, }; pub use hir_expand::{ - name::name, name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, - MacroFile, Origin, + 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 fdd589648..944cc79df 100644 --- a/crates/ra_ide/src/display/structure.rs +++ b/crates/ra_ide/src/display/structure.rs @@ -2,7 +2,6 @@ use crate::TextRange; -use hir::{name, AsName, Path}; use ra_syntax::{ ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, @@ -152,9 +151,8 @@ fn structure_node(node: &SyntaxNode) -> Option { Some(node) }, ast::MacroCall(it) => { - 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() + match it.path().and_then(|it| it.segment()).and_then(|it| it.name_ref()) { + Some(path_segment) if path_segment.text() == "macro_rules" => decl(it), _ => None, } -- cgit v1.2.3