Skip to content

Commit c31bfae

Browse files
committed
[CodeCompletion] Introduce 'Unknown' type relation
Now * NotApplicable: The result is not relevant for type relation (e.g. keywords, and overloads) * Unknown: the relation was not calculated (e.g. cached results), or the context type is unknown. * Invalid: The result type is invalid for this context (i.e. 'Void' for non-'Void' context) * Unrelated: The result type has no relation to the context type * Convertible: The result type is convertible to the context type * Identical: The result type is identical to the context type
1 parent 17abedf commit c31bfae

10 files changed

+19
-10
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ class CodeCompletionResult {
530530
/// The result does not have a type (e.g. keyword).
531531
NotApplicable,
532532

533+
/// The type relation have not been calculated.
534+
Unknown,
535+
533536
/// The relationship of the result's type to the expected type is not
534537
/// invalid, not convertible, and not identical.
535538
Unrelated,

lib/IDE/CodeCompletion.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,9 @@ static CodeCompletionResult::ExpectedTypeRelation
903903
calculateMaxTypeRelationForDecl(
904904
const Decl *D, const ExpectedTypeContext &typeContext,
905905
bool IsImplicitlyCurriedInstanceMethod = false) {
906+
if (typeContext.empty())
907+
return CodeCompletionResult::ExpectedTypeRelation::Unknown;
908+
906909
auto Result = CodeCompletionResult::ExpectedTypeRelation::Unrelated;
907910
for (auto Type : typeContext.possibleTypes) {
908911
// Do not use Void type context for a single-expression body, since the
@@ -1034,7 +1037,7 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
10341037
}
10351038

10361039
auto typeRelation = ExpectedTypeRelation;
1037-
if (typeRelation == CodeCompletionResult::Unrelated)
1040+
if (typeRelation == CodeCompletionResult::Unknown)
10381041
typeRelation =
10391042
calculateMaxTypeRelationForDecl(AssociatedDecl, declTypeContext);
10401043

lib/IDE/CodeCompletionResultBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CodeCompletionResultBuilder {
6565
CurrentModule;
6666
ExpectedTypeContext declTypeContext;
6767
CodeCompletionResult::ExpectedTypeRelation ExpectedTypeRelation =
68-
CodeCompletionResult::Unrelated;
68+
CodeCompletionResult::Unknown;
6969
bool Cancelled = false;
7070
ArrayRef<std::pair<StringRef, StringRef>> CommentWords;
7171
bool IsNotRecommended = false;

test/SourceKit/CodeComplete/complete_constructor.swift.response

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
key.description: "(arg1: Int, arg2: Int)",
88
key.typename: "Foo",
99
key.context: source.codecompletion.context.thisclass,
10-
key.typerelation: source.codecompletion.typerelation.unrelated,
10+
key.typerelation: source.codecompletion.typerelation.unknown,
1111
key.num_bytes_to_erase: 0,
1212
key.associated_usrs: "s:20complete_constructor3FooC4arg14arg2ACSi_Sitcfc",
1313
key.modulename: "complete_constructor"

test/SourceKit/CodeComplete/complete_from_clang_module.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foo
99
// CHECK-NEXT: key.typename: "Int32",
1010
// CHECK-NEXT: key.doc.brief: "Aaa. fooIntVar. Bbb.",
1111
// CHECK-NEXT: key.context: source.codecompletion.context.othermodule,
12-
// CHECK-NEXT: key.typerelation: source.codecompletion.typerelation.unrelated,
12+
// CHECK-NEXT: key.typerelation: source.codecompletion.typerelation.unknown,
1313
// CHECK-NEXT: key.num_bytes_to_erase: 0,
1414
// CHECK-NEXT: key.associated_usrs: "c:@fooIntVar",
1515
// CHECK-NEXT: key.modulename: "Foo"

test/SourceKit/CodeComplete/complete_member.swift.response

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
key.description: "self",
4545
key.typename: "FooProtocol",
4646
key.context: source.codecompletion.context.thisclass,
47-
key.typerelation: source.codecompletion.typerelation.unrelated,
47+
key.typerelation: source.codecompletion.typerelation.unknown,
4848
key.num_bytes_to_erase: 0
4949
}
5050
]

test/SourceKit/CodeComplete/complete_optionalmethod.swift.response

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
key.description: "self",
2020
key.typename: "T",
2121
key.context: source.codecompletion.context.thisclass,
22-
key.typerelation: source.codecompletion.typerelation.unrelated,
22+
key.typerelation: source.codecompletion.typerelation.unknown,
2323
key.num_bytes_to_erase: 0
2424
}
2525
]

test/SourceKit/CodeComplete/complete_typerelation.swift.convertible.response

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
key.description: "self",
5757
key.typename: "MyEnum.Type",
5858
key.context: source.codecompletion.context.thisclass,
59-
key.typerelation: source.codecompletion.typerelation.unrelated,
59+
key.typerelation: source.codecompletion.typerelation.unknown,
6060
key.num_bytes_to_erase: 0
6161
},
6262
{
@@ -91,7 +91,7 @@
9191
key.description: "Type",
9292
key.typename: "MyEnum.Type",
9393
key.context: source.codecompletion.context.thisclass,
94-
key.typerelation: source.codecompletion.typerelation.unrelated,
94+
key.typerelation: source.codecompletion.typerelation.unknown,
9595
key.num_bytes_to_erase: 0
9696
}
9797
]

test/SourceKit/CodeComplete/complete_typerelation.swift.identical.response

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
key.description: "self",
5757
key.typename: "MyEnum.Type",
5858
key.context: source.codecompletion.context.thisclass,
59-
key.typerelation: source.codecompletion.typerelation.unrelated,
59+
key.typerelation: source.codecompletion.typerelation.unknown,
6060
key.num_bytes_to_erase: 0
6161
},
6262
{
@@ -91,7 +91,7 @@
9191
key.description: "Type",
9292
key.typename: "MyEnum.Type",
9393
key.context: source.codecompletion.context.thisclass,
94-
key.typerelation: source.codecompletion.typerelation.unrelated,
94+
key.typerelation: source.codecompletion.typerelation.unknown,
9595
key.num_bytes_to_erase: 0
9696
}
9797
]

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ bool SwiftToSourceKitCompletionAdapter::handleResult(
503503
}
504504

505505
static UIdent CCTypeRelNotApplicable("source.codecompletion.typerelation.notapplicable");
506+
static UIdent CCTypeRelUnknown("source.codecompletion.typerelation.unknown");
506507
static UIdent CCTypeRelUnrelated("source.codecompletion.typerelation.unrelated");
507508
static UIdent CCTypeRelInvalid("source.codecompletion.typerelation.invalid");
508509
static UIdent CCTypeRelConvertible("source.codecompletion.typerelation.convertible");
@@ -511,6 +512,8 @@ bool SwiftToSourceKitCompletionAdapter::handleResult(
511512
switch (Result->getExpectedTypeRelation()) {
512513
case CodeCompletionResult::NotApplicable:
513514
Info.TypeRelation = CCTypeRelNotApplicable; break;
515+
case CodeCompletionResult::Unknown:
516+
Info.TypeRelation = CCTypeRelUnknown; break;
514517
case CodeCompletionResult::Unrelated:
515518
Info.TypeRelation = CCTypeRelUnrelated; break;
516519
case CodeCompletionResult::Invalid:

0 commit comments

Comments
 (0)