Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
33 changes: 33 additions & 0 deletions crates/ide-completion/src/tests/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#]],
);
}
Loading