aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-09 14:02:11 +0100
committerLukas Wirth <[email protected]>2021-06-09 14:02:11 +0100
commit3c40b15d625df192eb17c34f15f7dbc23f5284b9 (patch)
treef3fd6dd1072a5a8bdd7145c0f1fc3258752badb2
parent590472607c9629fdd37e3f6f33dacfdc2a3f56cc (diff)
Don't descend MacroCall TokenTree delimiters
-rw-r--r--crates/hir/src/semantics.rs12
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlighting.html5
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs5
3 files changed, 20 insertions, 2 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 2d08a7704..c437dbdc6 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -17,7 +17,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
17use syntax::{ 17use syntax::{
18 algo::find_node_at_offset, 18 algo::find_node_at_offset,
19 ast::{self, GenericParamsOwner, LoopBodyOwner}, 19 ast::{self, GenericParamsOwner, LoopBodyOwner},
20 match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextSize, 20 match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize,
21}; 21};
22 22
23use crate::{ 23use crate::{
@@ -394,7 +394,15 @@ impl<'db> SemanticsImpl<'db> {
394 match node { 394 match node {
395 ast::MacroCall(macro_call) => { 395 ast::MacroCall(macro_call) => {
396 let tt = macro_call.token_tree()?; 396 let tt = macro_call.token_tree()?;
397 if !tt.syntax().text_range().contains_range(token.value.text_range()) { 397 let l_delim = match tt.left_delimiter_token() {
398 Some(it) => it.text_range().end(),
399 None => tt.syntax().text_range().start()
400 };
401 let r_delim = match tt.right_delimiter_token() {
402 Some(it) => it.text_range().start(),
403 None => tt.syntax().text_range().end()
404 };
405 if !TextRange::new(l_delim, r_delim).contains_range(token.value.text_range()) {
398 return None; 406 return None;
399 } 407 }
400 let file_id = sa.expand(self.db, token.with_value(&macro_call))?; 408 let file_id = sa.expand(self.db, token.with_value(&macro_call))?;
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
index 0264e39a3..a7b5c3b89 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
@@ -148,6 +148,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
148 <span class="brace">}</span> 148 <span class="brace">}</span>
149<span class="brace">}</span> 149<span class="brace">}</span>
150 150
151<span class="keyword">macro_rules</span><span class="punctuation">!</span> <span class="macro declaration">dont_color_me_braces</span> <span class="brace">{</span>
152 <span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="brace">{</span><span class="numeric_literal">0</span><span class="brace">}</span>
153<span class="brace">}</span>
154
151<span class="keyword">macro_rules</span><span class="punctuation">!</span> <span class="macro declaration">noop</span> <span class="brace">{</span> 155<span class="keyword">macro_rules</span><span class="punctuation">!</span> <span class="macro declaration">noop</span> <span class="brace">{</span>
152 <span class="parenthesis">(</span><span class="punctuation">$</span>expr<span class="colon">:</span>expr<span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="brace">{</span> 156 <span class="parenthesis">(</span><span class="punctuation">$</span>expr<span class="colon">:</span>expr<span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="brace">{</span>
153 <span class="punctuation">$</span>expr 157 <span class="punctuation">$</span>expr
@@ -171,6 +175,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
171<span class="comment">// comment</span> 175<span class="comment">// comment</span>
172<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> 176<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
173 <span class="macro">println!</span><span class="parenthesis">(</span><span class="string_literal">"Hello, {}!"</span><span class="comma">,</span> <span class="numeric_literal">92</span><span class="parenthesis">)</span><span class="semicolon">;</span> 177 <span class="macro">println!</span><span class="parenthesis">(</span><span class="string_literal">"Hello, {}!"</span><span class="comma">,</span> <span class="numeric_literal">92</span><span class="parenthesis">)</span><span class="semicolon">;</span>
178 <span class="macro">dont_color_me_braces!</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
174 179
175 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">vec</span> <span class="operator">=</span> <span class="unresolved_reference">Vec</span><span class="operator">::</span><span class="unresolved_reference">new</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> 180 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">vec</span> <span class="operator">=</span> <span class="unresolved_reference">Vec</span><span class="operator">::</span><span class="unresolved_reference">new</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
176 <span class="keyword control">if</span> <span class="bool_literal">true</span> <span class="brace">{</span> 181 <span class="keyword control">if</span> <span class="bool_literal">true</span> <span class="brace">{</span>
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index 662b53481..6ad2a362a 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -122,6 +122,10 @@ def_fn! {
122 } 122 }
123} 123}
124 124
125macro_rules! dont_color_me_braces {
126 () => {0}
127}
128
125macro_rules! noop { 129macro_rules! noop {
126 ($expr:expr) => { 130 ($expr:expr) => {
127 $expr 131 $expr
@@ -145,6 +149,7 @@ macro without_args {
145// comment 149// comment
146fn main() { 150fn main() {
147 println!("Hello, {}!", 92); 151 println!("Hello, {}!", 92);
152 dont_color_me_braces!();
148 153
149 let mut vec = Vec::new(); 154 let mut vec = Vec::new();
150 if true { 155 if true {