diff options
Diffstat (limited to 'crates/completion/src/render.rs')
-rw-r--r-- | crates/completion/src/render.rs | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index 1ba7201a1..e93c59f71 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs | |||
@@ -11,13 +11,13 @@ pub(crate) mod type_alias; | |||
11 | mod builder_ext; | 11 | mod builder_ext; |
12 | 12 | ||
13 | use hir::{Documentation, HasAttrs, HirDisplay, Mutability, ScopeDef, Type}; | 13 | use hir::{Documentation, HasAttrs, HirDisplay, Mutability, ScopeDef, Type}; |
14 | use ide_db::RootDatabase; | 14 | use ide_db::{helpers::SnippetCap, RootDatabase}; |
15 | use syntax::TextRange; | 15 | use syntax::TextRange; |
16 | use test_utils::mark; | 16 | use test_utils::mark; |
17 | 17 | ||
18 | use crate::{ | 18 | use crate::{ |
19 | config::SnippetCap, item::ImportEdit, CompletionContext, CompletionItem, CompletionItemKind, | 19 | item::ImportEdit, CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, |
20 | CompletionKind, CompletionScore, | 20 | CompletionScore, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | use crate::render::{enum_variant::render_variant, function::render_fn, macro_::render_macro}; | 23 | use crate::render::{enum_variant::render_variant, function::render_fn, macro_::render_macro}; |
@@ -157,8 +157,7 @@ impl<'a> Render<'a> { | |||
157 | 157 | ||
158 | let kind = match resolution { | 158 | let kind = match resolution { |
159 | ScopeDef::ModuleDef(Function(func)) => { | 159 | ScopeDef::ModuleDef(Function(func)) => { |
160 | let item = render_fn(self.ctx, import_to_add, Some(local_name), *func); | 160 | return render_fn(self.ctx, import_to_add, Some(local_name), *func); |
161 | return Some(item); | ||
162 | } | 161 | } |
163 | ScopeDef::ModuleDef(Variant(_)) | 162 | ScopeDef::ModuleDef(Variant(_)) |
164 | if self.ctx.completion.is_pat_binding_or_const | 163 | if self.ctx.completion.is_pat_binding_or_const |
@@ -321,8 +320,8 @@ mod tests { | |||
321 | use test_utils::mark; | 320 | use test_utils::mark; |
322 | 321 | ||
323 | use crate::{ | 322 | use crate::{ |
324 | test_utils::{check_edit, do_completion, get_all_items}, | 323 | test_utils::{check_edit, do_completion, get_all_items, TEST_CONFIG}, |
325 | CompletionConfig, CompletionKind, CompletionScore, | 324 | CompletionKind, CompletionScore, |
326 | }; | 325 | }; |
327 | 326 | ||
328 | fn check(ra_fixture: &str, expect: Expect) { | 327 | fn check(ra_fixture: &str, expect: Expect) { |
@@ -339,7 +338,7 @@ mod tests { | |||
339 | } | 338 | } |
340 | } | 339 | } |
341 | 340 | ||
342 | let mut completions = get_all_items(CompletionConfig::default(), ra_fixture); | 341 | let mut completions = get_all_items(TEST_CONFIG, ra_fixture); |
343 | completions.sort_by_key(|it| (Reverse(it.score()), it.label().to_string())); | 342 | completions.sort_by_key(|it| (Reverse(it.score()), it.label().to_string())); |
344 | let actual = completions | 343 | let actual = completions |
345 | .into_iter() | 344 | .into_iter() |
@@ -359,7 +358,7 @@ mod tests { | |||
359 | r#" | 358 | r#" |
360 | enum Foo { Foo { x: i32, y: i32 } } | 359 | enum Foo { Foo { x: i32, y: i32 } } |
361 | 360 | ||
362 | fn main() { Foo::Fo<|> } | 361 | fn main() { Foo::Fo$0 } |
363 | "#, | 362 | "#, |
364 | expect![[r#" | 363 | expect![[r#" |
365 | [ | 364 | [ |
@@ -382,7 +381,7 @@ fn main() { Foo::Fo<|> } | |||
382 | r#" | 381 | r#" |
383 | enum Foo { Foo (i32, i32) } | 382 | enum Foo { Foo (i32, i32) } |
384 | 383 | ||
385 | fn main() { Foo::Fo<|> } | 384 | fn main() { Foo::Fo$0 } |
386 | "#, | 385 | "#, |
387 | expect![[r#" | 386 | expect![[r#" |
388 | [ | 387 | [ |
@@ -407,7 +406,7 @@ fn main() { Foo::Fo<|> } | |||
407 | r#" | 406 | r#" |
408 | enum Foo { Foo } | 407 | enum Foo { Foo } |
409 | 408 | ||
410 | fn main() { Foo::Fo<|> } | 409 | fn main() { Foo::Fo$0 } |
411 | "#, | 410 | "#, |
412 | expect![[r#" | 411 | expect![[r#" |
413 | [ | 412 | [ |
@@ -431,7 +430,7 @@ fn main() { Foo::Fo<|> } | |||
431 | mod m { | 430 | mod m { |
432 | pub enum Spam { Foo, Bar(i32) } | 431 | pub enum Spam { Foo, Bar(i32) } |
433 | } | 432 | } |
434 | fn main() { let _: m::Spam = S<|> } | 433 | fn main() { let _: m::Spam = S$0 } |
435 | "#, | 434 | "#, |
436 | expect![[r#" | 435 | expect![[r#" |
437 | [ | 436 | [ |
@@ -484,7 +483,7 @@ fn something_deprecated() {} | |||
484 | #[deprecated(since = "1.0.0")] | 483 | #[deprecated(since = "1.0.0")] |
485 | fn something_else_deprecated() {} | 484 | fn something_else_deprecated() {} |
486 | 485 | ||
487 | fn main() { som<|> } | 486 | fn main() { som$0 } |
488 | "#, | 487 | "#, |
489 | expect![[r#" | 488 | expect![[r#" |
490 | [ | 489 | [ |
@@ -524,7 +523,7 @@ fn main() { som<|> } | |||
524 | check( | 523 | check( |
525 | r#" | 524 | r#" |
526 | struct A { #[deprecated] the_field: u32 } | 525 | struct A { #[deprecated] the_field: u32 } |
527 | fn foo() { A { the<|> } } | 526 | fn foo() { A { the$0 } } |
528 | "#, | 527 | "#, |
529 | expect![[r#" | 528 | expect![[r#" |
530 | [ | 529 | [ |
@@ -552,7 +551,7 @@ struct S { | |||
552 | } | 551 | } |
553 | impl S { | 552 | impl S { |
554 | /// Method docs | 553 | /// Method docs |
555 | fn bar(self) { self.<|> } | 554 | fn bar(self) { self.$0 } |
556 | }"#, | 555 | }"#, |
557 | expect![[r#" | 556 | expect![[r#" |
558 | [ | 557 | [ |
@@ -585,7 +584,7 @@ impl S { | |||
585 | 584 | ||
586 | check( | 585 | check( |
587 | r#" | 586 | r#" |
588 | use self::my<|>; | 587 | use self::my$0; |
589 | 588 | ||
590 | /// mod docs | 589 | /// mod docs |
591 | mod my { } | 590 | mod my { } |
@@ -644,7 +643,7 @@ impl S { | |||
644 | #[inline] | 643 | #[inline] |
645 | fn the_method(&self) { } | 644 | fn the_method(&self) { } |
646 | } | 645 | } |
647 | fn foo(s: S) { s.<|> } | 646 | fn foo(s: S) { s.$0 } |
648 | "#, | 647 | "#, |
649 | expect![[r#" | 648 | expect![[r#" |
650 | [ | 649 | [ |
@@ -672,7 +671,7 @@ fn foo(foo: u8, bar: u8) {} | |||
672 | struct ManualVtable { f: fn(u8, u8) } | 671 | struct ManualVtable { f: fn(u8, u8) } |
673 | 672 | ||
674 | fn main() -> ManualVtable { | 673 | fn main() -> ManualVtable { |
675 | ManualVtable { f: f<|> } | 674 | ManualVtable { f: f$0 } |
676 | } | 675 | } |
677 | "#, | 676 | "#, |
678 | r#" | 677 | r#" |
@@ -693,7 +692,7 @@ fn main() -> ManualVtable { | |||
693 | "foo", | 692 | "foo", |
694 | r#" | 693 | r#" |
695 | mod m { pub fn foo() {} } | 694 | mod m { pub fn foo() {} } |
696 | use crate::m::f<|>; | 695 | use crate::m::f$0; |
697 | "#, | 696 | "#, |
698 | r#" | 697 | r#" |
699 | mod m { pub fn foo() {} } | 698 | mod m { pub fn foo() {} } |
@@ -708,7 +707,7 @@ use crate::m::foo; | |||
708 | "foo", | 707 | "foo", |
709 | r#" | 708 | r#" |
710 | fn foo(x: i32) {} | 709 | fn foo(x: i32) {} |
711 | fn main() { f<|>(); } | 710 | fn main() { f$0(); } |
712 | "#, | 711 | "#, |
713 | r#" | 712 | r#" |
714 | fn foo(x: i32) {} | 713 | fn foo(x: i32) {} |
@@ -720,7 +719,7 @@ fn main() { foo(); } | |||
720 | r#" | 719 | r#" |
721 | struct Foo; | 720 | struct Foo; |
722 | impl Foo { fn foo(&self){} } | 721 | impl Foo { fn foo(&self){} } |
723 | fn f(foo: &Foo) { foo.f<|>(); } | 722 | fn f(foo: &Foo) { foo.f$0(); } |
724 | "#, | 723 | "#, |
725 | r#" | 724 | r#" |
726 | struct Foo; | 725 | struct Foo; |
@@ -737,7 +736,7 @@ fn f(foo: &Foo) { foo.foo(); } | |||
737 | "Vec", | 736 | "Vec", |
738 | r#" | 737 | r#" |
739 | struct Vec<T> {} | 738 | struct Vec<T> {} |
740 | fn foo(xs: Ve<|>) | 739 | fn foo(xs: Ve$0) |
741 | "#, | 740 | "#, |
742 | r#" | 741 | r#" |
743 | struct Vec<T> {} | 742 | struct Vec<T> {} |
@@ -748,7 +747,7 @@ fn foo(xs: Vec<$0>) | |||
748 | "Vec", | 747 | "Vec", |
749 | r#" | 748 | r#" |
750 | type Vec<T> = (T,); | 749 | type Vec<T> = (T,); |
751 | fn foo(xs: Ve<|>) | 750 | fn foo(xs: Ve$0) |
752 | "#, | 751 | "#, |
753 | r#" | 752 | r#" |
754 | type Vec<T> = (T,); | 753 | type Vec<T> = (T,); |
@@ -759,7 +758,7 @@ fn foo(xs: Vec<$0>) | |||
759 | "Vec", | 758 | "Vec", |
760 | r#" | 759 | r#" |
761 | struct Vec<T = i128> {} | 760 | struct Vec<T = i128> {} |
762 | fn foo(xs: Ve<|>) | 761 | fn foo(xs: Ve$0) |
763 | "#, | 762 | "#, |
764 | r#" | 763 | r#" |
765 | struct Vec<T = i128> {} | 764 | struct Vec<T = i128> {} |
@@ -770,7 +769,7 @@ fn foo(xs: Vec) | |||
770 | "Vec", | 769 | "Vec", |
771 | r#" | 770 | r#" |
772 | struct Vec<T> {} | 771 | struct Vec<T> {} |
773 | fn foo(xs: Ve<|><i128>) | 772 | fn foo(xs: Ve$0<i128>) |
774 | "#, | 773 | "#, |
775 | r#" | 774 | r#" |
776 | struct Vec<T> {} | 775 | struct Vec<T> {} |
@@ -786,7 +785,7 @@ fn foo(xs: Vec<i128>) | |||
786 | r#" | 785 | r#" |
787 | struct S { foo: i64, bar: u32, baz: u32 } | 786 | struct S { foo: i64, bar: u32, baz: u32 } |
788 | fn test(bar: u32) { } | 787 | fn test(bar: u32) { } |
789 | fn foo(s: S) { test(s.<|>) } | 788 | fn foo(s: S) { test(s.$0) } |
790 | "#, | 789 | "#, |
791 | expect![[r#" | 790 | expect![[r#" |
792 | fd bar [type+name] | 791 | fd bar [type+name] |
@@ -803,7 +802,7 @@ fn foo(s: S) { test(s.<|>) } | |||
803 | r#" | 802 | r#" |
804 | struct A { foo: i64, bar: u32, baz: u32 } | 803 | struct A { foo: i64, bar: u32, baz: u32 } |
805 | struct B { x: (), y: f32, bar: u32 } | 804 | struct B { x: (), y: f32, bar: u32 } |
806 | fn foo(a: A) { B { bar: a.<|> }; } | 805 | fn foo(a: A) { B { bar: a.$0 }; } |
807 | "#, | 806 | "#, |
808 | expect![[r#" | 807 | expect![[r#" |
809 | fd bar [type+name] | 808 | fd bar [type+name] |
@@ -820,7 +819,7 @@ fn foo(a: A) { B { bar: a.<|> }; } | |||
820 | struct A { foo: i64, bar: u32, baz: u32 } | 819 | struct A { foo: i64, bar: u32, baz: u32 } |
821 | struct B { x: (), y: f32, bar: u32 } | 820 | struct B { x: (), y: f32, bar: u32 } |
822 | fn f(foo: i64) { } | 821 | fn f(foo: i64) { } |
823 | fn foo(a: A) { B { bar: f(a.<|>) }; } | 822 | fn foo(a: A) { B { bar: f(a.$0) }; } |
824 | "#, | 823 | "#, |
825 | expect![[r#" | 824 | expect![[r#" |
826 | fd foo [type+name] | 825 | fd foo [type+name] |
@@ -833,7 +832,7 @@ fn foo(a: A) { B { bar: f(a.<|>) }; } | |||
833 | struct A { foo: i64, bar: u32, baz: u32 } | 832 | struct A { foo: i64, bar: u32, baz: u32 } |
834 | struct B { x: (), y: f32, bar: u32 } | 833 | struct B { x: (), y: f32, bar: u32 } |
835 | fn f(foo: i64) { } | 834 | fn f(foo: i64) { } |
836 | fn foo(a: A) { f(B { bar: a.<|> }); } | 835 | fn foo(a: A) { f(B { bar: a.$0 }); } |
837 | "#, | 836 | "#, |
838 | expect![[r#" | 837 | expect![[r#" |
839 | fd bar [type+name] | 838 | fd bar [type+name] |
@@ -848,7 +847,7 @@ fn foo(a: A) { f(B { bar: a.<|> }); } | |||
848 | check_scores( | 847 | check_scores( |
849 | r#" | 848 | r#" |
850 | struct WorldSnapshot { _f: () }; | 849 | struct WorldSnapshot { _f: () }; |
851 | fn go(world: &WorldSnapshot) { go(w<|>) } | 850 | fn go(world: &WorldSnapshot) { go(w$0) } |
852 | "#, | 851 | "#, |
853 | expect![[r#" | 852 | expect![[r#" |
854 | bn world [type+name] | 853 | bn world [type+name] |
@@ -863,7 +862,7 @@ fn go(world: &WorldSnapshot) { go(w<|>) } | |||
863 | check_scores( | 862 | check_scores( |
864 | r#" | 863 | r#" |
865 | struct Foo; | 864 | struct Foo; |
866 | fn f(foo: &Foo) { f(foo, w<|>) } | 865 | fn f(foo: &Foo) { f(foo, w$0) } |
867 | "#, | 866 | "#, |
868 | expect![[r#" | 867 | expect![[r#" |
869 | st Foo [] | 868 | st Foo [] |