about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model.rs1
-rw-r--r--crates/ra_ide/src/completion/complete_unqualified_path.rs35
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs11
3 files changed, 46 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 840cfdfc823..7c015aa98a7 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -1363,6 +1363,7 @@ impl HirDisplay for Type {
 }
 
 /// For IDE only
+#[derive(Debug)]
 pub enum ScopeDef {
     ModuleDef(ModuleDef),
     MacroDef(MacroDef),
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs
index db791660a18..417a9200101 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 {
     }
 
     #[test]
+    fn completes_bindings_from_for_with_in_prefix() {
+        assert_debug_snapshot!(
+            do_reference_completion(
+                r"
+                fn test() {
+                    for index in &[1, 2, 3] {
+                        let t = in<|>
+                    }
+                }
+                "
+            ),
+            @r###"
+        [
+            CompletionItem {
+                label: "index",
+                source_range: 107..107,
+                delete: 107..107,
+                insert: "index",
+                kind: Binding,
+            },
+            CompletionItem {
+                label: "test()",
+                source_range: 107..107,
+                delete: 107..107,
+                insert: "test()$0",
+                kind: Function,
+                lookup: "test",
+                detail: "fn test()",
+            },
+        ]
+        "###
+        );
+    }
+
+    #[test]
     fn completes_generic_params() {
         assert_debug_snapshot!(
             do_reference_completion(
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index da336973c18..e8bf07d6eb4 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)
+                }
+            }
         }
     }