[SourceKit] Explicitly specify frontend action type when creating compiler invocation

Explicitly specify the frontend action to make sure we aren’t loading thes stdlib if the performed action is syntactic only.
This commit is contained in:
Alex Hoppen
2021-11-17 11:40:30 +01:00
parent 63c31033fc
commit 22f67e89a6
10 changed files with 93 additions and 70 deletions

View File

@@ -1417,7 +1417,8 @@ void SwiftLangSupport::findLocalRenameRanges(
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
CategorizedRenameRangesReceiver Receiver) {
std::string Error;
SwiftInvocationRef Invok = ASTMgr->getInvocation(Args, Filename, Error);
SwiftInvocationRef Invok =
ASTMgr->getTypecheckInvocation(Args, Filename, Error);
if (!Invok) {
LOG_WARN_FUNC("failed to create an ASTInvocation: " << Error);
Receiver(RequestResult<ArrayRef<CategorizedRenameRanges>>::fromError(Error));
@@ -1465,7 +1466,8 @@ SourceFile *SwiftLangSupport::getSyntacticSourceFile(
CompilerInvocation Invocation;
bool Failed = getASTManager()->initCompilerInvocationNoInputs(
Invocation, Args, ParseCI.getDiags(), Error);
Invocation, Args, FrontendOptions::ActionType::Parse, ParseCI.getDiags(),
Error);
if (Failed) {
Error = "Compiler invocation init failed";
return nullptr;
@@ -1518,7 +1520,8 @@ void SwiftLangSupport::getDocInfo(llvm::MemoryBuffer *InputBuf,
CompilerInvocation Invocation;
std::string Error;
bool Failed = getASTManager()->initCompilerInvocationNoInputs(
Invocation, Args, CI.getDiags(), Error, /*AllowInputs=*/false);
Invocation, Args, FrontendOptions::ActionType::Typecheck, CI.getDiags(),
Error, /*AllowInputs=*/false);
if (Failed) {
Consumer.failed(Error);
@@ -1551,8 +1554,9 @@ findModuleGroups(StringRef ModuleName, ArrayRef<const char *> Args,
PrintingDiagnosticConsumer PrintDiags;
CI.addDiagnosticConsumer(&PrintDiags);
std::string Error;
if (getASTManager()->initCompilerInvocationNoInputs(Invocation, Args,
CI.getDiags(), Error)) {
if (getASTManager()->initCompilerInvocationNoInputs(
Invocation, Args, FrontendOptions::ActionType::Typecheck,
CI.getDiags(), Error)) {
Receiver(RequestResult<ArrayRef<StringRef>>::fromError(Error));
return;
}
@@ -1563,12 +1567,6 @@ findModuleGroups(StringRef ModuleName, ArrayRef<const char *> Args,
// Load standard library so that Clang importer can use it.
ASTContext &Ctx = CI.getASTContext();
auto *Stdlib = Ctx.getModuleByIdentifier(Ctx.StdlibModuleName);
if (!Stdlib) {
Error = "Cannot load stdlib.";
Receiver(RequestResult<ArrayRef<StringRef>>::fromError(Error));
return;
}
auto *M = Ctx.getModuleByName(ModuleName);
if (!M) {
Error = "Cannot find the module.";