Skip to content

Commit

Permalink
Ensure initial parameters loaded on startup (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work authored Jan 8, 2025
1 parent 3beb8c8 commit 915701a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/plugin/memory-webview-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
}

// Set HTML content
await this.getWebviewContent(panel);
await this.getWebviewContent(panel, initialMemory);

// Sets up an event listener to listen for messages passed from the webview view context
// and executes code based on the message that is received
this.setWebviewMessageListener(panel, initialMemory);
}

protected async getWebviewContent(panel: vscode.WebviewPanel): Promise<void> {
protected async getWebviewContent(panel: vscode.WebviewPanel, initialMemory?: MemoryOptions): Promise<void> {
const mainUri = panel.webview.asWebviewUri(vscode.Uri.joinPath(
this.extensionUri,
'dist',
Expand All @@ -194,7 +194,7 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
<link href="${memoryInspectorCSS}" rel="stylesheet" />
</head>
<body>
<div id='root'></div>
<div id='root'></div>${initialMemory ? `<div id='initial-data' data-options='${JSON.stringify(initialMemory)}'></div>` : ''}
</body>
</html>
`;
Expand All @@ -206,7 +206,6 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
this.messenger.onNotification(readyType, async () => {
this.setSessionContext(participant, this.createContext());
await this.setMemoryDisplaySettings(participant, panel.title);
this.refresh(participant, options);
}, { sender: participant }),
this.messenger.onRequest(setOptionsType, newOptions => { options = { ...options, ...newOptions }; }, { sender: participant }),
this.messenger.onRequest(logMessageType, message => outputChannelLogger.info('[webview]:', message), { sender: participant }),
Expand Down
13 changes: 11 additions & 2 deletions src/webview/memory-webview-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ export const DEFAULT_MEMORY_DISPLAY_CONFIGURATION: MemoryDisplaySettings = {
visibleColumns: manifest.DEFAULT_VISIBLE_COLUMNS
};

function getInitialValuesHolder(): HTMLElement | null {
return document.getElementById('initial-data');
}

class App extends React.Component<{}, MemoryAppState> {
protected memoryWidget = React.createRef<MemoryWidget>();
protected refreshTimer?: NodeJS.Timeout | number;

public constructor(props: {}) {
super(props);
const initialValuesHolder = getInitialValuesHolder();
const initialReadArguments = initialValuesHolder ? { ...DEFAULT_READ_ARGUMENTS, ...JSON.parse(initialValuesHolder.dataset['options']!) } : DEFAULT_READ_ARGUMENTS;
columnContributionService.register(new AddressColumn(), false);
columnContributionService.register(new DataColumn(), false);
columnContributionService.register(variableDecorator);
Expand All @@ -106,8 +112,8 @@ class App extends React.Component<{}, MemoryAppState> {
sessionContext: DEFAULT_SESSION_CONTEXT,
memory: undefined,
effectiveAddressLength: 0,
configuredReadArguments: DEFAULT_READ_ARGUMENTS,
activeReadArguments: DEFAULT_READ_ARGUMENTS,
configuredReadArguments: initialReadArguments,
activeReadArguments: initialReadArguments,
decorations: [],
hoverService: hoverService,
columns: columnContributionService.getColumns(),
Expand All @@ -118,6 +124,9 @@ class App extends React.Component<{}, MemoryAppState> {
}

public componentDidMount(): void {
if (getInitialValuesHolder()) {
this.fetchMemory(this.state.activeReadArguments);
}
messenger.onRequest(setOptionsType, options => this.setOptions(options));
messenger.onNotification(memoryWrittenType, writtenMemory => this.memoryWritten(writtenMemory));
messenger.onNotification(sessionContextChangedType, sessionContext => this.sessionContextChanged(sessionContext));
Expand Down

0 comments on commit 915701a

Please sign in to comment.