aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/completions/trait_impl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/completions/trait_impl.rs')
-rw-r--r--crates/completion/src/completions/trait_impl.rs70
1 files changed, 35 insertions, 35 deletions
diff --git a/crates/completion/src/completions/trait_impl.rs b/crates/completion/src/completions/trait_impl.rs
index 54bb897e9..aa9c845da 100644
--- a/crates/completion/src/completions/trait_impl.rs
+++ b/crates/completion/src/completions/trait_impl.rs
@@ -15,7 +15,7 @@
15//! } 15//! }
16//! 16//!
17//! impl SomeTrait for () { 17//! impl SomeTrait for () {
18//! fn f<|> 18//! fn f$0
19//! } 19//! }
20//! ``` 20//! ```
21//! 21//!
@@ -27,7 +27,7 @@
27//! # } 27//! # }
28//! 28//!
29//! impl SomeTrait for () { 29//! impl SomeTrait for () {
30//! fn foo() {}<|> 30//! fn foo() {}$0
31//! } 31//! }
32//! ``` 32//! ```
33 33
@@ -82,7 +82,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
82 82
83fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, SyntaxNode, Impl)> { 83fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, SyntaxNode, Impl)> {
84 let mut token = ctx.token.clone(); 84 let mut token = ctx.token.clone();
85 // For keywork without name like `impl .. { fn <|> }`, the current position is inside 85 // For keywork without name like `impl .. { fn $0 }`, the current position is inside
86 // the whitespace token, which is outside `FN` syntax node. 86 // the whitespace token, which is outside `FN` syntax node.
87 // We need to follow the previous token in this case. 87 // We need to follow the previous token in this case.
88 if token.kind() == SyntaxKind::WHITESPACE { 88 if token.kind() == SyntaxKind::WHITESPACE {
@@ -90,20 +90,20 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Synt
90 } 90 }
91 91
92 let impl_item_offset = match token.kind() { 92 let impl_item_offset = match token.kind() {
93 // `impl .. { const <|> }` 93 // `impl .. { const $0 }`
94 // ERROR 0 94 // ERROR 0
95 // CONST_KW <- * 95 // CONST_KW <- *
96 SyntaxKind::CONST_KW => 0, 96 SyntaxKind::CONST_KW => 0,
97 // `impl .. { fn/type <|> }` 97 // `impl .. { fn/type $0 }`
98 // FN/TYPE_ALIAS 0 98 // FN/TYPE_ALIAS 0
99 // FN_KW <- * 99 // FN_KW <- *
100 SyntaxKind::FN_KW | SyntaxKind::TYPE_KW => 0, 100 SyntaxKind::FN_KW | SyntaxKind::TYPE_KW => 0,
101 // `impl .. { fn/type/const foo<|> }` 101 // `impl .. { fn/type/const foo$0 }`
102 // FN/TYPE_ALIAS/CONST 1 102 // FN/TYPE_ALIAS/CONST 1
103 // NAME 0 103 // NAME 0
104 // IDENT <- * 104 // IDENT <- *
105 SyntaxKind::IDENT if token.parent().kind() == SyntaxKind::NAME => 1, 105 SyntaxKind::IDENT if token.parent().kind() == SyntaxKind::NAME => 1,
106 // `impl .. { foo<|> }` 106 // `impl .. { foo$0 }`
107 // MACRO_CALL 3 107 // MACRO_CALL 3
108 // PATH 2 108 // PATH 2
109 // PATH_SEGMENT 1 109 // PATH_SEGMENT 1
@@ -120,7 +120,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Synt
120 // <item> 120 // <item>
121 let impl_def = ast::Impl::cast(impl_item.parent()?.parent()?)?; 121 let impl_def = ast::Impl::cast(impl_item.parent()?.parent()?)?;
122 let kind = match impl_item.kind() { 122 let kind = match impl_item.kind() {
123 // `impl ... { const <|> fn/type/const }` 123 // `impl ... { const $0 fn/type/const }`
124 _ if token.kind() == SyntaxKind::CONST_KW => ImplCompletionKind::Const, 124 _ if token.kind() == SyntaxKind::CONST_KW => ImplCompletionKind::Const,
125 SyntaxKind::CONST | SyntaxKind::ERROR => ImplCompletionKind::Const, 125 SyntaxKind::CONST | SyntaxKind::ERROR => ImplCompletionKind::Const,
126 SyntaxKind::TYPE_ALIAS => ImplCompletionKind::TypeAlias, 126 SyntaxKind::TYPE_ALIAS => ImplCompletionKind::TypeAlias,
@@ -267,7 +267,7 @@ trait Test {
267struct T; 267struct T;
268 268
269impl Test for T { 269impl Test for T {
270 t<|> 270 t$0
271} 271}
272"#, 272"#,
273 expect![[" 273 expect![["
@@ -287,7 +287,7 @@ struct T;
287 287
288impl Test for T { 288impl Test for T {
289 fn test() { 289 fn test() {
290 t<|> 290 t$0
291 } 291 }
292} 292}
293", 293",
@@ -301,7 +301,7 @@ struct T;
301 301
302impl Test for T { 302impl Test for T {
303 fn test() { 303 fn test() {
304 fn t<|> 304 fn t$0
305 } 305 }
306} 306}
307", 307",
@@ -315,7 +315,7 @@ struct T;
315 315
316impl Test for T { 316impl Test for T {
317 fn test() { 317 fn test() {
318 fn <|> 318 fn $0
319 } 319 }
320} 320}
321", 321",
@@ -330,7 +330,7 @@ struct T;
330 330
331impl Test for T { 331impl Test for T {
332 fn test() { 332 fn test() {
333 foo.<|> 333 foo.$0
334 } 334 }
335} 335}
336", 336",
@@ -343,7 +343,7 @@ trait Test { fn test(_: i32); fn test2(); }
343struct T; 343struct T;
344 344
345impl Test for T { 345impl Test for T {
346 fn test(t<|>) 346 fn test(t$0)
347} 347}
348", 348",
349 expect![[""]], 349 expect![[""]],
@@ -355,7 +355,7 @@ trait Test { fn test(_: fn()); fn test2(); }
355struct T; 355struct T;
356 356
357impl Test for T { 357impl Test for T {
358 fn test(f: fn <|>) 358 fn test(f: fn $0)
359} 359}
360", 360",
361 expect![[""]], 361 expect![[""]],
@@ -370,7 +370,7 @@ trait Test { const TEST: fn(); const TEST2: u32; type Test; fn test(); }
370struct T; 370struct T;
371 371
372impl Test for T { 372impl Test for T {
373 const TEST: fn <|> 373 const TEST: fn $0
374} 374}
375", 375",
376 expect![[""]], 376 expect![[""]],
@@ -382,7 +382,7 @@ trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
382struct T; 382struct T;
383 383
384impl Test for T { 384impl Test for T {
385 const TEST: T<|> 385 const TEST: T$0
386} 386}
387", 387",
388 expect![[""]], 388 expect![[""]],
@@ -394,7 +394,7 @@ trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
394struct T; 394struct T;
395 395
396impl Test for T { 396impl Test for T {
397 const TEST: u32 = f<|> 397 const TEST: u32 = f$0
398} 398}
399", 399",
400 expect![[""]], 400 expect![[""]],
@@ -407,7 +407,7 @@ struct T;
407 407
408impl Test for T { 408impl Test for T {
409 const TEST: u32 = { 409 const TEST: u32 = {
410 t<|> 410 t$0
411 }; 411 };
412} 412}
413", 413",
@@ -421,7 +421,7 @@ struct T;
421 421
422impl Test for T { 422impl Test for T {
423 const TEST: u32 = { 423 const TEST: u32 = {
424 fn <|> 424 fn $0
425 }; 425 };
426} 426}
427", 427",
@@ -435,7 +435,7 @@ struct T;
435 435
436impl Test for T { 436impl Test for T {
437 const TEST: u32 = { 437 const TEST: u32 = {
438 fn t<|> 438 fn t$0
439 }; 439 };
440} 440}
441", 441",
@@ -451,7 +451,7 @@ trait Test { type Test; type Test2; fn test(); }
451struct T; 451struct T;
452 452
453impl Test for T { 453impl Test for T {
454 type Test = T<|>; 454 type Test = T$0;
455} 455}
456", 456",
457 expect![[""]], 457 expect![[""]],
@@ -463,7 +463,7 @@ trait Test { type Test; type Test2; fn test(); }
463struct T; 463struct T;
464 464
465impl Test for T { 465impl Test for T {
466 type Test = fn <|>; 466 type Test = fn $0;
467} 467}
468", 468",
469 expect![[""]], 469 expect![[""]],
@@ -481,7 +481,7 @@ trait Test {
481struct T; 481struct T;
482 482
483impl Test for T { 483impl Test for T {
484 t<|> 484 t$0
485} 485}
486"#, 486"#,
487 r#" 487 r#"
@@ -510,7 +510,7 @@ trait Test {
510struct T; 510struct T;
511 511
512impl Test for T { 512impl Test for T {
513 fn t<|> 513 fn t$0
514} 514}
515"#, 515"#,
516 r#" 516 r#"
@@ -540,7 +540,7 @@ struct T;
540 540
541impl Test for T { 541impl Test for T {
542 fn foo() {} 542 fn foo() {}
543 fn f<|> 543 fn f$0
544} 544}
545"#, 545"#,
546 expect![[r#" 546 expect![[r#"
@@ -560,7 +560,7 @@ trait Test {
560struct T; 560struct T;
561 561
562impl Test for T { 562impl Test for T {
563 fn f<|> 563 fn f$0
564} 564}
565"#, 565"#,
566 r#" 566 r#"
@@ -585,7 +585,7 @@ trait Test {
585struct T; 585struct T;
586 586
587impl Test for T { 587impl Test for T {
588 fn f<|> 588 fn f$0
589} 589}
590"#, 590"#,
591 r#" 591 r#"
@@ -614,7 +614,7 @@ trait Test {
614} 614}
615 615
616impl Test for () { 616impl Test for () {
617 type S<|> 617 type S$0
618} 618}
619"#, 619"#,
620 " 620 "
@@ -639,7 +639,7 @@ trait Test {
639} 639}
640 640
641impl Test for () { 641impl Test for () {
642 const S<|> 642 const S$0
643} 643}
644"#, 644"#,
645 " 645 "
@@ -661,7 +661,7 @@ trait Test {
661} 661}
662 662
663impl Test for () { 663impl Test for () {
664 const S<|> 664 const S$0
665} 665}
666"#, 666"#,
667 " 667 "
@@ -724,7 +724,7 @@ impl Test for T {{
724 // Enumerate some possible next siblings. 724 // Enumerate some possible next siblings.
725 for next_sibling in &[ 725 for next_sibling in &[
726 "", 726 "",
727 "fn other_fn() {}", // `const <|> fn` -> `const fn` 727 "fn other_fn() {}", // `const $0 fn` -> `const fn`
728 "type OtherType = i32;", 728 "type OtherType = i32;",
729 "const OTHER_CONST: i32 = 0;", 729 "const OTHER_CONST: i32 = 0;",
730 "async fn other_fn() {}", 730 "async fn other_fn() {}",
@@ -733,9 +733,9 @@ impl Test for T {{
733 "default type OtherType = i32;", 733 "default type OtherType = i32;",
734 "default const OTHER_CONST: i32 = 0;", 734 "default const OTHER_CONST: i32 = 0;",
735 ] { 735 ] {
736 test("bar", "fn <|>", "fn bar() {\n $0\n}", next_sibling); 736 test("bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
737 test("Foo", "type <|>", "type Foo = ", next_sibling); 737 test("Foo", "type $0", "type Foo = ", next_sibling);
738 test("CONST", "const <|>", "const CONST: u16 = ", next_sibling); 738 test("CONST", "const $0", "const CONST: u16 = ", next_sibling);
739 } 739 }
740 } 740 }
741} 741}