Skip to content

Commit 6d97905

Browse files
authored
Merge pull request #41583 from ahoppen/pr/code-completion-qol
[CodeCompletion] Multiple code cleanups after split up of CodeCompletion.cpp
2 parents 4167e2f + 5bfa9ca commit 6d97905

11 files changed

+36
-67
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ ArrayRef<T> copyArray(llvm::BumpPtrAllocator &Allocator,
6161

6262
bool isDynamicLookup(Type T);
6363

64-
void postProcessResults(MutableArrayRef<CodeCompletionResult *> results,
65-
CompletionKind Kind, DeclContext *DC,
66-
CodeCompletionResultSink *Sink);
64+
void postProcessCompletionResults(
65+
MutableArrayRef<CodeCompletionResult *> results, CompletionKind Kind,
66+
DeclContext *DC, CodeCompletionResultSink *Sink);
6767

6868
void deliverCompletionResults(CodeCompletionContext &CompletionContext,
6969
CompletionLookup &Lookup, DeclContext *DC,

include/swift/IDE/CodeCompletionContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ class CodeCompletionContext {
9090
}
9191

9292
/// Allocate a string owned by the code completion context.
93-
StringRef copyString(StringRef Str);
93+
StringRef copyString(StringRef Str) {
94+
return Str.copy(*CurrentResults.Allocator);
95+
}
9496

9597
/// Sort code completion results in an implementation-defined order
9698
/// in place.

include/swift/IDE/DotExprCompletion.h

Lines changed: 4 additions & 11 deletions
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

Lines changed: 4 additions & 10 deletions
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

Lines changed: 4 additions & 14 deletions
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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ static void addConditionalCompilationFlags(ASTContext &Ctx,
11601160
/// If \p Sink is passed, the pointer of the each result may be replaced with a
11611161
/// pointer to the new item allocated in \p Sink.
11621162
/// If \p Sink is nullptr, the pointee of each result may be modified in place.
1163-
void swift::ide::postProcessResults(
1163+
void swift::ide::postProcessCompletionResults(
11641164
MutableArrayRef<CodeCompletionResult *> results, CompletionKind Kind,
11651165
DeclContext *DC, CodeCompletionResultSink *Sink) {
11661166
for (CodeCompletionResult *&result : results) {
@@ -1314,9 +1314,9 @@ void swift::ide::deliverCompletionResults(
13141314
Lookup.RequestedCachedResults.clear();
13151315
CompletionContext.typeContextKind = Lookup.typeContextKind();
13161316

1317-
postProcessResults(CompletionContext.getResultSink().Results,
1318-
CompletionContext.CodeCompletionKind, DC,
1319-
/*Sink=*/nullptr);
1317+
postProcessCompletionResults(CompletionContext.getResultSink().Results,
1318+
CompletionContext.CodeCompletionKind, DC,
1319+
/*Sink=*/nullptr);
13201320

13211321
Consumer.handleResultsAndModules(CompletionContext, RequestedModules, DC);
13221322
}
@@ -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/CodeCompletionConsumer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
134134
assert(V.hasValue());
135135
auto newItems = copyCodeCompletionResults(
136136
context.getResultSink(), **V, R.OnlyTypes, R.OnlyPrecedenceGroups);
137-
postProcessResults(newItems, context.CodeCompletionKind, DC,
138-
&context.getResultSink());
137+
postProcessCompletionResults(newItems, context.CodeCompletionKind, DC,
138+
&context.getResultSink());
139139
}
140140

141141
handleResults(context);

lib/IDE/CodeCompletionContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
using namespace swift;
1616
using namespace swift::ide;
1717

18-
StringRef CodeCompletionContext::copyString(StringRef Str) {
19-
return Str.copy(*CurrentResults.Allocator);
20-
}
21-
2218
std::vector<CodeCompletionResult *>
2319
CodeCompletionContext::sortCompletionResults(
2420
ArrayRef<CodeCompletionResult *> Results) {

lib/IDE/DotExprCompletion.cpp

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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) {

0 commit comments

Comments
 (0)