Skip to content

Commit acc6c10

Browse files
authored
Merge pull request #68075 from ahoppen/ahoppen/labeled-trailing-closure-solver-based
[CodeCompletion] Migrate labeled trailing closure completions to solver-based
2 parents 2c3c3c1 + 48ce1b3 commit acc6c10

28 files changed

+388
-461
lines changed

include/swift/IDE/AfterPoundExprCompletion.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class AfterPoundExprCompletion : public TypeCheckCompletionCallback {
4747
: CompletionExpr(CompletionExpr), DC(DC), ParentStmtKind(ParentStmtKind) {
4848
}
4949

50-
void deliverResults(ide::CodeCompletionContext &CompletionCtx,
51-
CodeCompletionConsumer &Consumer);
50+
void collectResults(ide::CodeCompletionContext &CompletionCtx);
5251
};
5352

5453
} // end namespace ide

include/swift/IDE/ArgumentCompletion.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,48 @@ class ArgumentTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
2525
struct Result {
2626
/// The type associated with the code completion expression itself.
2727
Type ExpectedType;
28+
2829
/// The expected return type of the function call.
2930
Type ExpectedCallType;
31+
3032
/// True if this is a subscript rather than a function call.
3133
bool IsSubscript;
34+
3235
/// The FuncDecl or SubscriptDecl associated with the call.
3336
ValueDecl *FuncD;
37+
3438
/// The type of the function being called.
3539
AnyFunctionType *FuncTy;
40+
3641
/// The index of the argument containing the completion location
3742
unsigned ArgIdx;
43+
3844
/// The index of the parameter corresponding to the completion argument.
3945
llvm::Optional<unsigned> ParamIdx;
46+
4047
/// The indices of all params that were bound to non-synthesized
4148
/// arguments. Used so we don't suggest them even when the args are out of
4249
/// order.
4350
std::set<unsigned> ClaimedParamIndices;
51+
4452
/// True if the completion is a noninitial term in a variadic argument.
4553
bool IsNoninitialVariadic;
54+
4655
/// The base type of the call/subscript (null for free functions).
4756
Type BaseType;
57+
4858
/// True if an argument label precedes the completion location.
4959
bool HasLabel;
60+
61+
/// The argument index of the first trailing closure.
62+
///
63+
/// \c None if the call doesn't have a trailing closure.
64+
llvm::Optional<unsigned> FirstTrailingClosureIndex;
65+
5066
/// Whether the surrounding context is async and thus calling async
5167
/// functions is supported.
5268
bool IsInAsyncContext;
69+
5370
/// A bitfield to mark whether the parameter at a given index is optional.
5471
/// Parameters can be optional if they have a default argument or belong to
5572
/// a parameter pack.
@@ -93,9 +110,12 @@ class ArgumentTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
93110
/// function signature instead of suggesting individual labels. Used when
94111
/// completing after the opening '(' of a function call \param Loc The
95112
/// location of the code completion token
96-
void deliverResults(bool IncludeSignature, SourceLoc Loc, DeclContext *DC,
97-
CodeCompletionContext &CompletionCtx,
98-
CodeCompletionConsumer &Consumer);
113+
/// \param IsLabeledTrailingClosure Whether we are completing the label of a
114+
/// labeled trailing closure, ie. if the code completion location is outside
115+
/// the call after the first trailing closure of the call.
116+
void collectResults(bool IncludeSignature, bool IsLabeledTrailingClosure,
117+
SourceLoc Loc, DeclContext *DC,
118+
CodeCompletionContext &CompletionCtx);
99119
};
100120

101121
} // end namespace ide

include/swift/IDE/CodeCompletion.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ void postProcessCompletionResults(
6565
MutableArrayRef<CodeCompletionResult *> results, CompletionKind Kind,
6666
const DeclContext *DC, CodeCompletionResultSink *Sink);
6767

68-
void deliverCompletionResults(CodeCompletionContext &CompletionContext,
68+
void collectCompletionResults(CodeCompletionContext &CompletionContext,
6969
CompletionLookup &Lookup, DeclContext *DC,
70-
CodeCompletionConsumer &Consumer);
70+
const ExpectedTypeContext &TypeContext,
71+
bool CanCurrDeclContextHandleAsync);
7172

7273
/// Create a factory for code completion callbacks.
7374
IDEInspectionCallbacksFactory *

include/swift/IDE/CodeCompletionConsumer.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,9 @@ namespace ide {
2222
struct RequestedCachedModule;
2323

2424
/// An abstract base class for consumers of code completion results.
25-
/// \see \c SimpleCachingCodeCompletionConsumer.
2625
class CodeCompletionConsumer {
2726
public:
2827
virtual ~CodeCompletionConsumer() {}
29-
virtual void
30-
handleResultsAndModules(CodeCompletionContext &context,
31-
ArrayRef<RequestedCachedModule> requestedModules,
32-
const ExpectedTypeContext *TypeContext,
33-
const DeclContext *DC,
34-
bool CanCurrDeclContextHandleAsync) = 0;
35-
};
36-
37-
/// A simplified code completion consumer interface that clients can use to get
38-
/// CodeCompletionResults with automatic caching of top-level completions from
39-
/// imported modules.
40-
struct SimpleCachingCodeCompletionConsumer : public CodeCompletionConsumer {
41-
42-
// Implement the CodeCompletionConsumer interface.
43-
void handleResultsAndModules(CodeCompletionContext &context,
44-
ArrayRef<RequestedCachedModule> requestedModules,
45-
const ExpectedTypeContext *TypeContext,
46-
const DeclContext *DCForModules,
47-
bool CanCurrDeclContextHandleAsync) override;
48-
4928
/// Clients should override this method to receive \p Results.
5029
virtual void handleResults(CodeCompletionContext &context) = 0;
5130
};

include/swift/IDE/CodeCompletionContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace swift {
2020
namespace ide {
2121

2222
class CodeCompletionCache;
23+
struct RequestedCachedModule;
2324

2425
class CodeCompletionContext {
2526
friend class CodeCompletionResultBuilder;
@@ -103,6 +104,13 @@ class CodeCompletionContext {
103104
sortCompletionResults(ArrayRef<CodeCompletionResult *> Results);
104105

105106
CodeCompletionResultSink &getResultSink() { return CurrentResults; }
107+
108+
/// Add code completion results from the given requested modules to this
109+
/// context.
110+
void addResultsFromModules(ArrayRef<RequestedCachedModule> RequestedModules,
111+
const ExpectedTypeContext &TypeContext,
112+
const DeclContext *DC,
113+
bool CanCurrDeclContextHandleAsync);
106114
};
107115

108116
} // end namespace ide

include/swift/IDE/CodeCompletionResult.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ enum class CompletionKind : uint8_t {
211211
EffectsSpecifier,
212212
PoundAvailablePlatform,
213213
CallArg,
214-
LabeledTrailingClosure,
215214
ReturnStmtExpr,
216215
ThenStmtExpr,
217216
YieldStmtExpr,

include/swift/IDE/CodeCompletionResultType.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ class ExpectedTypeContext {
7474
}
7575
}
7676

77+
/// Form a union of this expected type context with \p Other.
78+
///
79+
/// Any possible type from either type context will be considered a possible
80+
/// type in the merged type context.
81+
void merge(const ExpectedTypeContext &Other) {
82+
PossibleTypes.append(Other.PossibleTypes);
83+
84+
// We can't merge ideal types. If they are different, setting to a null type
85+
// is the best thing we can do.
86+
if (!IdealType || !Other.IdealType || !IdealType->isEqual(Other.IdealType)) {
87+
IdealType = Type();
88+
}
89+
IsImplicitSingleExpressionReturn |= Other.IsImplicitSingleExpressionReturn;
90+
PreferNonVoid &= Other.PreferNonVoid;
91+
ExpectedCustomAttributeKinds |= Other.ExpectedCustomAttributeKinds;
92+
}
93+
7794
Type getIdealType() const { return IdealType; }
7895

7996
void setIdealType(Type IdealType) { this->IdealType = IdealType; }

include/swift/IDE/ExprCompletion.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ class ExprTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
9090
AddUnresolvedMemberCompletions(AddUnresolvedMemberCompletions) {}
9191

9292
/// \param CCLoc The location of the code completion token.
93-
void deliverResults(SourceLoc CCLoc,
94-
ide::CodeCompletionContext &CompletionCtx,
95-
CodeCompletionConsumer &Consumer);
93+
void collectResults(SourceLoc CCLoc,
94+
ide::CodeCompletionContext &CompletionCtx);
9695
};
9796

9897
} // end namespace ide

include/swift/IDE/KeyPathCompletion.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ class KeyPathTypeCheckCompletionCallback : public TypeCheckCompletionCallback {
3737
public:
3838
KeyPathTypeCheckCompletionCallback(KeyPathExpr *KeyPath) : KeyPath(KeyPath) {}
3939

40-
void deliverResults(DeclContext *DC, SourceLoc DotLoc,
41-
ide::CodeCompletionContext &CompletionCtx,
42-
CodeCompletionConsumer &Consumer);
40+
void collectResults(DeclContext *DC, SourceLoc DotLoc,
41+
ide::CodeCompletionContext &CompletionCtx);
4342
};
4443

4544
} // end namespace ide

include/swift/IDE/PostfixCompletion.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ class PostfixCompletionCallback : public TypeCheckCompletionCallback {
103103
/// \p DotLoc is invalid
104104
/// \param HasLeadingSpace Whether there is a space separating the exiting
105105
/// expression and the code completion token.
106-
void deliverResults(SourceLoc DotLoc, bool IsInSelector,
106+
void collectResults(SourceLoc DotLoc, bool IsInSelector,
107107
bool IncludeOperators, bool HasLeadingSpace,
108-
CodeCompletionContext &CompletionCtx,
109-
CodeCompletionConsumer &Consumer);
108+
CodeCompletionContext &CompletionCtx);
110109
};
111110

112111
} // end namespace ide

0 commit comments

Comments
 (0)