Skip to content

Commit 92d5db1

Browse files
committed
vscode: fix the crash reporter
The rust process will use several `writeln!` on the file to write out the panic information. This may take some time and vscode could be reading these files before. So add a small timer in vscode to make sure we do not try to send the telemetry before we have all the info
1 parent 292035e commit 92d5db1

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

editors/vscode/src/extension.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,24 +325,24 @@ export function activate(context: vscode.ExtensionContext) {
325325

326326
const version_extension = custom_lsp ? " [CUSTOM BINARY]" : "";
327327

328-
watcher.onDidCreate((uri) => {
329-
vscode.workspace.fs.readFile(uri).then((data) => {
330-
const contents = Buffer.from(data).toString("utf-8");
331-
const lines = contents.split("\n");
332-
const version = lines[0] + version_extension;
333-
// Location is trusted because it is a path within the LSP (as build on our CI)
334-
const location = new vscode.TelemetryTrustedValue(lines[1]);
335-
const backtrace = lines[2];
336-
const message = lines.slice(3).join("\n");
337-
telemetryLogger.logError("lsp-panic", {
338-
version: version,
339-
location: location,
340-
message: message,
341-
backtrace: backtrace,
342-
});
343-
console.log("Removing file");
344-
vscode.workspace.fs.delete(uri);
328+
watcher.onDidCreate(async (uri) => {
329+
// wait a bit to make sure the file is fully written
330+
await new Promise((resolve) => setTimeout(resolve, 300));
331+
332+
const contents = await vscode.workspace.fs.readFile(uri);
333+
const lines = contents.toString().split("\n");
334+
const version = lines[0] + version_extension;
335+
// Location is trusted because it is a path within the LSP (as build on our CI)
336+
const location = new vscode.TelemetryTrustedValue(lines[1]);
337+
const backtrace = lines[2];
338+
const message = lines.slice(3).join("\n");
339+
telemetryLogger.logError("lsp-panic", {
340+
version: version,
341+
location: location,
342+
message: message,
343+
backtrace: backtrace,
345344
});
345+
vscode.workspace.fs.delete(uri);
346346
});
347347

348348
// Ensure the watcher is disposed of when the extension is deactivated

0 commit comments

Comments
 (0)