Skip to content

Commit 5bfa9ca

Browse files
committed
[CodeCompletion] Make deliver*Result functions members on their TypeCheckCompletionCallback
1 parent 119cc88 commit 5bfa9ca

7 files changed

+24
-53
lines changed

include/swift/IDE/DotExprCompletion.h

+4-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace ide {
2424
/// (\c CompletionKind::DotExpr ) from the solutions formed during expression
2525
/// type-checking.
2626
class DotExprTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
27-
public:
2827
struct Result {
2928
Type BaseTy;
3029
ValueDecl *BaseDecl;
@@ -34,7 +33,6 @@ class DotExprTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
3433
bool IsImplicitSingleExpressionReturn;
3534
};
3635

37-
private:
3836
DeclContext *DC;
3937
CodeCompletionExpr *CompletionExpr;
4038
SmallVector<Result, 4> Results;
@@ -46,10 +44,6 @@ class DotExprTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
4644
CodeCompletionExpr *CompletionExpr)
4745
: DC(DC), CompletionExpr(CompletionExpr) {}
4846

49-
/// Get the results collected from any sawSolutions() callbacks recevied so
50-
/// far.
51-
ArrayRef<Result> getResults() const { return Results; }
52-
5347
/// True if at least one solution was passed via the \c sawSolution
5448
/// callback.
5549
bool gotCallback() const { return GotCallback; }
@@ -59,12 +53,11 @@ class DotExprTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
5953
void fallbackTypeCheck();
6054

6155
void sawSolution(const constraints::Solution &solution) override;
62-
};
6356

64-
void deliverDotExprResults(
65-
ArrayRef<DotExprTypeCheckCompletionCallback::Result> Results,
66-
Expr *BaseExpr, DeclContext *DC, SourceLoc DotLoc, bool IsInSelector,
67-
CodeCompletionContext &CompletionCtx, CodeCompletionConsumer &Consumer);
57+
void deliverResults(Expr *BaseExpr, DeclContext *DC, SourceLoc DotLoc,
58+
bool IsInSelector, CodeCompletionContext &CompletionCtx,
59+
CodeCompletionConsumer &Consumer);
60+
};
6861

6962
} // end namespace ide
7063
} // end namespace swift

include/swift/IDE/KeyPathCompletion.h

+4-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace swift {
2121
namespace ide {
2222

2323
class KeyPathTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
24-
public:
2524
struct Result {
2625
/// The type on which completion should occur, i.e. a result type of the
2726
/// previous component.
@@ -30,23 +29,18 @@ class KeyPathTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
3029
bool OnRoot;
3130
};
3231

33-
private:
3432
KeyPathExpr *KeyPath;
3533
SmallVector<Result, 4> Results;
3634

3735
public:
3836
KeyPathTypeCheckCompletionCallback(KeyPathExpr *KeyPath) : KeyPath(KeyPath) {}
3937

40-
ArrayRef<Result> getResults() const { return Results; }
41-
4238
void sawSolution(const constraints::Solution &solution) override;
43-
};
4439

45-
void deliverKeyPathResults(
46-
ArrayRef<KeyPathTypeCheckCompletionCallback::Result> Results,
47-
DeclContext *DC, SourceLoc DotLoc,
48-
ide::CodeCompletionContext &CompletionCtx,
49-
CodeCompletionConsumer &Consumer);
40+
void deliverResults(DeclContext *DC, SourceLoc DotLoc,
41+
ide::CodeCompletionContext &CompletionCtx,
42+
CodeCompletionConsumer &Consumer);
43+
};
5044

5145
} // end namespace ide
5246
} // end namespace swift

include/swift/IDE/UnresolvedMemberCompletion.h

+4-14
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ namespace ide {
2525
/// formed during expression type-checking.
2626
class UnresolvedMemberTypeCheckCompletionCallback
2727
: public TypeCheckCompletionCallback {
28-
public:
2928
struct ExprResult {
3029
Type ExpectedTy;
3130
bool IsImplicitSingleExpressionReturn;
3231
};
3332

34-
private:
3533
CodeCompletionExpr *CompletionExpr;
3634
SmallVector<ExprResult, 4> ExprResults;
3735
SmallVector<Type, 1> EnumPatternTypes;
@@ -42,12 +40,6 @@ class UnresolvedMemberTypeCheckCompletionCallback
4240
CodeCompletionExpr *CompletionExpr)
4341
: CompletionExpr(CompletionExpr) {}
4442

45-
ArrayRef<ExprResult> getExprResults() const { return ExprResults; }
46-
47-
/// If we are completing in a pattern matching position, the types of all
48-
/// enums for whose cases are valid as an \c EnumElementPattern.
49-
ArrayRef<Type> getEnumPatternTypes() const { return EnumPatternTypes; }
50-
5143
/// True if at least one solution was passed via the \c sawSolution
5244
/// callback.
5345
bool gotCallback() const { return GotCallback; }
@@ -57,13 +49,11 @@ class UnresolvedMemberTypeCheckCompletionCallback
5749
void fallbackTypeCheck(DeclContext *DC);
5850

5951
void sawSolution(const constraints::Solution &solution) override;
60-
};
6152

62-
void deliverUnresolvedMemberResults(
63-
ArrayRef<UnresolvedMemberTypeCheckCompletionCallback::ExprResult> Results,
64-
ArrayRef<Type> EnumPatternTypes, DeclContext *DC, SourceLoc DotLoc,
65-
ide::CodeCompletionContext &CompletionCtx,
66-
CodeCompletionConsumer &Consumer);
53+
void deliverResults(DeclContext *DC, SourceLoc DotLoc,
54+
ide::CodeCompletionContext &CompletionCtx,
55+
CodeCompletionConsumer &Consumer);
56+
};
6757

6858
} // end namespace ide
6959
} // end namespace swift

lib/IDE/CodeCompletion.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,8 @@ bool CodeCompletionCallbacksImpl::trySolverCompletion(bool MaybeFuncBody) {
13501350
addKeywords(CompletionContext.getResultSink(), MaybeFuncBody);
13511351

13521352
Expr *CheckedBase = CodeCompleteTokenExpr->getBase();
1353-
deliverDotExprResults(Lookup.getResults(), CheckedBase, CurDeclContext,
1354-
DotLoc, isInsideObjCSelector(), CompletionContext,
1355-
Consumer);
1353+
Lookup.deliverResults(CheckedBase, CurDeclContext, DotLoc,
1354+
isInsideObjCSelector(), CompletionContext, Consumer);
13561355
return true;
13571356
}
13581357
case CompletionKind::UnresolvedMember: {
@@ -1368,9 +1367,7 @@ bool CodeCompletionCallbacksImpl::trySolverCompletion(bool MaybeFuncBody) {
13681367
Lookup.fallbackTypeCheck(CurDeclContext);
13691368

13701369
addKeywords(CompletionContext.getResultSink(), MaybeFuncBody);
1371-
deliverUnresolvedMemberResults(Lookup.getExprResults(),
1372-
Lookup.getEnumPatternTypes(), CurDeclContext,
1373-
DotLoc, CompletionContext, Consumer);
1370+
Lookup.deliverResults(CurDeclContext, DotLoc, CompletionContext, Consumer);
13741371
return true;
13751372
}
13761373
case CompletionKind::KeyPathExprSwift: {
@@ -1384,8 +1381,7 @@ bool CodeCompletionCallbacksImpl::trySolverCompletion(bool MaybeFuncBody) {
13841381
Context.CompletionCallback, &Lookup);
13851382
typeCheckContextAt(CurDeclContext, CompletionLoc);
13861383

1387-
deliverKeyPathResults(Lookup.getResults(), CurDeclContext, DotLoc,
1388-
CompletionContext, Consumer);
1384+
Lookup.deliverResults(CurDeclContext, DotLoc, CompletionContext, Consumer);
13891385
return true;
13901386
}
13911387
default:

lib/IDE/DotExprCompletion.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ void DotExprTypeCheckCompletionCallback::sawSolution(
9191
}
9292
}
9393

94-
void swift::ide::deliverDotExprResults(
95-
ArrayRef<DotExprTypeCheckCompletionCallback::Result> Results,
94+
void DotExprTypeCheckCompletionCallback::deliverResults(
9695
Expr *BaseExpr, DeclContext *DC, SourceLoc DotLoc, bool IsInSelector,
9796
CodeCompletionContext &CompletionCtx, CodeCompletionConsumer &Consumer) {
9897
ASTContext &Ctx = DC->getASTContext();

lib/IDE/KeyPathCompletion.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ void KeyPathTypeCheckCompletionCallback::sawSolution(
7373
Results.push_back({BaseType, /*OnRoot=*/(ComponentIndex == 0)});
7474
}
7575

76-
void swift::ide::deliverKeyPathResults(
77-
ArrayRef<KeyPathTypeCheckCompletionCallback::Result> Results,
76+
void KeyPathTypeCheckCompletionCallback::deliverResults(
7877
DeclContext *DC, SourceLoc DotLoc,
7978
ide::CodeCompletionContext &CompletionCtx,
8079
CodeCompletionConsumer &Consumer) {

lib/IDE/UnresolvedMemberCompletion.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ void UnresolvedMemberTypeCheckCompletionCallback::fallbackTypeCheck(
138138
[&](const Solution &S) { sawSolution(S); });
139139
}
140140

141-
void swift::ide::deliverUnresolvedMemberResults(
142-
ArrayRef<UnresolvedMemberTypeCheckCompletionCallback::ExprResult> Results,
143-
ArrayRef<Type> EnumPatternTypes, DeclContext *DC, SourceLoc DotLoc,
141+
void UnresolvedMemberTypeCheckCompletionCallback::deliverResults(
142+
DeclContext *DC, SourceLoc DotLoc,
144143
ide::CodeCompletionContext &CompletionCtx,
145144
CodeCompletionConsumer &Consumer) {
146145
ASTContext &Ctx = DC->getASTContext();
@@ -149,14 +148,15 @@ void swift::ide::deliverUnresolvedMemberResults(
149148

150149
assert(DotLoc.isValid());
151150
Lookup.setHaveDot(DotLoc);
152-
Lookup.shouldCheckForDuplicates(Results.size() + EnumPatternTypes.size() > 1);
151+
Lookup.shouldCheckForDuplicates(ExprResults.size() + EnumPatternTypes.size() >
152+
1);
153153

154154
// Get the canonical versions of the top-level types
155155
SmallPtrSet<CanType, 4> originalTypes;
156-
for (auto &Result : Results)
156+
for (auto &Result : ExprResults)
157157
originalTypes.insert(Result.ExpectedTy->getCanonicalType());
158158

159-
for (auto &Result : Results) {
159+
for (auto &Result : ExprResults) {
160160
Lookup.setExpectedTypes({Result.ExpectedTy},
161161
Result.IsImplicitSingleExpressionReturn,
162162
/*expectsNonVoid*/ true);

0 commit comments

Comments
 (0)