Skip to content

Commit fddcd43

Browse files
bors[bot]Jonas Schievink
and
Jonas Schievink
authored
Merge #11967
11967: fix: Fix trait impl completions not triggering after `fn`/`const`/`type` r=jonas-schievink a=jonas-schievink ![screenshot-2022-04-12-17:13:01](https://user-images.githubusercontent.com/1786438/162996087-56540f5e-a6be-4111-a4a5-8de21f483a5e.png) Fixes #11467 cc #11860 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents 49847a2 + 3328a0a commit fddcd43

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

crates/ide_completion/src/completions/trait_impl.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn add_function_impl(
167167
};
168168

169169
let mut item = CompletionItem::new(completion_kind, replacement_range, label);
170-
item.lookup_by(fn_name)
170+
item.lookup_by(format!("fn {}", fn_name))
171171
.set_documentation(func.docs(ctx.db))
172172
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
173173

@@ -232,7 +232,7 @@ fn add_type_alias_impl(
232232

233233
let mut item = CompletionItem::new(SymbolKind::TypeAlias, replacement_range, label);
234234
item.text_edit(TextEdit::replace(replacement_range, snippet))
235-
.lookup_by(alias_name)
235+
.lookup_by(format!("type {}", alias_name))
236236
.set_documentation(type_alias.docs(ctx.db))
237237
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
238238
item.add_to(acc);
@@ -261,7 +261,7 @@ fn add_const_impl(
261261

262262
let mut item = CompletionItem::new(SymbolKind::Const, replacement_range, label);
263263
item.text_edit(TextEdit::replace(replacement_range, snippet))
264-
.lookup_by(const_name)
264+
.lookup_by(format!("const {}", const_name))
265265
.set_documentation(const_.docs(ctx.db))
266266
.set_relevance(CompletionRelevance {
267267
is_item_from_trait: true,
@@ -549,7 +549,7 @@ impl Test for T {
549549
#[test]
550550
fn name_ref_single_function() {
551551
check_edit(
552-
"test",
552+
"fn test",
553553
r#"
554554
trait Test {
555555
fn test();
@@ -578,7 +578,7 @@ impl Test for T {
578578
#[test]
579579
fn single_function() {
580580
check_edit(
581-
"test",
581+
"fn test",
582582
r#"
583583
trait Test {
584584
fn test();
@@ -607,7 +607,7 @@ impl Test for T {
607607
#[test]
608608
fn generic_fn() {
609609
check_edit(
610-
"foo",
610+
"fn foo",
611611
r#"
612612
trait Test {
613613
fn foo<T>();
@@ -632,7 +632,7 @@ impl Test for T {
632632
"#,
633633
);
634634
check_edit(
635-
"foo",
635+
"fn foo",
636636
r#"
637637
trait Test {
638638
fn foo<T>() where T: Into<String>;
@@ -662,7 +662,7 @@ where T: Into<String> {
662662
#[test]
663663
fn associated_type() {
664664
check_edit(
665-
"SomeType",
665+
"type SomeType",
666666
r#"
667667
trait Test {
668668
type SomeType;
@@ -687,7 +687,7 @@ impl Test for () {
687687
#[test]
688688
fn associated_const() {
689689
check_edit(
690-
"SOME_CONST",
690+
"const SOME_CONST",
691691
r#"
692692
trait Test {
693693
const SOME_CONST: u16;
@@ -709,7 +709,7 @@ impl Test for () {
709709
);
710710

711711
check_edit(
712-
"SOME_CONST",
712+
"const SOME_CONST",
713713
r#"
714714
trait Test {
715715
const SOME_CONST: u16 = 92;
@@ -783,9 +783,9 @@ impl Test for T {{
783783
"default type OtherType = i32;",
784784
"default const OTHER_CONST: i32 = 0;",
785785
] {
786-
test("bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
787-
test("Foo", "type $0", "type Foo = ", next_sibling);
788-
test("CONST", "const $0", "const CONST: u16 = ", next_sibling);
786+
test("fn bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
787+
test("type Foo", "type $0", "type Foo = ", next_sibling);
788+
test("const CONST", "const $0", "const CONST: u16 = ", next_sibling);
789789
}
790790
}
791791

@@ -830,15 +830,15 @@ impl Foo for T {{
830830
),
831831
)
832832
};
833-
test("function", "fn f$0", "fn function() {\n $0\n}");
834-
test("Type", "type T$0", "type Type = ");
835-
test("CONST", "const C$0", "const CONST: i32 = ");
833+
test("fn function", "fn f$0", "fn function() {\n $0\n}");
834+
test("type Type", "type T$0", "type Type = ");
835+
test("const CONST", "const C$0", "const CONST: i32 = ");
836836
}
837837

838838
#[test]
839839
fn generics_are_inlined_in_return_type() {
840840
check_edit(
841-
"function",
841+
"fn function",
842842
r#"
843843
trait Foo<T> {
844844
fn function() -> T;
@@ -867,7 +867,7 @@ impl Foo<u32> for Bar {
867867
#[test]
868868
fn generics_are_inlined_in_parameter() {
869869
check_edit(
870-
"function",
870+
"fn function",
871871
r#"
872872
trait Foo<T> {
873873
fn function(bar: T);
@@ -896,7 +896,7 @@ impl Foo<u32> for Bar {
896896
#[test]
897897
fn generics_are_inlined_when_part_of_other_types() {
898898
check_edit(
899-
"function",
899+
"fn function",
900900
r#"
901901
trait Foo<T> {
902902
fn function(bar: Vec<T>);
@@ -925,7 +925,7 @@ impl Foo<u32> for Bar {
925925
#[test]
926926
fn generics_are_inlined_complex() {
927927
check_edit(
928-
"function",
928+
"fn function",
929929
r#"
930930
trait Foo<T, U, V> {
931931
fn function(bar: Vec<T>, baz: U) -> Arc<Vec<V>>;
@@ -954,7 +954,7 @@ impl Foo<u32, Vec<usize>, u8> for Bar {
954954
#[test]
955955
fn generics_are_inlined_in_associated_const() {
956956
check_edit(
957-
"BAR",
957+
"const BAR",
958958
r#"
959959
trait Foo<T> {
960960
const BAR: T;
@@ -981,7 +981,7 @@ impl Foo<u32> for Bar {
981981
#[test]
982982
fn generics_are_inlined_in_where_clause() {
983983
check_edit(
984-
"function",
984+
"fn function",
985985
r#"
986986
trait SomeTrait<T> {}
987987

0 commit comments

Comments
 (0)