diff options
Diffstat (limited to 'crates/ide/src/expand_macro.rs')
-rw-r--r-- | crates/ide/src/expand_macro.rs | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index 12a091ac4..854d54b71 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs | |||
@@ -1,11 +1,8 @@ | |||
1 | use std::iter; | 1 | use std::iter; |
2 | 2 | ||
3 | use hir::Semantics; | 3 | use hir::Semantics; |
4 | use ide_db::RootDatabase; | 4 | use ide_db::{helpers::pick_best_token, RootDatabase}; |
5 | use syntax::{ | 5 | use syntax::{ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, SyntaxNode, WalkEvent, T}; |
6 | ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, SyntaxNode, SyntaxToken, | ||
7 | TokenAtOffset, WalkEvent, T, | ||
8 | }; | ||
9 | 6 | ||
10 | use crate::FilePosition; | 7 | use crate::FilePosition; |
11 | 8 | ||
@@ -29,7 +26,10 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option< | |||
29 | let sema = Semantics::new(db); | 26 | let sema = Semantics::new(db); |
30 | let file = sema.parse(position.file_id); | 27 | let file = sema.parse(position.file_id); |
31 | 28 | ||
32 | let tok = pick_best(file.syntax().token_at_offset(position.offset))?; | 29 | let tok = pick_best_token(file.syntax().token_at_offset(position.offset), |kind| match kind { |
30 | SyntaxKind::IDENT => 1, | ||
31 | _ => 0, | ||
32 | })?; | ||
33 | let mut expanded = None; | 33 | let mut expanded = None; |
34 | let mut name = None; | 34 | let mut name = None; |
35 | for node in tok.ancestors() { | 35 | for node in tok.ancestors() { |
@@ -57,16 +57,6 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option< | |||
57 | Some(ExpandedMacro { name: name?, expansion }) | 57 | Some(ExpandedMacro { name: name?, expansion }) |
58 | } | 58 | } |
59 | 59 | ||
60 | fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { | ||
61 | return tokens.max_by_key(priority); | ||
62 | fn priority(n: &SyntaxToken) -> usize { | ||
63 | match n.kind() { | ||
64 | IDENT => 1, | ||
65 | _ => 0, | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | |||
70 | fn expand_macro_recur( | 60 | fn expand_macro_recur( |
71 | sema: &Semantics<RootDatabase>, | 61 | sema: &Semantics<RootDatabase>, |
72 | macro_call: &ast::MacroCall, | 62 | macro_call: &ast::MacroCall, |