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 {
1363
1363
}
1364
1364
1365
1365
/// For IDE only
1366
+ #[ derive( Debug ) ]
1366
1367
pub enum ScopeDef {
1367
1368
ModuleDef ( ModuleDef ) ,
1368
1369
MacroDef ( MacroDef ) ,
Original file line number Diff line number Diff line change @@ -297,6 +297,42 @@ mod tests {
297
297
) ;
298
298
}
299
299
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
+
300
336
#[ test]
301
337
fn completes_generic_params ( ) {
302
338
assert_debug_snapshot ! (
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use ra_syntax::{
12
12
use ra_text_edit:: Indel ;
13
13
14
14
use crate :: { call_info:: ActiveParameter , completion:: CompletionConfig , FilePosition } ;
15
+ use test_utils:: mark;
15
16
16
17
/// `CompletionContext` is created early during completion to figure out, where
17
18
/// exactly is the cursor, syntax-wise.
@@ -169,7 +170,17 @@ impl<'a> CompletionContext<'a> {
169
170
match self . token . kind ( ) {
170
171
// workaroud when completion is triggered by trigger characters.
171
172
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
+ }
173
184
}
174
185
}
175
186
You can’t perform that action at this time.
0 commit comments