Skip to content

Commit ababdca

Browse files
authored
Merge pull request #63859 from ahoppen/ahoppen/typecontextinfo-solver-based
[IDE] Migrate TypeContextInfo to solver-based
2 parents 61629ea + 39668a8 commit ababdca

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

lib/IDE/TypeContextInfo.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#include "swift/AST/GenericEnvironment.h"
1616
#include "swift/AST/NameLookup.h"
1717
#include "swift/AST/USRGeneration.h"
18+
#include "swift/IDE/TypeCheckCompletionCallback.h"
1819
#include "swift/Parse/IDEInspectionCallbacks.h"
20+
#include "swift/Sema/ConstraintSystem.h"
1921
#include "swift/Sema/IDETypeChecking.h"
2022
#include "clang/AST/Attr.h"
2123
#include "clang/AST/Decl.h"
@@ -85,19 +87,42 @@ void ContextInfoCallbacks::completeCaseStmtBeginning(CodeCompletionExpr *E) {
8587
// TODO: Implement?
8688
}
8789

90+
class TypeContextInfoCallback : public TypeCheckCompletionCallback {
91+
Expr *ParsedExpr;
92+
SmallVector<Type, 2> Types;
93+
94+
void sawSolutionImpl(const constraints::Solution &S) override {
95+
if (!S.hasType(ParsedExpr)) {
96+
return;
97+
}
98+
if (Type T = getTypeForCompletion(S, ParsedExpr)) {
99+
Types.push_back(T);
100+
}
101+
}
102+
103+
public:
104+
TypeContextInfoCallback(Expr *ParsedExpr) : ParsedExpr(ParsedExpr) {}
105+
106+
ArrayRef<Type> getTypes() const { return Types; }
107+
};
108+
88109
void ContextInfoCallbacks::doneParsing(SourceFile *SrcFile) {
89110
if (!ParsedExpr)
90111
return;
91112

92-
typeCheckContextAt(TypeCheckASTNodeAtLocContext::declContext(CurDeclContext),
93-
ParsedExpr->getLoc());
94-
95-
ExprContextInfo Info(CurDeclContext, ParsedExpr);
113+
TypeContextInfoCallback TypeCheckCallback(ParsedExpr);
114+
{
115+
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
116+
Context.CompletionCallback, &TypeCheckCallback);
117+
typeCheckContextAt(
118+
TypeCheckASTNodeAtLocContext::declContext(CurDeclContext),
119+
ParsedExpr->getLoc());
120+
}
96121

97122
llvm::SmallSet<CanType, 2> seenTypes;
98123
SmallVector<TypeContextInfoItem, 2> results;
99124

100-
for (auto T : Info.getPossibleTypes()) {
125+
for (auto T : TypeCheckCallback.getTypes()) {
101126
if (T->is<ErrorType>() || T->is<UnresolvedType>())
102127
continue;
103128

0 commit comments

Comments
 (0)