SourceKit/ExpressionType: allow users to canonicalize collected expression types

The default response of the expression type request doesn't canonicalize expression
types. This patch adds a flag to allow users to canonicalize them.
This commit is contained in:
Xi Ge
2019-06-28 11:36:37 -07:00
parent 310f028d9e
commit ff32d5899a
10 changed files with 59 additions and 16 deletions

View File

@@ -2092,6 +2092,7 @@ semanticRefactoring(StringRef Filename, SemanticRefactoringInfo Info,
void SwiftLangSupport::collectExpressionTypes(StringRef FileName,
ArrayRef<const char *> Args,
ArrayRef<const char *> ExpectedProtocols,
bool CanonicalType,
std::function<void(const RequestResult<ExpressionTypesInFile> &)> Receiver) {
std::string Error;
SwiftInvocationRef Invok = ASTMgr->getInvocation(Args, FileName, Error);
@@ -2104,18 +2105,23 @@ void SwiftLangSupport::collectExpressionTypes(StringRef FileName,
class ExpressionTypeCollector: public SwiftASTConsumer {
std::function<void(const RequestResult<ExpressionTypesInFile> &)> Receiver;
std::vector<const char *> ExpectedProtocols;
bool CanonicalType;
public:
ExpressionTypeCollector(
std::function<void(const RequestResult<ExpressionTypesInFile> &)> Receiver,
ArrayRef<const char *> ExpectedProtocols): Receiver(std::move(Receiver)),
ExpectedProtocols(ExpectedProtocols.vec()) {}
ArrayRef<const char *> ExpectedProtocols,
bool CanonicalType):
Receiver(std::move(Receiver)),
ExpectedProtocols(ExpectedProtocols.vec()),
CanonicalType(CanonicalType) {}
void handlePrimaryAST(ASTUnitRef AstUnit) override {
auto *SF = AstUnit->getCompilerInstance().getPrimarySourceFile();
std::vector<ExpressionTypeInfo> Scratch;
llvm::SmallString<256> TypeBuffer;
llvm::raw_svector_ostream OS(TypeBuffer);
ExpressionTypesInFile Result;
for (auto Item: collectExpressionType(*SF, ExpectedProtocols, Scratch, OS)) {
for (auto Item: collectExpressionType(*SF, ExpectedProtocols, Scratch,
CanonicalType, OS)) {
Result.Results.push_back({Item.offset, Item.length, Item.typeOffset, {}});
for (auto P: Item.protocols) {
Result.Results.back().ProtocolOffsets.push_back(P.first);
@@ -2134,7 +2140,8 @@ void SwiftLangSupport::collectExpressionTypes(StringRef FileName,
}
};
auto Collector = std::make_shared<ExpressionTypeCollector>(Receiver,
ExpectedProtocols);
ExpectedProtocols,
CanonicalType);
/// FIXME: When request cancellation is implemented and Xcode adopts it,
/// don't use 'OncePerASTToken'.
static const char OncePerASTToken = 0;