Skip to content

fix: Fix trait impl completions not triggering after fn/const/type #11967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions crates/ide_completion/src/completions/trait_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn add_function_impl(
};

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

Expand Down Expand Up @@ -232,7 +232,7 @@ fn add_type_alias_impl(

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

let mut item = CompletionItem::new(SymbolKind::Const, replacement_range, label);
item.text_edit(TextEdit::replace(replacement_range, snippet))
.lookup_by(const_name)
.lookup_by(format!("const {}", const_name))
.set_documentation(const_.docs(ctx.db))
.set_relevance(CompletionRelevance {
is_item_from_trait: true,
Expand Down Expand Up @@ -549,7 +549,7 @@ impl Test for T {
#[test]
fn name_ref_single_function() {
check_edit(
"test",
"fn test",
r#"
trait Test {
fn test();
Expand Down Expand Up @@ -578,7 +578,7 @@ impl Test for T {
#[test]
fn single_function() {
check_edit(
"test",
"fn test",
r#"
trait Test {
fn test();
Expand Down Expand Up @@ -607,7 +607,7 @@ impl Test for T {
#[test]
fn generic_fn() {
check_edit(
"foo",
"fn foo",
r#"
trait Test {
fn foo<T>();
Expand All @@ -632,7 +632,7 @@ impl Test for T {
"#,
);
check_edit(
"foo",
"fn foo",
r#"
trait Test {
fn foo<T>() where T: Into<String>;
Expand Down Expand Up @@ -662,7 +662,7 @@ where T: Into<String> {
#[test]
fn associated_type() {
check_edit(
"SomeType",
"type SomeType",
r#"
trait Test {
type SomeType;
Expand All @@ -687,7 +687,7 @@ impl Test for () {
#[test]
fn associated_const() {
check_edit(
"SOME_CONST",
"const SOME_CONST",
r#"
trait Test {
const SOME_CONST: u16;
Expand All @@ -709,7 +709,7 @@ impl Test for () {
);

check_edit(
"SOME_CONST",
"const SOME_CONST",
r#"
trait Test {
const SOME_CONST: u16 = 92;
Expand Down Expand Up @@ -783,9 +783,9 @@ impl Test for T {{
"default type OtherType = i32;",
"default const OTHER_CONST: i32 = 0;",
] {
test("bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
test("Foo", "type $0", "type Foo = ", next_sibling);
test("CONST", "const $0", "const CONST: u16 = ", next_sibling);
test("fn bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
test("type Foo", "type $0", "type Foo = ", next_sibling);
test("const CONST", "const $0", "const CONST: u16 = ", next_sibling);
}
}

Expand Down Expand Up @@ -830,15 +830,15 @@ impl Foo for T {{
),
)
};
test("function", "fn f$0", "fn function() {\n $0\n}");
test("Type", "type T$0", "type Type = ");
test("CONST", "const C$0", "const CONST: i32 = ");
test("fn function", "fn f$0", "fn function() {\n $0\n}");
test("type Type", "type T$0", "type Type = ");
test("const CONST", "const C$0", "const CONST: i32 = ");
}

#[test]
fn generics_are_inlined_in_return_type() {
check_edit(
"function",
"fn function",
r#"
trait Foo<T> {
fn function() -> T;
Expand Down Expand Up @@ -867,7 +867,7 @@ impl Foo<u32> for Bar {
#[test]
fn generics_are_inlined_in_parameter() {
check_edit(
"function",
"fn function",
r#"
trait Foo<T> {
fn function(bar: T);
Expand Down Expand Up @@ -896,7 +896,7 @@ impl Foo<u32> for Bar {
#[test]
fn generics_are_inlined_when_part_of_other_types() {
check_edit(
"function",
"fn function",
r#"
trait Foo<T> {
fn function(bar: Vec<T>);
Expand Down Expand Up @@ -925,7 +925,7 @@ impl Foo<u32> for Bar {
#[test]
fn generics_are_inlined_complex() {
check_edit(
"function",
"fn function",
r#"
trait Foo<T, U, V> {
fn function(bar: Vec<T>, baz: U) -> Arc<Vec<V>>;
Expand Down Expand Up @@ -954,7 +954,7 @@ impl Foo<u32, Vec<usize>, u8> for Bar {
#[test]
fn generics_are_inlined_in_associated_const() {
check_edit(
"BAR",
"const BAR",
r#"
trait Foo<T> {
const BAR: T;
Expand All @@ -981,7 +981,7 @@ impl Foo<u32> for Bar {
#[test]
fn generics_are_inlined_in_where_clause() {
check_edit(
"function",
"fn function",
r#"
trait SomeTrait<T> {}

Expand Down