mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user