(context: vs.ExtensionContext, private readonly logger: Logger, analyzer: Analyzer, analytics: Analytics)
| 16 | |
| 17 | export 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); |
nothing calls this directly
no test coverage detected