diff --git a/src/common/messaging.ts b/src/common/messaging.ts index 0abadd4..ab03792 100644 --- a/src/common/messaging.ts +++ b/src/common/messaging.ts @@ -24,10 +24,8 @@ export type MemoryWriteResult = DebugProtocol.WriteMemoryResponse['body']; export const readyType: NotificationType = { method: 'ready' }; export const logMessageType: RequestType = { method: 'logMessage' }; -export const getMemoryDisplayConfigurationType: RequestType = { method: 'getMemoryDisplayConfiguration' }; export const setMemoryDisplayConfigurationType: NotificationType = { method: 'setMemoryDisplayConfiguration' }; export const memoryDisplayConfigurationChangedType: NotificationType = { method: 'memoryDisplayConfigurationChanged' }; -export const getColumnsVisibility: RequestType = { method: 'getColumnsVisibility' }; export const columnVisibilityType: NotificationType = { method: 'columnVisibility' }; export const setOptionsType: RequestType, void> = { method: 'setOptions' }; export const readMemoryType: RequestType = { method: 'readMemory' }; diff --git a/src/plugin/memory-webview-main.ts b/src/plugin/memory-webview-main.ts index 9805836..509c717 100644 --- a/src/plugin/memory-webview-main.ts +++ b/src/plugin/memory-webview-main.ts @@ -31,8 +31,6 @@ import { memoryDisplayConfigurationChangedType, columnVisibilityType, setMemoryDisplayConfigurationType, - getColumnsVisibility, - getMemoryDisplayConfigurationType, } from '../common/messaging'; import { MemoryProvider } from './memory-provider'; import { outputChannelLogger } from './logger'; @@ -52,6 +50,10 @@ enum RefreshEnum { } const isMemoryVariable = (variable: Variable): variable is Variable => variable && !!(variable as Variable).memoryReference; +const columnConfigurations = [ + manifest.CONFIG_SHOW_ASCII_COLUMN, + manifest.CONFIG_SHOW_VARIABLES_COLUMN, +]; export class MemoryWebview { public static ViewType = `${manifest.PACKAGE_NAME}.memory`; @@ -142,13 +144,13 @@ export class MemoryWebview { const participant = this.messenger.registerWebviewPanel(panel); const disposables = [ - this.messenger.onNotification(readyType, () => this.refresh(participant, options), { sender: participant }), + this.messenger.onNotification(readyType, () => { + this.refresh(participant, options); + }, { sender: participant }), this.messenger.onRequest(logMessageType, message => outputChannelLogger.info('[webview]:', message), { sender: participant }), this.messenger.onRequest(readMemoryType, request => this.readMemory(request), { sender: participant }), this.messenger.onRequest(writeMemoryType, request => this.writeMemory(request), { sender: participant }), this.messenger.onRequest(getVariables, request => this.getVariables(request), { sender: participant }), - this.messenger.onRequest(getMemoryDisplayConfigurationType, () => this.getMemoryDisplayConfiguration(), { sender: participant }), - this.messenger.onRequest(getColumnsVisibility, () => this.getColumnConfigurations(), { sender: participant }), this.messenger.onNotification(setMemoryDisplayConfigurationType, request => this.setConfiguration(request), { sender: participant }), this.messenger.onNotification(columnVisibilityType, request => this.handleColumnToggled(request), { sender: participant }), @@ -160,7 +162,11 @@ export class MemoryWebview { this.onMemoryDisplayConfigurationChanged(participant), this.onColumnVisibilityConfigurationChanged(participant), ]; - + panel.onDidChangeViewState(newState => { + if (newState.webviewPanel.visible) { + this.refresh(participant, options); + } + }); panel.onDidDispose(() => disposables.forEach(disposible => disposible.dispose())); } @@ -176,6 +182,13 @@ export class MemoryWebview { protected async refresh(participant: WebviewIdMessageParticipant, options?: Partial): Promise { this.messenger.sendRequest(setOptionsType, participant, options); + const memoryDisplayConfiguration = this.getMemoryDisplayConfiguration(); + this.messenger.sendNotification(memoryDisplayConfigurationChangedType, participant, memoryDisplayConfiguration); + columnConfigurations.forEach(columnConfiguration => { + const [id] = columnConfiguration.split('Visible'); + const active = vscode.workspace.getConfiguration(manifest.PACKAGE_NAME).get(columnConfiguration) ?? true; + this.messenger.sendNotification(columnVisibilityType, participant, { id, active }); + }); } protected getMemoryDisplayConfiguration(): MemoryDisplayConfiguration { @@ -199,10 +212,6 @@ export class MemoryWebview { } protected onColumnVisibilityConfigurationChanged(participant: MessageParticipant): vscode.Disposable { - const columnConfigurations = [ - manifest.CONFIG_SHOW_ASCII_COLUMN, - manifest.CONFIG_SHOW_VARIABLES_COLUMN, - ]; return vscode.workspace.onDidChangeConfiguration(e => { columnConfigurations.forEach(configuration => { if (e.affectsConfiguration(`${manifest.PACKAGE_NAME}.${configuration}`)) { @@ -214,15 +223,6 @@ export class MemoryWebview { }); } - protected getColumnConfigurations(): ColumnVisibilityStatus[] { - const COLUMN_CONFIGURATIONS = [manifest.CONFIG_SHOW_VARIABLES_COLUMN, manifest.CONFIG_SHOW_ASCII_COLUMN]; - return COLUMN_CONFIGURATIONS.map(configuration => { - const [id] = configuration.split('Visible'); - const active = vscode.workspace.getConfiguration(manifest.PACKAGE_NAME).get(configuration) ?? false; - return { id, active }; - }); - } - protected async readMemory(request: DebugProtocol.ReadMemoryArguments): Promise { try { return await this.memoryProvider.readMemory(request); diff --git a/src/webview/components/memory-widget.tsx b/src/webview/components/memory-widget.tsx index fee257e..3dd7089 100644 --- a/src/webview/components/memory-widget.tsx +++ b/src/webview/components/memory-widget.tsx @@ -20,8 +20,7 @@ import { MemoryTable } from './memory-table'; import { OptionsWidget } from './options-widget'; import { Decoration, Endianness, Memory, MemoryDisplayConfiguration } from '../utils/view-types'; import { messenger } from '../view-messenger'; -import { getMemoryDisplayConfigurationType, memoryDisplayConfigurationChangedType } from '../../common/messaging'; -import { HOST_EXTENSION } from 'vscode-messenger-common'; +import { memoryDisplayConfigurationChangedType } from '../../common/messaging'; import { ColumnStatus } from '../columns/column-contribution-service'; interface MemoryWidgetProps { @@ -56,9 +55,6 @@ export class MemoryWidget extends React.Component this.setState(configuration)); - messenger.sendRequest(getMemoryDisplayConfigurationType, HOST_EXTENSION, undefined).then(configuration => { - this.setState(configuration); - }); } override render(): React.ReactNode { diff --git a/src/webview/memory-webview-view.tsx b/src/webview/memory-webview-view.tsx index af5aa51..c627f29 100644 --- a/src/webview/memory-webview-view.tsx +++ b/src/webview/memory-webview-view.tsx @@ -23,7 +23,6 @@ import { setOptionsType, readMemoryType, columnVisibilityType, - getColumnsVisibility } from '../common/messaging'; import type { DebugProtocol } from '@vscode/debugprotocol'; import { ColumnVisibilityStatus, Decoration, Memory, MemoryState } from './utils/view-types'; @@ -67,10 +66,6 @@ class App extends React.Component<{}, MemoryAppState> { messenger.onRequest(setOptionsType, options => this.setOptions(options)); messenger.sendNotification(readyType, HOST_EXTENSION, undefined); messenger.onNotification(columnVisibilityType, request => this.handleColumnVisibilityChanged(request)); - messenger.sendRequest(getColumnsVisibility, HOST_EXTENSION, undefined).then(columnsVisibility => { - columnsVisibility.forEach(columnVisibility => this.handleColumnVisibilityChanged(columnVisibility)); - }); - } public render(): React.ReactNode {