From 0e814a3b5f5c7d034b0249cfb4391d9fcb9d8e42 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Sun, 24 May 2020 16:47:35 +0200 Subject: fix textedit range returned for completion when left token is a keyword #4545 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/completion/completion_context.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src/completion/completion_context.rs') 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> { match self.token.kind() { // workaroud when completion is triggered by trigger characters. IDENT => self.original_token.text_range(), - _ => TextRange::empty(self.offset), + _ => { + // If we haven't characters between keyword and our cursor we take the keyword start range to edit + if self.token.kind().is_keyword() + && self.offset == self.original_token.text_range().end() + { + TextRange::empty(self.original_token.text_range().start()) + } else { + TextRange::empty(self.offset) + } + } } } -- cgit v1.2.3 From 846cefa4917dc68a85b7b307be5d1890b83e1e2d Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Wed, 27 May 2020 15:15:19 +0200 Subject: fix textedit range returned for completion when left token is a keyword Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/completion/completion_context.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_ide/src/completion/completion_context.rs') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index e8bf07d6e..c4646b727 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -12,6 +12,7 @@ use ra_syntax::{ use ra_text_edit::Indel; use crate::{call_info::ActiveParameter, completion::CompletionConfig, FilePosition}; +use test_utils::mark; /// `CompletionContext` is created early during completion to figure out, where /// exactly is the cursor, syntax-wise. @@ -174,6 +175,7 @@ impl<'a> CompletionContext<'a> { if self.token.kind().is_keyword() && self.offset == self.original_token.text_range().end() { + mark::hit!(completes_bindings_from_for_with_in_prefix); TextRange::empty(self.original_token.text_range().start()) } else { TextRange::empty(self.offset) -- cgit v1.2.3