Skip to content

Commit 7af5c40

Browse files
committed
Handle multiple cpptools-srv crashes. (#12225)
1 parent 1d2bd10 commit 7af5c40

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Extension/src/LanguageServer/extension.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle();
3636
export const CppSourceStr: string = "C/C++";
3737
export const configPrefix: string = "C/C++: ";
3838

39-
let prevCrashFile: string;
39+
let prevMacCrashFile: string;
40+
let prevCppCrashFile: string;
4041
export let clients: ClientCollection;
4142
let activeDocument: vscode.TextDocument | undefined;
4243
let ui: LanguageStatusUI;
@@ -914,7 +915,7 @@ function onShowRefCommand(arg?: TreeNode): void {
914915

915916
function reportMacCrashes(): void {
916917
if (process.platform === "darwin") {
917-
prevCrashFile = "";
918+
prevMacCrashFile = "";
918919
const home: string = os.homedir();
919920
const crashFolder: string = path.resolve(home, "Library/Logs/DiagnosticReports");
920921
fs.stat(crashFolder, (err) => {
@@ -932,10 +933,10 @@ function reportMacCrashes(): void {
932933
if (event !== "rename") {
933934
return;
934935
}
935-
if (!filename || filename === prevCrashFile) {
936+
if (!filename || filename === prevMacCrashFile) {
936937
return;
937938
}
938-
prevCrashFile = filename;
939+
prevMacCrashFile = filename;
939940
if (!filename.startsWith("cpptools")) {
940941
return;
941942
}
@@ -964,7 +965,7 @@ export function usesCrashHandler(): boolean {
964965

965966
export function watchForCrashes(crashDirectory: string): void {
966967
if (crashDirectory !== "") {
967-
prevCrashFile = "";
968+
prevCppCrashFile = "";
968969
fs.stat(crashDirectory, (err) => {
969970
const crashObject: Record<string, string> = {};
970971
if (err?.code) {
@@ -980,10 +981,10 @@ export function watchForCrashes(crashDirectory: string): void {
980981
if (event !== "rename") {
981982
return;
982983
}
983-
if (!filename || filename === prevCrashFile) {
984+
if (!filename || filename === prevCppCrashFile) {
984985
return;
985986
}
986-
prevCrashFile = filename;
987+
prevCppCrashFile = filename;
987988
if (!filename.startsWith("cpptools")) {
988989
return;
989990
}
@@ -1125,7 +1126,7 @@ async function handleCrashFileRead(crashDirectory: string, crashFile: string, er
11251126

11261127
const lines: string[] = data.split("\n");
11271128
let addressData: string = ".\n.";
1128-
data = crashFile + "\n";
1129+
data = (crashFile.startsWith("cpptools-srv") ? "cpptools-srv.txt" : crashFile) + "\n";
11291130
const filtPath: string | null = which.sync("c++filt", { nothrow: true });
11301131
const isMac: boolean = process.platform === "darwin";
11311132
const startStr: string = isMac ? " _" : "<";
@@ -1202,7 +1203,9 @@ async function handleCrashFileRead(crashDirectory: string, crashFile: string, er
12021203
logCppCrashTelemetry(data, addressData);
12031204

12041205
await util.deleteFile(path.resolve(crashDirectory, crashFile)).catch(logAndReturn.undefined);
1205-
void util.deleteDirectory(crashDirectory).catch(logAndReturn.undefined);
1206+
if (crashFile === "cpptools.txt") {
1207+
void util.deleteDirectory(crashDirectory).catch(logAndReturn.undefined);
1208+
}
12061209
}
12071210

12081211
export function deactivate(): Thenable<void> {

0 commit comments

Comments
 (0)