|
15 | 15 | #include "swift/AST/GenericEnvironment.h" |
16 | 16 | #include "swift/AST/NameLookup.h" |
17 | 17 | #include "swift/AST/USRGeneration.h" |
| 18 | +#include "swift/IDE/TypeCheckCompletionCallback.h" |
18 | 19 | #include "swift/Parse/IDEInspectionCallbacks.h" |
| 20 | +#include "swift/Sema/ConstraintSystem.h" |
19 | 21 | #include "swift/Sema/IDETypeChecking.h" |
20 | 22 | #include "clang/AST/Attr.h" |
21 | 23 | #include "clang/AST/Decl.h" |
@@ -85,19 +87,42 @@ void ContextInfoCallbacks::completeCaseStmtBeginning(CodeCompletionExpr *E) { |
85 | 87 | // TODO: Implement? |
86 | 88 | } |
87 | 89 |
|
| 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 | + |
88 | 109 | void ContextInfoCallbacks::doneParsing(SourceFile *SrcFile) { |
89 | 110 | if (!ParsedExpr) |
90 | 111 | return; |
91 | 112 |
|
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 | + } |
96 | 121 |
|
97 | 122 | llvm::SmallSet<CanType, 2> seenTypes; |
98 | 123 | SmallVector<TypeContextInfoItem, 2> results; |
99 | 124 |
|
100 | | - for (auto T : Info.getPossibleTypes()) { |
| 125 | + for (auto T : TypeCheckCallback.getTypes()) { |
101 | 126 | if (T->is<ErrorType>() || T->is<UnresolvedType>()) |
102 | 127 | continue; |
103 | 128 |
|
|
0 commit comments