|
1 | 1 | import * as fs from "fs"; |
2 | 2 | import * as path from "path"; |
3 | 3 | import * as vs from "vscode"; |
4 | | -import { devToolsPages, doNotAskAgainAction, isInFlutterDebugModeDebugSessionContext, isInFlutterProfileModeDebugSessionContext } from "../../shared/constants"; |
| 4 | +import { devToolsPages, doNotAskAgainAction, isInFlutterDebugModeDebugSessionContext, isInFlutterProfileModeDebugSessionContext, widgetInspectorPage } from "../../shared/constants"; |
5 | 5 | import { DebuggerType, DebugOption, debugOptionNames, LogSeverity, VmServiceExtension } from "../../shared/enums"; |
6 | | -import { DartWorkspaceContext, DevToolsPage, Logger, LogMessage } from "../../shared/interfaces"; |
| 6 | +import { DartWorkspaceContext, DevToolsPage, Logger, LogMessage, WidgetErrorInspectData } from "../../shared/interfaces"; |
7 | 7 | import { flatMap, PromiseCompleter } from "../../shared/utils"; |
8 | 8 | import { findProjectFolders, fsPath } from "../../shared/utils/fs"; |
9 | 9 | import { showDevToolsNotificationIfAppropriate } from "../../shared/vscode/user_prompts"; |
@@ -54,6 +54,7 @@ export class DebugCommands { |
54 | 54 | public readonly onDebugSessionVmServiceAvailable = this.onDebugSessionVmServiceAvailableEmitter.event; |
55 | 55 | public readonly vmServices: VmServiceExtensions; |
56 | 56 | public readonly devTools: DevToolsManager; |
| 57 | + private suppressFlutterWidgetErrors = false; |
57 | 58 |
|
58 | 59 | constructor(private readonly logger: Logger, private context: Context, workspaceContext: DartWorkspaceContext, private readonly analytics: Analytics, pubGlobal: PubGlobal) { |
59 | 60 | this.vmServices = new VmServiceExtensions(logger, this.sendServiceSetting); |
@@ -121,11 +122,10 @@ export class DebugCommands { |
121 | 122 |
|
122 | 123 | // Only show a notification if we were not triggered automatically. |
123 | 124 | const notify = !options || options.triggeredAutomatically !== true; |
124 | | - const reuseWindows = config.devToolsReuseWindows; |
125 | 125 | const page = options?.page; |
126 | 126 |
|
127 | 127 | if (session.vmServiceUri) { |
128 | | - return this.devTools.spawnForSession(session as DartDebugSessionInformation & { vmServiceUri: string }, { embed: config.embedDevTools, reuseWindows, notify, page }); |
| 128 | + return this.devTools.spawnForSession(session as DartDebugSessionInformation & { vmServiceUri: string }, { notify, page }); |
129 | 129 | } else if (session.session.configuration.noDebug) { |
130 | 130 | vs.window.showInformationMessage("You must start your app with debugging in order to use DevTools."); |
131 | 131 | } else { |
@@ -549,6 +549,34 @@ export class DebugCommands { |
549 | 549 | await new Promise((resolve) => setTimeout(resolve, 400)); |
550 | 550 | } |
551 | 551 | session.progress[e.body.progressID]?.complete(); |
| 552 | + } else if (e.event === "dart.flutter.widgetErrorInspectData") { |
| 553 | + if (this.suppressFlutterWidgetErrors || !config.showInspectorNotificationsForWidgetErrors) |
| 554 | + return; |
| 555 | + |
| 556 | + const data = e.body as WidgetErrorInspectData; |
| 557 | + if (data.devToolsUrl !== (await this.devTools.devtoolsUrl)) |
| 558 | + return; |
| 559 | + |
| 560 | + // To avoid spam, when we show this dialog we will set a flag that prevents any more |
| 561 | + // of these types of dialogs until it is dismissed or 5 seconds have passed. |
| 562 | + this.suppressFlutterWidgetErrors = true; |
| 563 | + const timer = setTimeout(() => this.suppressFlutterWidgetErrors = false, 5000); |
| 564 | + |
| 565 | + const inspectAction = `Inspect Widget`; |
| 566 | + const choice = await vs.window.showWarningMessage(data.errorDescription, inspectAction, doNotAskAgainAction); |
| 567 | + if (choice === inspectAction && session.vmServiceUri) { |
| 568 | + this.devTools.spawnForSession( |
| 569 | + session as DartDebugSessionInformation & { vmServiceUri: string }, |
| 570 | + { |
| 571 | + inspectorRef: data.inspectorReference, |
| 572 | + page: widgetInspectorPage, |
| 573 | + }, |
| 574 | + ); |
| 575 | + } else if (choice === doNotAskAgainAction) { |
| 576 | + config.setShowInspectorNotificationsForWidgetErrors(false); |
| 577 | + } |
| 578 | + clearTimeout(timer); |
| 579 | + this.suppressFlutterWidgetErrors = false; |
552 | 580 | } |
553 | 581 | } |
554 | 582 |
|
|
0 commit comments