(
logger: Logger,
{ prompt, buttonText, offerLog, specificLog, severity, restartReason, restartData }:
{ prompt?: string; buttonText?: string; offerLog?: boolean; specificLog?: string; severity?: "ERROR" | "WARNING"; restartReason: ExtensionRestartReason, restartData?: string, },
)
| 210 | } |
| 211 | |
| 212 | export async function promptToReloadExtension( |
| 213 | logger: Logger, |
| 214 | { prompt, buttonText, offerLog, specificLog, severity, restartReason, restartData }: |
| 215 | { prompt?: string; buttonText?: string; offerLog?: boolean; specificLog?: string; severity?: "ERROR" | "WARNING"; restartReason: ExtensionRestartReason, restartData?: string, }, |
| 216 | ): Promise<void> { |
| 217 | const restartAction = buttonText || "Restart Extension"; |
| 218 | const actions = offerLog ? [restartAction, showLogAction] : [restartAction]; |
| 219 | |
| 220 | logger.warn(`Prompting to reload: (${prompt}) (actions: ${actions.join(", ")})`); |
| 221 | |
| 222 | const ringLogContents = ringLog.toString(); |
| 223 | let showPromptAgain = true; |
| 224 | const tempLogPath = path.join(os.tmpdir(), `log-${getRandomInt(0x1000, 0x10000).toString(16)}.txt`); |
| 225 | while (showPromptAgain) { |
| 226 | showPromptAgain = false; |
| 227 | const show = severity === "ERROR" |
| 228 | ? window.showErrorMessage |
| 229 | : severity === "WARNING" |
| 230 | ? window.showWarningMessage |
| 231 | : window.showInformationMessage; |
| 232 | const chosenAction = prompt && await show(prompt, ...actions); |
| 233 | if (chosenAction === showLogAction) { |
| 234 | showPromptAgain = true; |
| 235 | if (specificLog && fs.existsSync(specificLog)) |
| 236 | void workspace.openTextDocument(specificLog).then(window.showTextDocument); |
| 237 | else |
| 238 | void openLogContents(undefined, ringLogContents, tempLogPath); |
| 239 | } else if (!prompt || chosenAction === restartAction) { |
| 240 | void commands.executeCommand("_dart.reloadExtension", restartReason, restartData); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | const shouldLogTimings = false; |
| 246 | const start = process.hrtime.bigint(); |
no test coverage detected