Skip to content

Commit 3c9f3c8

Browse files
committed
SourceKit: Use actual diagnostics for arg parsing
With this change, you will no longer receive "error when parsing the compiler arguments". Instead, you will receive the underlying error, like "error: unable to load output file map 'output_file_map.json': No such file or directory"
1 parent c932f60 commit 3c9f3c8

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,18 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
438438
Args.push_back(Impl.RuntimeResourcePath.c_str());
439439
Args.append(OrigArgs.begin(), OrigArgs.end());
440440

441+
SmallString<32> ErrStr;
442+
llvm::raw_svector_ostream ErrOS(ErrStr);
443+
StreamDiagConsumer DiagConsumer(ErrOS);
444+
Diags.addConsumer(DiagConsumer);
445+
441446
bool HadError = driver::getSingleFrontendInvocationFromDriverArguments(
442447
Args, Diags, [&](ArrayRef<const char *> FrontendArgs) {
443448
return Invocation.parseArgs(FrontendArgs, Diags);
444449
});
445450

446451
if (HadError) {
447-
// FIXME: Get the actual diagnostic.
448-
Error = "error when parsing the compiler arguments";
452+
Error = ErrOS.str();
449453
return true;
450454
}
451455

@@ -493,20 +497,9 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &CompInvok,
493497
ArrayRef<const char *> OrigArgs,
494498
StringRef PrimaryFile,
495499
std::string &Error) {
496-
497-
SmallString<32> ErrStr;
498-
llvm::raw_svector_ostream ErrOS(ErrStr);
499500
DiagnosticEngine Diagnostics(Impl.SourceMgr);
500-
StreamDiagConsumer DiagConsumer(ErrOS);
501-
Diagnostics.addConsumer(DiagConsumer);
502-
503-
if (initCompilerInvocation(CompInvok, OrigArgs, Diagnostics, PrimaryFile,
504-
Error)) {
505-
if (!ErrOS.str().empty())
506-
Error = ErrOS.str();
507-
return true;
508-
}
509-
return false;
501+
return initCompilerInvocation(CompInvok, OrigArgs, Diagnostics, PrimaryFile,
502+
Error);
510503
}
511504

512505
bool SwiftASTManager::initCompilerInvocationNoInputs(

0 commit comments

Comments
 (0)