Skip to content

Commit 020c00e

Browse files
committed
Add some sanity checks
1 parent cbca4ef commit 020c00e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ impl<'a> CompletionContext<'a> {
115115
find_node_at_offset::<ast::MacroCall>(&original_file, offset),
116116
find_node_at_offset::<ast::MacroCall>(&hypothetical_file, offset),
117117
) {
118+
if actual_macro_call.path().as_ref().map(|s| s.syntax().text())
119+
!= macro_call_with_fake_ident.path().as_ref().map(|s| s.syntax().text())
120+
{
121+
break;
122+
}
118123
if let (Some(actual_expansion), Some(hypothetical_expansion)) = (
119124
ctx.sema.expand(&actual_macro_call),
120125
ctx.sema.expand_hypothetical(
@@ -123,11 +128,15 @@ impl<'a> CompletionContext<'a> {
123128
fake_ident_token,
124129
),
125130
) {
131+
let new_offset = hypothetical_expansion.1.text_range().start();
132+
if new_offset >= actual_expansion.text_range().end() {
133+
break;
134+
}
126135
// TODO check that the expansions 'look the same' up to the inserted token?
127136
original_file = actual_expansion;
128137
hypothetical_file = hypothetical_expansion.0;
129138
fake_ident_token = hypothetical_expansion.1;
130-
offset = fake_ident_token.text_range().start();
139+
offset = new_offset;
131140
} else {
132141
break;
133142
}

0 commit comments

Comments
 (0)