From 020c00e44df1514b921669edc85129b37bce1610 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 7 Mar 2020 17:47:49 +0100 Subject: Add some sanity checks --- crates/ra_ide/src/completion/completion_context.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index ae3528f35..d173ef1f3 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -115,6 +115,11 @@ impl<'a> CompletionContext<'a> { find_node_at_offset::(&original_file, offset), find_node_at_offset::(&hypothetical_file, offset), ) { + if actual_macro_call.path().as_ref().map(|s| s.syntax().text()) + != macro_call_with_fake_ident.path().as_ref().map(|s| s.syntax().text()) + { + break; + } if let (Some(actual_expansion), Some(hypothetical_expansion)) = ( ctx.sema.expand(&actual_macro_call), ctx.sema.expand_hypothetical( @@ -123,11 +128,15 @@ impl<'a> CompletionContext<'a> { fake_ident_token, ), ) { + let new_offset = hypothetical_expansion.1.text_range().start(); + if new_offset >= actual_expansion.text_range().end() { + break; + } // TODO check that the expansions 'look the same' up to the inserted token? original_file = actual_expansion; hypothetical_file = hypothetical_expansion.0; fake_ident_token = hypothetical_expansion.1; - offset = fake_ident_token.text_range().start(); + offset = new_offset; } else { break; } -- cgit v1.2.3