Skip to content

Commit 5588a11

Browse files
authored
Merge pull request #22762 from rintaro/5.1-sourcekit-conformingmethods
[5.1][IDE/SourceKit] New SourceKit request for filtered method list
2 parents 4cc52aa + 4997a3f commit 5588a11

24 files changed

+1075
-227
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===--- ConformingMethodList.h --- -----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_IDE_CONFORMINGMETHODLIST_H
14+
#define SWIFT_IDE_CONFORMINGMETHODLIST_H
15+
16+
#include "swift/AST/Type.h"
17+
#include "swift/Basic/LLVM.h"
18+
19+
namespace swift {
20+
class CodeCompletionCallbacksFactory;
21+
22+
namespace ide {
23+
24+
/// A result item for context info query.
25+
class ConformingMethodListResult {
26+
public:
27+
/// The decl context of the parsed expression.
28+
DeclContext *DC;
29+
30+
/// The resolved type of the expression.
31+
Type ExprType;
32+
33+
/// Methods which satisfy the criteria.
34+
SmallVector<ValueDecl *, 0> Members;
35+
36+
ConformingMethodListResult(DeclContext *DC, Type ExprType)
37+
: DC(DC), ExprType(ExprType) {}
38+
};
39+
40+
/// An abstract base class for consumers of context info results.
41+
class ConformingMethodListConsumer {
42+
public:
43+
virtual ~ConformingMethodListConsumer() {}
44+
virtual void handleResult(const ConformingMethodListResult &result) = 0;
45+
};
46+
47+
/// Printing consumer
48+
class PrintingConformingMethodListConsumer
49+
: public ConformingMethodListConsumer {
50+
llvm::raw_ostream &OS;
51+
52+
public:
53+
PrintingConformingMethodListConsumer(llvm::raw_ostream &OS) : OS(OS) {}
54+
55+
void handleResult(const ConformingMethodListResult &result) override;
56+
};
57+
58+
/// Create a factory for code completion callbacks.
59+
CodeCompletionCallbacksFactory *makeConformingMethodListCallbacksFactory(
60+
ArrayRef<const char *> expectedTypeNames,
61+
ConformingMethodListConsumer &Consumer);
62+
63+
} // namespace ide
64+
} // namespace swift
65+
66+
#endif // SWIFT_IDE_CONFORMINGMETHODLIST_H

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -117,114 +117,114 @@ class CodeCompletionCallbacks {
117117

118118
/// Complete the whole expression. This is a fallback that should
119119
/// produce results when more specific completion methods failed.
120-
virtual void completeExpr() = 0;
120+
virtual void completeExpr() {};
121121

122122
/// Complete expr-dot after we have consumed the dot.
123-
virtual void completeDotExpr(Expr *E, SourceLoc DotLoc) = 0;
123+
virtual void completeDotExpr(Expr *E, SourceLoc DotLoc) {};
124124

125125
/// Complete the beginning of a statement or expression.
126-
virtual void completeStmtOrExpr() = 0;
126+
virtual void completeStmtOrExpr() {};
127127

128128
/// Complete the beginning of expr-postfix -- no tokens provided
129129
/// by user.
130-
virtual void completePostfixExprBeginning(CodeCompletionExpr *E) = 0;
130+
virtual void completePostfixExprBeginning(CodeCompletionExpr *E) {};
131131

132132
/// Complete the beginning of expr-postfix in a for-each loop sequqence
133133
/// -- no tokens provided by user.
134-
virtual void completeForEachSequenceBeginning(CodeCompletionExpr *E) = 0;
134+
virtual void completeForEachSequenceBeginning(CodeCompletionExpr *E) {};
135135

136136
/// Complete a given expr-postfix.
137-
virtual void completePostfixExpr(Expr *E, bool hasSpace) = 0;
137+
virtual void completePostfixExpr(Expr *E, bool hasSpace) {};
138138

139139
/// Complete a given expr-postfix, given that there is a following
140140
/// left parenthesis.
141-
virtual void completePostfixExprParen(Expr *E, Expr *CodeCompletionE) = 0;
141+
virtual void completePostfixExprParen(Expr *E, Expr *CodeCompletionE) {};
142142

143143
/// Complete expr-super after we have consumed the 'super' keyword.
144-
virtual void completeExprSuper(SuperRefExpr *SRE) = 0;
144+
virtual void completeExprSuper(SuperRefExpr *SRE) {};
145145

146146
/// Complete expr-super after we have consumed the 'super' keyword and
147147
/// a dot.
148-
virtual void completeExprSuperDot(SuperRefExpr *SRE) = 0;
148+
virtual void completeExprSuperDot(SuperRefExpr *SRE) {};
149149

150150
/// Complete the argument to an Objective-C #keyPath
151151
/// expression.
152152
///
153153
/// \param KPE A partial #keyPath expression that can be used to
154154
/// provide context. This will be \c NULL if no components of the
155155
/// #keyPath argument have been parsed yet.
156-
virtual void completeExprKeyPath(KeyPathExpr *KPE, SourceLoc DotLoc) = 0;
156+
virtual void completeExprKeyPath(KeyPathExpr *KPE, SourceLoc DotLoc) {};
157157

158158
/// Complete the beginning of type-simple -- no tokens provided
159159
/// by user.
160-
virtual void completeTypeSimpleBeginning() = 0;
160+
virtual void completeTypeSimpleBeginning() {};
161161

162162
/// Complete a given type-identifier after we have consumed the dot.
163-
virtual void completeTypeIdentifierWithDot(IdentTypeRepr *ITR) = 0;
163+
virtual void completeTypeIdentifierWithDot(IdentTypeRepr *ITR) {};
164164

165165
/// Complete a given type-identifier when there is no trailing dot.
166-
virtual void completeTypeIdentifierWithoutDot(IdentTypeRepr *ITR) = 0;
166+
virtual void completeTypeIdentifierWithoutDot(IdentTypeRepr *ITR) {};
167167

168168
/// Complete at the beginning of a case stmt pattern.
169-
virtual void completeCaseStmtBeginning() = 0;
169+
virtual void completeCaseStmtBeginning() {};
170170

171171
/// Complete a case stmt pattern that starts with a dot.
172-
virtual void completeCaseStmtDotPrefix() = 0;
172+
virtual void completeCaseStmtDotPrefix() {};
173173

174174
/// Complete at the beginning of member of a nominal decl member -- no tokens
175175
/// provided by user.
176176
virtual void completeNominalMemberBeginning(
177-
SmallVectorImpl<StringRef> &Keywords) = 0;
177+
SmallVectorImpl<StringRef> &Keywords) {};
178178

179179
/// Complete at the beginning of accessor in a accessor block.
180-
virtual void completeAccessorBeginning() = 0;
180+
virtual void completeAccessorBeginning() {};
181181

182182
/// Complete the keyword in attribute, for instance, @available.
183-
virtual void completeDeclAttrKeyword(Decl *D, bool Sil, bool Param) = 0;
183+
virtual void completeDeclAttrKeyword(Decl *D, bool Sil, bool Param) {};
184184

185185
/// Complete the parameters in attribute, for instance, version specifier for
186186
/// @available.
187-
virtual void completeDeclAttrParam(DeclAttrKind DK, int Index) = 0;
187+
virtual void completeDeclAttrParam(DeclAttrKind DK, int Index) {};
188188

189189
/// Complete within a precedence group decl or after a colon in an
190190
/// operator decl.
191-
virtual void completeInPrecedenceGroup(SyntaxKind SK) = 0;
191+
virtual void completeInPrecedenceGroup(SyntaxKind SK) {};
192192

193193
/// Complete the platform names inside #available statements.
194-
virtual void completePoundAvailablePlatform() = 0;
194+
virtual void completePoundAvailablePlatform() {};
195195

196196
/// Complete the import decl with importable modules.
197197
virtual void
198-
completeImportDecl(std::vector<std::pair<Identifier, SourceLoc>> &Path) = 0;
198+
completeImportDecl(std::vector<std::pair<Identifier, SourceLoc>> &Path) {};
199199

200200
/// Complete unresolved members after dot.
201201
virtual void completeUnresolvedMember(CodeCompletionExpr *E,
202-
SourceLoc DotLoc) = 0;
202+
SourceLoc DotLoc) {};
203203

204-
virtual void completeAssignmentRHS(AssignExpr *E) = 0;
204+
virtual void completeAssignmentRHS(AssignExpr *E) {};
205205

206-
virtual void completeCallArg(CodeCompletionExpr *E) = 0;
206+
virtual void completeCallArg(CodeCompletionExpr *E) {};
207207

208-
virtual void completeReturnStmt(CodeCompletionExpr *E) = 0;
208+
virtual void completeReturnStmt(CodeCompletionExpr *E) {};
209209

210210
/// Complete a yield statement. A missing yield index means that the
211211
/// completion immediately follows the 'yield' keyword; it may be either
212212
/// an expresion or a parenthesized expression list. A present yield
213213
/// index means that the completion is within the parentheses and is
214214
/// for a specific yield value.
215215
virtual void completeYieldStmt(CodeCompletionExpr *E,
216-
Optional<unsigned> yieldIndex) = 0;
216+
Optional<unsigned> yieldIndex) {};
217217

218218
virtual void completeAfterPoundExpr(CodeCompletionExpr *E,
219-
Optional<StmtKind> ParentKind) = 0;
219+
Optional<StmtKind> ParentKind) {};
220220

221-
virtual void completeAfterPoundDirective() = 0;
221+
virtual void completeAfterPoundDirective() {};
222222

223-
virtual void completePlatformCondition() = 0;
223+
virtual void completePlatformCondition() {};
224224

225-
virtual void completeAfterIfStmt(bool hasElse) = 0;
225+
virtual void completeAfterIfStmt(bool hasElse) {};
226226

227-
virtual void completeGenericParams(TypeLoc TL) = 0;
227+
virtual void completeGenericParams(TypeLoc TL) {};
228228

229229
/// Signals that the AST for the all the delayed-parsed code was
230230
/// constructed. No \c complete*() callbacks will be done after this.

lib/IDE/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_swift_host_library(swiftIDE STATIC
22
CodeCompletion.cpp
33
CodeCompletionCache.cpp
44
CommentConversion.cpp
5+
ConformingMethodList.cpp
56
ExprContextAnalysis.cpp
67
Formatting.cpp
78
Refactoring.cpp

lib/IDE/CodeCompletion.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -374,48 +374,6 @@ static Stmt *findNearestStmt(const DeclContext *DC, SourceLoc Loc,
374374
const_cast<DeclContext *>(DC)->walkContext(Finder);
375375
return Finder.getFoundStmt();
376376
}
377-
/// Prepare the given expression for type-checking again, prinicipally by
378-
/// erasing any ErrorType types on the given expression, allowing later
379-
/// type-checking to make progress.
380-
///
381-
/// FIXME: this is fundamentally a workaround for the fact that we may end up
382-
/// typechecking parts of an expression more than once - first for checking
383-
/// the context, and later for checking more-specific things like unresolved
384-
/// members. We should restructure code-completion type-checking so that we
385-
/// never typecheck more than once (or find a more principled way to do it).
386-
static void prepareForRetypechecking(Expr *E) {
387-
assert(E);
388-
struct Eraser : public ASTWalker {
389-
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
390-
if (expr && expr->getType() && (expr->getType()->hasError() ||
391-
expr->getType()->hasUnresolvedType()))
392-
expr->setType(Type());
393-
if (auto *ACE = dyn_cast_or_null<AutoClosureExpr>(expr)) {
394-
return { true, ACE->getSingleExpressionBody() };
395-
}
396-
return { true, expr };
397-
}
398-
bool walkToTypeLocPre(TypeLoc &TL) override {
399-
if (TL.getType() && (TL.getType()->hasError() ||
400-
TL.getType()->hasUnresolvedType()))
401-
TL.setType(Type());
402-
return true;
403-
}
404-
405-
std::pair<bool, Pattern*> walkToPatternPre(Pattern *P) override {
406-
if (P && P->hasType() && (P->getType()->hasError() ||
407-
P->getType()->hasUnresolvedType())) {
408-
P->setType(Type());
409-
}
410-
return { true, P };
411-
}
412-
std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override {
413-
return { false, S };
414-
}
415-
};
416-
417-
E->walk(Eraser());
418-
}
419377

420378
CodeCompletionString::CodeCompletionString(ArrayRef<Chunk> Chunks) {
421379
std::uninitialized_copy(Chunks.begin(), Chunks.end(),

0 commit comments

Comments
 (0)