aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/call_info.rs17
-rw-r--r--crates/ra_syntax/src/lib.rs14
2 files changed, 22 insertions, 9 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs
index e494f5620..3572825b5 100644
--- a/crates/ra_ide_api/src/call_info.rs
+++ b/crates/ra_ide_api/src/call_info.rs
@@ -4,7 +4,7 @@ use ra_db::SourceDatabase;
4use ra_syntax::{ 4use ra_syntax::{
5 algo::ancestors_at_offset, 5 algo::ancestors_at_offset,
6 ast::{self, ArgListOwner}, 6 ast::{self, ArgListOwner},
7 AstNode, SyntaxNode, TextUnit, 7 match_ast, AstNode, SyntaxNode, TextUnit,
8}; 8};
9use test_utils::tested_by; 9use test_utils::tested_by;
10 10
@@ -91,14 +91,13 @@ enum FnCallNode {
91impl FnCallNode { 91impl FnCallNode {
92 fn with_node(syntax: &SyntaxNode, offset: TextUnit) -> Option<FnCallNode> { 92 fn with_node(syntax: &SyntaxNode, offset: TextUnit) -> Option<FnCallNode> {
93 ancestors_at_offset(syntax, offset).find_map(|node| { 93 ancestors_at_offset(syntax, offset).find_map(|node| {
94 if let Some(expr) = ast::CallExpr::cast(node.clone()) { 94 match_ast! {
95 Some(FnCallNode::CallExpr(expr)) 95 match node {
96 } else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) { 96 ast::CallExpr(it) => { Some(FnCallNode::CallExpr(it)) },
97 Some(FnCallNode::MethodCallExpr(expr)) 97 ast::MethodCallExpr(it) => { Some(FnCallNode::MethodCallExpr(it)) },
98 } else if let Some(expr) = ast::MacroCall::cast(node) { 98 ast::MacroCall(it) => { Some(FnCallNode::MacroCallExpr(it)) },
99 Some(FnCallNode::MacroCallExpr(expr)) 99 _ => { None },
100 } else { 100 }
101 None
102 } 101 }
103 }) 102 })
104 } 103 }
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index c315ba552..5dcb6a95a 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -160,6 +160,20 @@ impl SourceFile {
160 } 160 }
161} 161}
162 162
163/// Matches a `SyntaxNode` against an `ast` type.
164///
165/// # Example:
166///
167/// ```ignore
168/// match_ast! {
169/// match node {
170/// ast::CallExpr(it) => { ... },
171/// ast::MethodCallExpr(it) => { ... },
172/// ast::MacroCall(it) => { ... },
173/// _ => None,
174/// }
175/// }
176/// ```
163#[macro_export] 177#[macro_export]
164macro_rules! match_ast { 178macro_rules! match_ast {
165 (match $node:ident { 179 (match $node:ident {