aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-03-07 16:47:49 +0000
committerFlorian Diebold <[email protected]>2020-03-07 16:47:49 +0000
commit020c00e44df1514b921669edc85129b37bce1610 (patch)
treed354526ce5c22113da9f76e4bed797cfdfedacc0 /crates
parentcbca4effce148b1bdebd32556aaa19d13dd2a974 (diff)
Add some sanity checks
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs11
1 files changed, 10 insertions, 1 deletions
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> {
115 find_node_at_offset::<ast::MacroCall>(&original_file, offset), 115 find_node_at_offset::<ast::MacroCall>(&original_file, offset),
116 find_node_at_offset::<ast::MacroCall>(&hypothetical_file, offset), 116 find_node_at_offset::<ast::MacroCall>(&hypothetical_file, offset),
117 ) { 117 ) {
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 }
118 if let (Some(actual_expansion), Some(hypothetical_expansion)) = ( 123 if let (Some(actual_expansion), Some(hypothetical_expansion)) = (
119 ctx.sema.expand(&actual_macro_call), 124 ctx.sema.expand(&actual_macro_call),
120 ctx.sema.expand_hypothetical( 125 ctx.sema.expand_hypothetical(
@@ -123,11 +128,15 @@ impl<'a> CompletionContext<'a> {
123 fake_ident_token, 128 fake_ident_token,
124 ), 129 ),
125 ) { 130 ) {
131 let new_offset = hypothetical_expansion.1.text_range().start();
132 if new_offset >= actual_expansion.text_range().end() {
133 break;
134 }
126 // TODO check that the expansions 'look the same' up to the inserted token? 135 // TODO check that the expansions 'look the same' up to the inserted token?
127 original_file = actual_expansion; 136 original_file = actual_expansion;
128 hypothetical_file = hypothetical_expansion.0; 137 hypothetical_file = hypothetical_expansion.0;
129 fake_ident_token = hypothetical_expansion.1; 138 fake_ident_token = hypothetical_expansion.1;
130 offset = fake_ident_token.text_range().start(); 139 offset = new_offset;
131 } else { 140 } else {
132 break; 141 break;
133 } 142 }