From d1488ee53e333cce364f3023d85ff1a0143e996e Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Mon, 18 May 2026 04:00:53 +0300 Subject: [PATCH] Do not consider the path of the macro in a macro call to be inside a macro call --- crates/hir/src/semantics.rs | 7 +++- crates/ide-completion/src/tests/expression.rs | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index d0202c1054c5..562c78809a6d 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -1088,7 +1088,12 @@ impl<'db> SemanticsImpl<'db> { /// That is, we strictly check if it lies inside the input of a macro call. pub fn is_inside_macro_call(&self, token @ InFile { value, .. }: InFile<&SyntaxToken>) -> bool { value.parent_ancestors().any(|ancestor| { - if ast::MacroCall::can_cast(ancestor.kind()) { + if let Some(macro_call) = ast::MacroCall::cast(ancestor.clone()) + // If this is the *path* of a macro, it's not inside the call. + && macro_call.path().is_none_or(|path| { + !path.syntax().text_range().contains_range(value.text_range()) + }) + { return true; } diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index c26c4c2ff846..e2baf42848b8 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -3928,3 +3928,36 @@ fn tryme(param: impl SubTrait) { "#]], ); } + +#[test] +fn can_complete_macro_path_inside_expansion() { + check( + r#" +macro_rules! bar { () => (); } +macro_rules! foo { ($i:ident) => { $i!() }; } +fn main() { + foo!(ba$0); +} + "#, + expect![[r#" + fn main() fn() + ma bar macro_rules! bar + ma foo macro_rules! foo + bt u32 u32 + kw const + kw crate:: + kw false + kw for + kw if + kw if let + kw loop + kw match + kw return + kw self:: + kw true + kw unsafe + kw while + kw while let + "#]], + ); +}