mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SourceKit] Fix “Assertion `!GlibcModuleMapPath.empty()' failed” on Linux
https://bugs.swift.org/browse/SR-4490
This commit is contained in:
@@ -225,8 +225,9 @@ public:
|
||||
|
||||
}
|
||||
|
||||
static bool makeParserAST(CompilerInstance &CI, StringRef Text) {
|
||||
CompilerInvocation Invocation;
|
||||
static bool makeParserAST(CompilerInstance &CI, StringRef Text,
|
||||
CompilerInvocation Invocation) {
|
||||
Invocation.clearInputs();
|
||||
Invocation.setModuleName("main");
|
||||
Invocation.setInputKind(InputFileKind::IFK_Swift);
|
||||
|
||||
@@ -358,6 +359,7 @@ SwiftInterfaceGenContextRef
|
||||
SwiftInterfaceGenContext::createForSwiftSource(StringRef DocumentName,
|
||||
StringRef SourceFileName,
|
||||
ASTUnitRef AstUnit,
|
||||
CompilerInvocation Invocation,
|
||||
std::string &ErrMsg) {
|
||||
SwiftInterfaceGenContextRef IFaceGenCtx{ new SwiftInterfaceGenContext() };
|
||||
IFaceGenCtx->Impl.DocumentName = DocumentName;
|
||||
@@ -371,7 +373,8 @@ SwiftInterfaceGenContext::createForSwiftSource(StringRef DocumentName,
|
||||
AnnotatingPrinter Printer(IFaceGenCtx->Impl.Info, OS);
|
||||
printSwiftSourceInterface(AstUnit->getPrimarySourceFile(), Printer, Options);
|
||||
IFaceGenCtx->Impl.Info.Text = OS.str();
|
||||
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
|
||||
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
|
||||
Invocation)) {
|
||||
ErrMsg = "Error during syntactic parsing";
|
||||
return nullptr;
|
||||
}
|
||||
@@ -434,7 +437,8 @@ SwiftInterfaceGenContext::create(StringRef DocumentName,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
|
||||
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
|
||||
Invocation)) {
|
||||
ErrMsg = "Error during syntactic parsing";
|
||||
return nullptr;
|
||||
}
|
||||
@@ -482,7 +486,8 @@ SwiftInterfaceGenContext::createForTypeInterface(CompilerInvocation Invocation,
|
||||
IFaceGenCtx->Impl.DocumentName, ErrorMsg))
|
||||
return nullptr;
|
||||
IFaceGenCtx->Impl.Info.Text = OS.str();
|
||||
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
|
||||
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
|
||||
Invocation)) {
|
||||
ErrorMsg = "Error during syntactic parsing";
|
||||
return nullptr;
|
||||
}
|
||||
@@ -738,22 +743,26 @@ class PrimaryFileInterfaceConsumer : public SwiftASTConsumer {
|
||||
std::string SourceFileName;
|
||||
SwiftInterfaceGenMap &Contexts;
|
||||
std::shared_ptr<EditorConsumer> Consumer;
|
||||
SwiftInvocationRef ASTInvok;
|
||||
|
||||
public:
|
||||
PrimaryFileInterfaceConsumer(StringRef Name, StringRef SourceFileName,
|
||||
SwiftInterfaceGenMap &Contexts,
|
||||
std::shared_ptr<EditorConsumer> Consumer) :
|
||||
std::shared_ptr<EditorConsumer> Consumer,
|
||||
SwiftInvocationRef ASTInvok) :
|
||||
Name(Name), SourceFileName(SourceFileName), Contexts(Contexts),
|
||||
Consumer(Consumer) {}
|
||||
Consumer(Consumer), ASTInvok(ASTInvok) {}
|
||||
|
||||
void failed(StringRef Error) override {
|
||||
Consumer->handleRequestError(Error.data());
|
||||
}
|
||||
|
||||
void handlePrimaryAST(ASTUnitRef AstUnit) override {
|
||||
CompilerInvocation CompInvok;
|
||||
ASTInvok->applyTo(CompInvok);
|
||||
std::string Error;
|
||||
auto IFaceGenRef = SwiftInterfaceGenContext::createForSwiftSource(Name,
|
||||
SourceFileName, AstUnit, Error);
|
||||
SourceFileName, AstUnit, CompInvok, Error);
|
||||
if (!Error.empty())
|
||||
Consumer->handleRequestError(Error.data());
|
||||
Contexts.set(Name, IFaceGenRef);
|
||||
@@ -782,7 +791,7 @@ void SwiftLangSupport::editorOpenSwiftSourceInterface(StringRef Name,
|
||||
std::make_pair("SourceName", SourceName)});
|
||||
}
|
||||
auto AstConsumer = std::make_shared<PrimaryFileInterfaceConsumer>(Name,
|
||||
SourceName, IFaceGenContexts, Consumer);
|
||||
SourceName, IFaceGenContexts, Consumer, Invocation);
|
||||
static const char OncePerASTToken = 0;
|
||||
getASTManager().processASTAsync(Invocation, AstConsumer, &OncePerASTToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user