diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/expand_macro.rs | 23 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 4 |
3 files changed, 12 insertions, 17 deletions
diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index be0ee03bf..eebae5ebe 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs | |||
@@ -3,9 +3,7 @@ use std::iter; | |||
3 | use hir::Semantics; | 3 | use hir::Semantics; |
4 | use ide_db::RootDatabase; | 4 | use ide_db::RootDatabase; |
5 | use syntax::{ | 5 | use syntax::{ |
6 | algo::{find_node_at_offset, SyntaxRewriter}, | 6 | algo::find_node_at_offset, ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, |
7 | ast, AstNode, NodeOrToken, SyntaxKind, | ||
8 | SyntaxKind::*, | ||
9 | SyntaxNode, WalkEvent, T, | 7 | SyntaxNode, WalkEvent, T, |
10 | }; | 8 | }; |
11 | 9 | ||
@@ -46,26 +44,23 @@ fn expand_macro_recur( | |||
46 | sema: &Semantics<RootDatabase>, | 44 | sema: &Semantics<RootDatabase>, |
47 | macro_call: &ast::MacroCall, | 45 | macro_call: &ast::MacroCall, |
48 | ) -> Option<SyntaxNode> { | 46 | ) -> Option<SyntaxNode> { |
49 | let mut expanded = sema.expand(macro_call)?; | 47 | let expanded = sema.expand(macro_call)?.clone_for_update(); |
50 | 48 | ||
51 | let children = expanded.descendants().filter_map(ast::MacroCall::cast); | 49 | let children = expanded.descendants().filter_map(ast::MacroCall::cast); |
52 | let mut rewriter = SyntaxRewriter::default(); | 50 | let mut replacements = Vec::new(); |
53 | 51 | ||
54 | for child in children.into_iter() { | 52 | for child in children { |
55 | if let Some(new_node) = expand_macro_recur(sema, &child) { | 53 | if let Some(new_node) = expand_macro_recur(sema, &child) { |
56 | // Replace the whole node if it is root | 54 | // check if the whole original syntax is replaced |
57 | // `replace_descendants` will not replace the parent node | ||
58 | // but `SyntaxNode::descendants include itself | ||
59 | if expanded == *child.syntax() { | 55 | if expanded == *child.syntax() { |
60 | expanded = new_node; | 56 | return Some(new_node); |
61 | } else { | ||
62 | rewriter.replace(child.syntax(), &new_node) | ||
63 | } | 57 | } |
58 | replacements.push((child, new_node)); | ||
64 | } | 59 | } |
65 | } | 60 | } |
66 | 61 | ||
67 | let res = rewriter.rewrite(&expanded); | 62 | replacements.into_iter().rev().for_each(|(old, new)| ted::replace(old.syntax(), new)); |
68 | Some(res) | 63 | Some(expanded) |
69 | } | 64 | } |
70 | 65 | ||
71 | // FIXME: It would also be cool to share logic here and in the mbe tests, | 66 | // FIXME: It would also be cool to share logic here and in the mbe tests, |
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 8cc877c1c..18552459b 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs | |||
@@ -222,7 +222,7 @@ pub(super) fn element( | |||
222 | T![>] | T![<] | T![==] | T![>=] | T![<=] | T![!=] | 222 | T![>] | T![<] | T![==] | T![>=] | T![<=] | T![!=] |
223 | if element.parent().and_then(ast::BinExpr::cast).is_some() => | 223 | if element.parent().and_then(ast::BinExpr::cast).is_some() => |
224 | { | 224 | { |
225 | HlTag::Operator(HlOperator::Comparision).into() | 225 | HlTag::Operator(HlOperator::Comparison).into() |
226 | } | 226 | } |
227 | _ if element.parent().and_then(ast::BinExpr::cast).is_some() => { | 227 | _ if element.parent().and_then(ast::BinExpr::cast).is_some() => { |
228 | HlTag::Operator(HlOperator::Other).into() | 228 | HlTag::Operator(HlOperator::Other).into() |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 8128d231d..e58392d67 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -96,7 +96,7 @@ pub enum HlOperator { | |||
96 | /// &&, ||, ! | 96 | /// &&, ||, ! |
97 | Logical, | 97 | Logical, |
98 | /// >, <, ==, >=, <=, != | 98 | /// >, <, ==, >=, <=, != |
99 | Comparision, | 99 | Comparison, |
100 | /// | 100 | /// |
101 | Other, | 101 | Other, |
102 | } | 102 | } |
@@ -151,7 +151,7 @@ impl HlTag { | |||
151 | HlOperator::Bitwise => "bitwise", | 151 | HlOperator::Bitwise => "bitwise", |
152 | HlOperator::Arithmetic => "arithmetic", | 152 | HlOperator::Arithmetic => "arithmetic", |
153 | HlOperator::Logical => "logical", | 153 | HlOperator::Logical => "logical", |
154 | HlOperator::Comparision => "comparision", | 154 | HlOperator::Comparison => "comparison", |
155 | HlOperator::Other => "operator", | 155 | HlOperator::Other => "operator", |
156 | }, | 156 | }, |
157 | HlTag::StringLiteral => "string_literal", | 157 | HlTag::StringLiteral => "string_literal", |