diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 2d08a7704f..c437dbdc69 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -17,7 +17,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use syntax::{ algo::find_node_at_offset, ast::{self, GenericParamsOwner, LoopBodyOwner}, - match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextSize, + match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize, }; use crate::{ @@ -394,7 +394,15 @@ impl<'db> SemanticsImpl<'db> { match node { ast::MacroCall(macro_call) => { let tt = macro_call.token_tree()?; - if !tt.syntax().text_range().contains_range(token.value.text_range()) { + let l_delim = match tt.left_delimiter_token() { + Some(it) => it.text_range().end(), + None => tt.syntax().text_range().start() + }; + let r_delim = match tt.right_delimiter_token() { + Some(it) => it.text_range().start(), + None => tt.syntax().text_range().end() + }; + if !TextRange::new(l_delim, r_delim).contains_range(token.value.text_range()) { return None; } let file_id = sa.expand(self.db, token.with_value(¯o_call))?; diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 0264e39a33..a7b5c3b895 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 } } +macro_rules! dont_color_me_braces { + () => {0} +} + macro_rules! noop { ($expr:expr) => { $expr @@ -171,6 +175,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd // comment fn main() { println!("Hello, {}!", 92); + dont_color_me_braces!(); let mut vec = Vec::new(); if true { diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 662b534813..6ad2a362a6 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -122,6 +122,10 @@ def_fn! { } } +macro_rules! dont_color_me_braces { + () => {0} +} + macro_rules! noop { ($expr:expr) => { $expr @@ -145,6 +149,7 @@ macro without_args { // comment fn main() { println!("Hello, {}!", 92); + dont_color_me_braces!(); let mut vec = Vec::new(); if true {