diff options
author | Benjamin Coenen <[email protected]> | 2020-05-24 15:47:35 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-05-24 15:47:35 +0100 |
commit | 0e814a3b5f5c7d034b0249cfb4391d9fcb9d8e42 (patch) | |
tree | f83cdc8f32c9a0110fc695f47b5df5a6868f50af /crates/ra_ide/src | |
parent | f4f5fca10175b8d5fdfa36563c103f81b2b0acd3 (diff) |
fix textedit range returned for completion when left token is a keyword #4545
Signed-off-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/completion/complete_unqualified_path.rs | 35 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 11 |
2 files changed, 45 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index db791660a..417a92001 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs | |||
@@ -298,6 +298,41 @@ mod tests { | |||
298 | } | 298 | } |
299 | 299 | ||
300 | #[test] | 300 | #[test] |
301 | fn completes_bindings_from_for_with_in_prefix() { | ||
302 | assert_debug_snapshot!( | ||
303 | do_reference_completion( | ||
304 | r" | ||
305 | fn test() { | ||
306 | for index in &[1, 2, 3] { | ||
307 | let t = in<|> | ||
308 | } | ||
309 | } | ||
310 | " | ||
311 | ), | ||
312 | @r###" | ||
313 | [ | ||
314 | CompletionItem { | ||
315 | label: "index", | ||
316 | source_range: 107..107, | ||
317 | delete: 107..107, | ||
318 | insert: "index", | ||
319 | kind: Binding, | ||
320 | }, | ||
321 | CompletionItem { | ||
322 | label: "test()", | ||
323 | source_range: 107..107, | ||
324 | delete: 107..107, | ||
325 | insert: "test()$0", | ||
326 | kind: Function, | ||
327 | lookup: "test", | ||
328 | detail: "fn test()", | ||
329 | }, | ||
330 | ] | ||
331 | "### | ||
332 | ); | ||
333 | } | ||
334 | |||
335 | #[test] | ||
301 | fn completes_generic_params() { | 336 | fn completes_generic_params() { |
302 | assert_debug_snapshot!( | 337 | assert_debug_snapshot!( |
303 | do_reference_completion( | 338 | do_reference_completion( |
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index da336973c..e8bf07d6e 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -169,7 +169,16 @@ impl<'a> CompletionContext<'a> { | |||
169 | match self.token.kind() { | 169 | match self.token.kind() { |
170 | // workaroud when completion is triggered by trigger characters. | 170 | // workaroud when completion is triggered by trigger characters. |
171 | IDENT => self.original_token.text_range(), | 171 | IDENT => self.original_token.text_range(), |
172 | _ => TextRange::empty(self.offset), | 172 | _ => { |
173 | // If we haven't characters between keyword and our cursor we take the keyword start range to edit | ||
174 | if self.token.kind().is_keyword() | ||
175 | && self.offset == self.original_token.text_range().end() | ||
176 | { | ||
177 | TextRange::empty(self.original_token.text_range().start()) | ||
178 | } else { | ||
179 | TextRange::empty(self.offset) | ||
180 | } | ||
181 | } | ||
173 | } | 182 | } |
174 | } | 183 | } |
175 | 184 | ||