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 https://github.com/rust-analyzer/rust-analyzer/issues/11467
cc https://github.com/rust-analyzer/rust-analyzer/issues/11860

bors r+

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
This commit is contained in:
bors[bot] 2022-04-12 16:03:12 +00:00 committed by GitHub
commit a64a70ebff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -167,7 +167,7 @@ fn add_function_impl(
}; };
let mut item = CompletionItem::new(completion_kind, replacement_range, label); 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_documentation(func.docs(ctx.db))
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() }); .set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
@ -232,7 +232,7 @@ fn add_type_alias_impl(
let mut item = CompletionItem::new(SymbolKind::TypeAlias, replacement_range, label); let mut item = CompletionItem::new(SymbolKind::TypeAlias, replacement_range, label);
item.text_edit(TextEdit::replace(replacement_range, snippet)) 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_documentation(type_alias.docs(ctx.db))
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() }); .set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
item.add_to(acc); item.add_to(acc);
@ -261,7 +261,7 @@ fn add_const_impl(
let mut item = CompletionItem::new(SymbolKind::Const, replacement_range, label); let mut item = CompletionItem::new(SymbolKind::Const, replacement_range, label);
item.text_edit(TextEdit::replace(replacement_range, snippet)) 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_documentation(const_.docs(ctx.db))
.set_relevance(CompletionRelevance { .set_relevance(CompletionRelevance {
is_item_from_trait: true, is_item_from_trait: true,
@ -549,7 +549,7 @@ impl Test for T {
#[test] #[test]
fn name_ref_single_function() { fn name_ref_single_function() {
check_edit( check_edit(
"test", "fn test",
r#" r#"
trait Test { trait Test {
fn test(); fn test();
@ -578,7 +578,7 @@ impl Test for T {
#[test] #[test]
fn single_function() { fn single_function() {
check_edit( check_edit(
"test", "fn test",
r#" r#"
trait Test { trait Test {
fn test(); fn test();
@ -607,7 +607,7 @@ impl Test for T {
#[test] #[test]
fn generic_fn() { fn generic_fn() {
check_edit( check_edit(
"foo", "fn foo",
r#" r#"
trait Test { trait Test {
fn foo<T>(); fn foo<T>();
@ -632,7 +632,7 @@ impl Test for T {
"#, "#,
); );
check_edit( check_edit(
"foo", "fn foo",
r#" r#"
trait Test { trait Test {
fn foo<T>() where T: Into<String>; fn foo<T>() where T: Into<String>;
@ -662,7 +662,7 @@ where T: Into<String> {
#[test] #[test]
fn associated_type() { fn associated_type() {
check_edit( check_edit(
"SomeType", "type SomeType",
r#" r#"
trait Test { trait Test {
type SomeType; type SomeType;
@ -687,7 +687,7 @@ impl Test for () {
#[test] #[test]
fn associated_const() { fn associated_const() {
check_edit( check_edit(
"SOME_CONST", "const SOME_CONST",
r#" r#"
trait Test { trait Test {
const SOME_CONST: u16; const SOME_CONST: u16;
@ -709,7 +709,7 @@ impl Test for () {
); );
check_edit( check_edit(
"SOME_CONST", "const SOME_CONST",
r#" r#"
trait Test { trait Test {
const SOME_CONST: u16 = 92; const SOME_CONST: u16 = 92;
@ -783,9 +783,9 @@ impl Test for T {{
"default type OtherType = i32;", "default type OtherType = i32;",
"default const OTHER_CONST: i32 = 0;", "default const OTHER_CONST: i32 = 0;",
] { ] {
test("bar", "fn $0", "fn bar() {\n $0\n}", next_sibling); test("fn bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
test("Foo", "type $0", "type Foo = ", next_sibling); test("type Foo", "type $0", "type Foo = ", next_sibling);
test("CONST", "const $0", "const CONST: u16 = ", next_sibling); test("const CONST", "const $0", "const CONST: u16 = ", next_sibling);
} }
} }
@ -830,15 +830,15 @@ impl Foo for T {{
), ),
) )
}; };
test("function", "fn f$0", "fn function() {\n $0\n}"); test("fn function", "fn f$0", "fn function() {\n $0\n}");
test("Type", "type T$0", "type Type = "); test("type Type", "type T$0", "type Type = ");
test("CONST", "const C$0", "const CONST: i32 = "); test("const CONST", "const C$0", "const CONST: i32 = ");
} }
#[test] #[test]
fn generics_are_inlined_in_return_type() { fn generics_are_inlined_in_return_type() {
check_edit( check_edit(
"function", "fn function",
r#" r#"
trait Foo<T> { trait Foo<T> {
fn function() -> T; fn function() -> T;
@ -867,7 +867,7 @@ impl Foo<u32> for Bar {
#[test] #[test]
fn generics_are_inlined_in_parameter() { fn generics_are_inlined_in_parameter() {
check_edit( check_edit(
"function", "fn function",
r#" r#"
trait Foo<T> { trait Foo<T> {
fn function(bar: T); fn function(bar: T);
@ -896,7 +896,7 @@ impl Foo<u32> for Bar {
#[test] #[test]
fn generics_are_inlined_when_part_of_other_types() { fn generics_are_inlined_when_part_of_other_types() {
check_edit( check_edit(
"function", "fn function",
r#" r#"
trait Foo<T> { trait Foo<T> {
fn function(bar: Vec<T>); fn function(bar: Vec<T>);
@ -925,7 +925,7 @@ impl Foo<u32> for Bar {
#[test] #[test]
fn generics_are_inlined_complex() { fn generics_are_inlined_complex() {
check_edit( check_edit(
"function", "fn function",
r#" r#"
trait Foo<T, U, V> { trait Foo<T, U, V> {
fn function(bar: Vec<T>, baz: U) -> Arc<Vec<V>>; fn function(bar: Vec<T>, baz: U) -> Arc<Vec<V>>;
@ -954,7 +954,7 @@ impl Foo<u32, Vec<usize>, u8> for Bar {
#[test] #[test]
fn generics_are_inlined_in_associated_const() { fn generics_are_inlined_in_associated_const() {
check_edit( check_edit(
"BAR", "const BAR",
r#" r#"
trait Foo<T> { trait Foo<T> {
const BAR: T; const BAR: T;
@ -981,7 +981,7 @@ impl Foo<u32> for Bar {
#[test] #[test]
fn generics_are_inlined_in_where_clause() { fn generics_are_inlined_in_where_clause() {
check_edit( check_edit(
"function", "fn function",
r#" r#"
trait SomeTrait<T> {} trait SomeTrait<T> {}