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

Method constructor

src/extension/commands/analyzer.ts:18–54  ·  view source on GitHub ↗
(context: vs.ExtensionContext, private readonly logger: Logger, analyzer: Analyzer, analytics: Analytics)

Source from the content-addressed store, hash-verified

16
17export class AnalyzerCommands {
18 constructor(context: vs.ExtensionContext, private readonly logger: Logger, analyzer: Analyzer, analytics: Analytics) {
19 context.subscriptions.push(vs.commands.registerCommand("dart.openAnalyzerDiagnostics", async () => {
20 const res = await analyzer.getDiagnosticServerPort();
21 if (res)
22 await envUtils.openInBrowser(`http://127.0.0.1:${res.port}/`);
23 }));
24 context.subscriptions.push(vs.commands.registerCommand("dart.restartAnalysisServer", async () => {
25 logger.warn(`dart.restartAnalysisServer was invoked, restarting analysis server...`);
26 forcedReanalyzeCount++;
27 if (forcedReanalyzeCount === 10)
28 this.showServerRestartPrompt().catch((e) => logger.error(e));
29 analytics.log(AnalyticsEvent.Command_RestartAnalyzer);
30
31 // Capture log before starting the restart.
32 const logPrefix = `The Dart Analysis Server was restarted. Below is a log of the most recent ${ringLog.size} events captured before the restart.`;
33 const logHeader = getLogHeader();
34 const ringLogContents = ringLog.toString();
35 const completeLog = `${logPrefix}${logHeader}${ringLogContents}`;
36
37 // Restart.
38 void vs.commands.executeCommand("_dart.reloadExtension", ExtensionRestartReason.AnalysisServerRestartCommand);
39
40 // Show a notification and offer the log file.
41 const tempLogPath = path.join(os.tmpdir(), `log-${getRandomInt(0x1000, 0x10000).toString(16)}.txt`);
42 const chosenAction = await vs.window.showInformationMessage("The Dart Analysis Server has been restarted", showLogAction);
43 if (chosenAction === showLogAction)
44 void openLogContents(undefined, completeLog, tempLogPath);
45
46 }));
47 context.subscriptions.push(vs.commands.registerCommand("dart.forceReanalyze", async () => {
48 forcedReanalyzeCount++;
49 if (forcedReanalyzeCount === 10)
50 this.showServerRestartPrompt().catch((e) => logger.error(e));
51 analytics.log(AnalyticsEvent.Command_ForceReanalyze);
52 await analyzer.forceReanalyze();
53 }));
54 }
55
56 private async showServerRestartPrompt(): Promise<void> {
57 const choice = await vs.window.showInformationMessage("Needing to reanalyze a lot? Please consider filing a bug with a server instrumentation log", issueTrackerAction);

Callers

nothing calls this directly

Calls 12

getLogHeaderFunction · 0.90
getRandomIntFunction · 0.90
openLogContentsFunction · 0.90
openInBrowserMethod · 0.80
forceReanalyzeMethod · 0.80
warnMethod · 0.65
errorMethod · 0.65
executeCommandMethod · 0.65
logMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected