aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-09 14:17:38 +0100
committerGitHub <[email protected]>2021-06-09 14:17:38 +0100
commit5f592f4f58a6e1e1db0f920af34a2f569b65017c (patch)
tree00417f2fa52662fd1525b695d2d07642f9c6ba7d
parentcc7cfc5d3d7777524a9e8a94da3f5f2dd455fc0a (diff)
parent3c40b15d625df192eb17c34f15f7dbc23f5284b9 (diff)
Merge #9191
9191: fix: Don't descend MacroCall TokenTree delimiters r=jonas-schievink a=Veykril Fixes #9190 Co-authored-by: Lukas Wirth <[email protected]>
-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 827e23e2b..d522d5245 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::{
@@ -395,7 +395,15 @@ impl<'db> SemanticsImpl<'db> {
395 match node { 395 match node {
396 ast::MacroCall(macro_call) => { 396 ast::MacroCall(macro_call) => {
397 let tt = macro_call.token_tree()?; 397 let tt = macro_call.token_tree()?;
398 if !tt.syntax().text_range().contains_range(token.value.text_range()) { 398 let l_delim = match tt.left_delimiter_token() {
399 Some(it) => it.text_range().end(),
400 None => tt.syntax().text_range().start()
401 };
402 let r_delim = match tt.right_delimiter_token() {
403 Some(it) => it.text_range().start(),
404 None => tt.syntax().text_range().end()
405 };
406 if !TextRange::new(l_delim, r_delim).contains_range(token.value.text_range()) {
399 return None; 407 return None;
400 } 408 }
401 let file_id = sa.expand(self.db, token.with_value(&macro_call))?; 409 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 {