File tree Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -1363,6 +1363,7 @@ impl HirDisplay for Type {
13631363}
13641364
13651365/// For IDE only
1366+ #[ derive( Debug ) ]
13661367pub enum ScopeDef {
13671368 ModuleDef ( ModuleDef ) ,
13681369 MacroDef ( MacroDef ) ,
Original file line number Diff line number Diff line change @@ -297,6 +297,42 @@ mod tests {
297297 ) ;
298298 }
299299
300+ #[ test]
301+ fn completes_bindings_from_for_with_in_prefix ( ) {
302+ mark:: check!( completes_bindings_from_for_with_in_prefix) ;
303+ assert_debug_snapshot ! (
304+ do_reference_completion(
305+ r"
306+ fn test() {
307+ for index in &[1, 2, 3] {
308+ let t = in<|>
309+ }
310+ }
311+ "
312+ ) ,
313+ @r###"
314+ [
315+ CompletionItem {
316+ label: "index",
317+ source_range: 107..107,
318+ delete: 107..107,
319+ insert: "index",
320+ kind: Binding,
321+ },
322+ CompletionItem {
323+ label: "test()",
324+ source_range: 107..107,
325+ delete: 107..107,
326+ insert: "test()$0",
327+ kind: Function,
328+ lookup: "test",
329+ detail: "fn test()",
330+ },
331+ ]
332+ "###
333+ ) ;
334+ }
335+
300336 #[ test]
301337 fn completes_generic_params ( ) {
302338 assert_debug_snapshot ! (
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use ra_syntax::{
1212use ra_text_edit:: Indel ;
1313
1414use crate :: { call_info:: ActiveParameter , completion:: CompletionConfig , FilePosition } ;
15+ use test_utils:: mark;
1516
1617/// `CompletionContext` is created early during completion to figure out, where
1718/// exactly is the cursor, syntax-wise.
@@ -169,7 +170,17 @@ impl<'a> CompletionContext<'a> {
169170 match self . token . kind ( ) {
170171 // workaroud when completion is triggered by trigger characters.
171172 IDENT => self . original_token . text_range ( ) ,
172- _ => TextRange :: empty ( self . offset ) ,
173+ _ => {
174+ // If we haven't characters between keyword and our cursor we take the keyword start range to edit
175+ if self . token . kind ( ) . is_keyword ( )
176+ && self . offset == self . original_token . text_range ( ) . end ( )
177+ {
178+ mark:: hit!( completes_bindings_from_for_with_in_prefix) ;
179+ TextRange :: empty ( self . original_token . text_range ( ) . start ( ) )
180+ } else {
181+ TextRange :: empty ( self . offset )
182+ }
183+ }
173184 }
174185 }
175186
You can’t perform that action at this time.
0 commit comments