Skip to content

Commit c3e5d63

Browse files
committed
[sourcekit] Send notification if compiler argument parsing fails in editor.open
Since we will not reach `createAST` where we would normally send the notification, send one from `getInvocation` when it fails. rdar://39225180
1 parent 97b7353 commit c3e5d63

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

test/SourceKit/CompileNotifications/arg-parsing.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: not %sourcekitd-test -req=track-compiles == -req=complete %s -offset=0 -- %s -no-such-arg | %FileCheck %s -check-prefix=ARG_PARSE_1
2+
// RUN: %sourcekitd-test -req=track-compiles == -req=sema %s -print-raw-response -- %s -no-such-arg | %FileCheck %s -check-prefix=ARG_PARSE_1
3+
// RUN: %sourcekitd-test -req=track-compiles == -req=cursor -offset=0 %s -- %s -no-such-arg | %FileCheck %s -check-prefix=ARG_PARSE_1
24
// ARG_PARSE_1: {
35
// ARG_PARSE_1: key.notification: source.notification.compile-will-start
46
// ARG_PARSE_1: key.compileid: [[CID1:".*"]]
@@ -17,3 +19,23 @@
1719
// ARG_PARSE_1: }
1820
// ARG_PARSE_1-NOT: compile-will-start
1921
// ARG_PARSE_1-NOT: compile-did-finish
22+
23+
// RUN: not %sourcekitd-test -req=track-compiles == -req=complete %s -offset=0 | %FileCheck %s -check-prefix=ARG_PARSE_2
24+
// RUN: %sourcekitd-test -req=track-compiles == -req=sema %s -print-raw-response | %FileCheck %s -check-prefix=ARG_PARSE_2
25+
// ARG_PARSE_2: {
26+
// ARG_PARSE_2: key.notification: source.notification.compile-will-start
27+
// ARG_PARSE_2: key.compileid: [[CID1:".*"]]
28+
// ARG_PARSE_2: }
29+
// ARG_PARSE_2: {
30+
// ARG_PARSE_2: key.notification: source.notification.compile-did-finish
31+
// ARG_PARSE_2: key.diagnostics: [
32+
// ARG_PARSE_2: {
33+
// ARG_PARSE_2: key.filepath: "<unknown>",
34+
// ARG_PARSE_2: key.severity: source.diagnostic.severity.error,
35+
// ARG_PARSE_2: key.description: "no input files"
36+
// ARG_PARSE_2: }
37+
// ARG_PARSE_2: ]
38+
// ARG_PARSE_2: key.compileid: [[CID1]]
39+
// ARG_PARSE_2: }
40+
// ARG_PARSE_2-NOT: compile-will-start
41+
// ARG_PARSE_2-NOT: compile-did-finish

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,26 @@ SwiftInvocationRef
512512
SwiftASTManager::getInvocation(ArrayRef<const char *> OrigArgs,
513513
StringRef PrimaryFile,
514514
std::string &Error) {
515+
516+
DiagnosticEngine Diags(Impl.SourceMgr);
517+
EditorDiagConsumer CollectDiagConsumer;
518+
Diags.addConsumer(CollectDiagConsumer);
519+
515520
CompilerInvocation CompInvok;
516-
if (initCompilerInvocation(CompInvok, OrigArgs, PrimaryFile, Error)) {
521+
if (initCompilerInvocation(CompInvok, OrigArgs, Diags, PrimaryFile, Error)) {
522+
// We create a traced operation here to represent the failure to parse
523+
// arguments since we cannot reach `createAST` where that would normally
524+
// happen.
525+
trace::TracedOperation TracedOp(trace::OperationKind::PerformSema);
526+
if (TracedOp.enabled()) {
527+
trace::SwiftInvocation TraceInfo;
528+
trace::initTraceInfo(TraceInfo, PrimaryFile, OrigArgs);
529+
TracedOp.setDiagnosticProvider(
530+
[&CollectDiagConsumer](SmallVectorImpl<DiagnosticEntryInfo> &diags) {
531+
CollectDiagConsumer.getAllDiagnostics(diags);
532+
});
533+
TracedOp.start(TraceInfo);
534+
}
517535
return nullptr;
518536
}
519537

0 commit comments

Comments
 (0)