mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Don't descend MacroCall TokenTree delimiters
This commit is contained in:
parent
590472607c
commit
3c40b15d62
3 changed files with 20 additions and 2 deletions
|
@ -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))?;
|
||||
|
|
|
@ -148,6 +148,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">macro_rules</span><span class="punctuation">!</span> <span class="macro declaration">dont_color_me_braces</span> <span class="brace">{</span>
|
||||
<span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="brace">{</span><span class="numeric_literal">0</span><span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">macro_rules</span><span class="punctuation">!</span> <span class="macro declaration">noop</span> <span class="brace">{</span>
|
||||
<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">></span> <span class="brace">{</span>
|
||||
<span class="punctuation">$</span>expr
|
||||
|
@ -171,6 +175,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="comment">// comment</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<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>
|
||||
<span class="macro">dont_color_me_braces!</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
|
||||
<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>
|
||||
<span class="keyword control">if</span> <span class="bool_literal">true</span> <span class="brace">{</span>
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue