Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22397 from ChayimFriedman2/mac-call-path
fix: Do not consider the path of the macro in a macro call to be inside a macro call
A4-Tacks 2 weeks ago
parent 4ee433d · parent d1488ee · commit f4bd646
-rw-r--r--crates/hir/src/semantics.rs7
-rw-r--r--crates/ide-completion/src/tests/expression.rs33
2 files changed, 39 insertions, 1 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index d0202c1054..562c78809a 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 c26c4c2ff8..e2baf42848 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
+ "#]],
+ );
+}