(crashDirectory: string)
| 1120 | } |
| 1121 | |
| 1122 | export function watchForCrashes(crashDirectory: string): void { |
| 1123 | if (crashDirectory !== "") { |
| 1124 | prevCppCrashFile = ""; |
| 1125 | fs.stat(crashDirectory, (err) => { |
| 1126 | const crashObject: Record<string, string> = {}; |
| 1127 | if (err?.code) { |
| 1128 | // If the directory isn't there, we have a problem... |
| 1129 | crashObject["errCode"] = err.code; |
| 1130 | telemetry.logLanguageServerEvent("CppCrash", crashObject); |
| 1131 | return; |
| 1132 | } |
| 1133 | |
| 1134 | // vscode.workspace.createFileSystemWatcher only works in workspace folders. |
| 1135 | try { |
| 1136 | fs.watch(crashDirectory, (event, filename) => { |
| 1137 | if (event !== "change") { |
| 1138 | return; |
| 1139 | } |
| 1140 | if (!filename || filename === prevCppCrashFile) { |
| 1141 | return; |
| 1142 | } |
| 1143 | prevCppCrashFile = filename; |
| 1144 | if (!filename.startsWith("cpptools")) { |
| 1145 | return; |
| 1146 | } |
| 1147 | const crashDate: Date = new Date(); |
| 1148 | isWritingCrashCallStack = true; |
| 1149 | |
| 1150 | // Wait 5 seconds to allow time for the crash log to finish being written. |
| 1151 | setTimeout(() => { |
| 1152 | isWritingCrashCallStack = false; |
| 1153 | fs.readFile(path.resolve(crashDirectory, filename), 'utf8', (err, data) => { |
| 1154 | void handleCrashFileRead(crashDirectory, filename, crashDate, err, data); |
| 1155 | }); |
| 1156 | }, 5000); |
| 1157 | }); |
| 1158 | } catch { |
| 1159 | // The file watcher limit is hit (may not be possible on Mac, but just in case). |
| 1160 | } |
| 1161 | }); |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | let previousCrashData: string; |
| 1166 | let previousCrashCount: number = 0; |
no test coverage detected