Skip to content

Commit 41c7666

Browse files
committed
Prompt to capture diagnostics if sourcekit-lsp crashes
1 parent aaeafe0 commit 41c7666

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

src/commands/captureDiagnostics.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ import { Version } from "../utilities/version";
2323
import { execFileStreamOutput } from "../utilities/utilities";
2424
import configuration from "../configuration";
2525

26-
export async function captureDiagnostics(ctx: WorkspaceContext) {
26+
export async function captureDiagnostics(
27+
ctx: WorkspaceContext,
28+
allowMinimalCapture: boolean = true
29+
) {
2730
try {
28-
const captureMode = await captureDiagnosticsMode(ctx);
31+
const captureMode = await captureDiagnosticsMode(ctx, allowMinimalCapture);
2932

3033
// dialog was cancelled
3134
if (!captureMode) {
@@ -58,16 +61,34 @@ export async function captureDiagnostics(ctx: WorkspaceContext) {
5861
}
5962
}
6063

64+
export async function promptForDiagnostics(ctx: WorkspaceContext) {
65+
const ok = "OK";
66+
const cancel = "Cancel";
67+
const result = await vscode.window.showInformationMessage(
68+
"SourceKit-LSP has been restored. Would you like to capture a diagnostic bundle to file an issue?",
69+
ok,
70+
cancel
71+
);
72+
73+
if (!result || result === cancel) {
74+
return;
75+
}
76+
77+
return await captureDiagnostics(ctx, false);
78+
}
79+
6180
async function captureDiagnosticsMode(
62-
ctx: WorkspaceContext
81+
ctx: WorkspaceContext,
82+
allowMinimalCapture: boolean
6383
): Promise<"Minimal" | "Full" | undefined> {
6484
if (
6585
ctx.swiftVersion.isGreaterThanOrEqual(new Version(6, 0, 0)) ||
6686
vscode.workspace.getConfiguration("sourcekit-lsp").get<string>("trace.server", "off") !==
6787
"off"
6888
) {
69-
const fullButton = "Capture Full Diagnostics";
89+
const fullButton = allowMinimalCapture ? "Capture Full Diagnostics" : "Capture Diagnostics";
7090
const minimalButton = "Capture Minimal Diagnostics";
91+
const buttons = allowMinimalCapture ? [fullButton, minimalButton] : [fullButton];
7192
const fullCaptureResult = await vscode.window.showInformationMessage(
7293
`A Diagnostic Bundle collects information that helps the developers of the VS Code Swift extension diagnose and fix issues.
7394
@@ -82,10 +103,11 @@ This information contains:
82103
Please attach this bundle to GitHub issues.`,
83104
{
84105
modal: true,
85-
detail: `If you wish to omit potentially sensitive information choose "${minimalButton}"`,
106+
detail: allowMinimalCapture
107+
? `If you wish to omit potentially sensitive information choose "${minimalButton}"`
108+
: undefined,
86109
},
87-
fullButton,
88-
minimalButton
110+
...buttons
89111
);
90112
if (!fullCaptureResult) {
91113
return undefined;

src/sourcekit-lsp/LanguageClientManager.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { LanguageClient } from "vscode-languageclient/node";
2525
import { ArgumentFilter, BuildFlags } from "../toolchain/BuildFlags";
2626
import { DiagnosticsManager } from "../DiagnosticsManager";
2727
import { SwiftOutputChannel } from "../ui/SwiftOutputChannel";
28+
import { promptForDiagnostics } from "../commands/captureDiagnostics";
2829

2930
/** Manages the creation and destruction of Language clients as we move between
3031
* workspace folders
@@ -525,6 +526,20 @@ export class LanguageClientManager {
525526
diagnostics
526527
);
527528
},
529+
handleWorkDoneProgress: (() => {
530+
let restoringLSPStarted = false;
531+
return async (token, params, next) => {
532+
const result = await next(token, params);
533+
const title = (params as langclient.WorkDoneProgressBegin).title;
534+
if (title === "SourceKit-LSP: Restoring functionality") {
535+
restoringLSPStarted = true;
536+
} else if (params.kind === "end" && restoringLSPStarted) {
537+
restoringLSPStarted = false;
538+
await promptForDiagnostics(this.workspaceContext);
539+
}
540+
return result;
541+
};
542+
})(),
528543
},
529544
errorHandler: new SourceKitLSPErrorHandler(5),
530545
};

0 commit comments

Comments
 (0)