Skip to content

Commit

Permalink
Merge #9138
Browse files Browse the repository at this point in the history
9138: COMP: Fix auto-import when completing impl trait items r=Kobzol a=dima74

Fixes #8572

changelog: Fix auto-import when completing items in trait impl


Co-authored-by: Dmitry Murzin <diralik@yandex.ru>
  • Loading branch information
bors[bot] and dima74 committed Aug 1, 2022
2 parents 119db43 + 343287b commit 4bf850b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Expand Up @@ -78,8 +78,9 @@ object RsImplTraitMemberCompletionProvider : RsCompletionProvider() {
return
}

val memberGenerator = MembersGenerator(RsPsiFactory(element.project), implBlock, trait)
for (item in parentItems) {
// have to create new generator for each item, so that [MembersGenerator.itemsToImport] don't mix up
val memberGenerator = MembersGenerator(RsPsiFactory(element.project), implBlock, trait)
val lookup = getCompletion(item, implBlock, subst, memberGenerator, keyword?.first)
result.addElement(
lookup.toRsLookupElement(RsLookupElementProperties(isImplMemberFullLineCompletion = true))
Expand Down
Expand Up @@ -295,6 +295,38 @@ class RsImplTraitMemberCompletionProviderTest : RsCompletionTestBase() {
}
""")

fun `test auto import only completed function types`() = doFirstCompletion("""
mod foo {
pub struct S;
pub struct T;
pub trait Foo {
fn foo1();
fn foo2(s: S);
}
}
impl foo::Foo for () {
/*caret*/
}
""", """
mod foo {
pub struct S;
pub struct T;
pub trait Foo {
fn foo1();
fn foo2(s: S);
}
}
impl foo::Foo for () {
fn foo1() {
todo!()/*caret*/
}
}
""")

fun `test complete full function signature`() = doFirstCompletion("""
trait T1 {}
trait T2 {
Expand Down

0 comments on commit 4bf850b

Please sign in to comment.