Skip to content

Commit b0c8fc5

Browse files
authored
Merge pull request #19953 from rintaro/ide-completion-unresolvemember-polish
[CodeCompletion] Polish unresolved member completion
2 parents e596e1f + 04aba44 commit b0c8fc5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
26382638
for (auto *init : initializers) {
26392639
if (shouldHideDeclFromCompletionResults(init))
26402640
continue;
2641+
if (IsUnresolvedMember &&
2642+
cast<ConstructorDecl>(init)->getFailability() == OTK_Optional) {
2643+
continue;
2644+
}
26412645
addConstructorCall(cast<ConstructorDecl>(init), Reason, type, None,
26422646
/*IsOnType=*/true, name);
26432647
}
@@ -3786,6 +3790,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37863790
// same result type) as the contextual type.
37873791
FilteredDeclConsumer consumer(*this, [=](ValueDecl *VD,
37883792
DeclVisibilityKind reason) {
3793+
if (VD->isOperator())
3794+
return false;
3795+
37893796
if (!VD->hasInterfaceType()) {
37903797
TypeResolver->resolveDeclSignature(VD);
37913798
if (!VD->hasInterfaceType())
@@ -3819,6 +3826,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
38193826
// convertible to the contextual type.
38203827
if (auto CD = dyn_cast<TypeDecl>(VD)) {
38213828
declTy = declTy->getMetatypeInstanceType();
3829+
3830+
// Emit construction for the same type via typealias doesn't make sense
3831+
// because we are emitting all `.init()`s.
3832+
if (declTy->isEqual(T))
3833+
return false;
38223834
return swift::isConvertibleTo(declTy, T, *DC);
38233835
}
38243836

@@ -3836,7 +3848,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
38363848
// FIXME: This emits just 'factory'. We should emit 'factory()' instead.
38373849
declTy = FT->getResult();
38383850
}
3839-
return swift::isConvertibleTo(declTy, T, *DC);
3851+
return declTy->isEqual(T) || swift::isConvertibleTo(declTy, T, *DC);
38403852
});
38413853

38423854
auto baseType = MetatypeType::get(T);

test/IDE/complete_unresolved_members.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ func testInStringInterpolation() {
431431
class BaseClass {
432432
class SubClass : BaseClass { init() {} }
433433
static var subInstance: SubClass = SubClass()
434+
init() {}
435+
init?(failable: Void) {}
434436
}
435437
protocol MyProtocol {
436438
typealias Concrete1 = BaseClass
@@ -441,17 +443,19 @@ struct AnotherTy: MyProtocol {}
441443
func testSubType() {
442444
var _: BaseClass = .#^SUBTYPE_1^#
443445
}
444-
// SUBTYPE_1: Begin completions, 4 items
446+
// SUBTYPE_1: Begin completions, 3 items
447+
// SUBTYPE_1-NOT: init(failable:
448+
// SUBTYPE_1-NOT: Concrete1(
445449
// SUBTYPE_1-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Identical]: init()[#BaseClass#];
446450
// SUBTYPE_1-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: SubClass()[#BaseClass.SubClass#];
447451
// SUBTYPE_1-DAG: Decl[StaticVar]/CurrNominal/TypeRelation[Convertible]: subInstance[#BaseClass.SubClass#];
448-
// SUBTYPE_1-DAG: Decl[Constructor]/Super/TypeRelation[Identical]: Concrete1()[#BaseClass#];
449452
// SUBTYPE_1: End completions
450453

451454
func testMemberTypealias() {
452455
var _: MyProtocol = .#^SUBTYPE_2^#
453456
}
454457
// SUBTYPE_2: Begin completions, 2 items
458+
// SUBTYPE_1-NOT: Concrete1(failable:
455459
// SUBTYPE_2-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: Concrete1()[#BaseClass#];
456460
// SUBTYPE_2-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: Concrete2()[#AnotherTy#];
457461
// SUBTYPE_2: End completions

0 commit comments

Comments
 (0)