MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / promptToReloadExtension

Function promptToReloadExtension

src/extension/utils.ts:212–243  ·  view source on GitHub ↗
(
	logger: Logger,
	{ prompt, buttonText, offerLog, specificLog, severity, restartReason, restartData }:
		{ prompt?: string; buttonText?: string; offerLog?: boolean; specificLog?: string; severity?: "ERROR" | "WARNING"; restartReason: ExtensionRestartReason, restartData?: string, },
)

Source from the content-addressed store, hash-verified

210}
211
212export 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
245const shouldLogTimings = false;
246const start = process.hrtime.bigint();

Callers 12

activateFunction · 0.90
handlePubspecChangeMethod · 0.90
startPingMethod · 0.90
showTerminatedErrorMethod · 0.90
sendMessageMethod · 0.90
withRecordedTimeoutMethod · 0.90
spawnServerMethod · 0.90
closedMethod · 0.90

Calls 5

getRandomIntFunction · 0.90
openLogContentsFunction · 0.85
warnMethod · 0.65
executeCommandMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected