From c4721737ce5e26c272d48b2128ee36df57ca51d8 Mon Sep 17 00:00:00 2001 From: eahotht Date: Wed, 10 Apr 2024 22:16:55 +0200 Subject: [PATCH] Add Context for getVariables, StoreMemory, and ApplyMemory --- src/common/messaging.ts | 6 +++--- src/plugin/adapter-registry/adapter-capabilities.ts | 8 ++++---- src/plugin/memory-provider.ts | 6 +++--- src/plugin/memory-webview-main.ts | 4 ++-- src/webview/memory-webview-view.tsx | 2 +- src/webview/variables/variable-decorations.ts | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/common/messaging.ts b/src/common/messaging.ts index dde280b..50881cc 100644 --- a/src/common/messaging.ts +++ b/src/common/messaging.ts @@ -62,9 +62,9 @@ export const setOptionsType: RequestType = { method: 'setOp export const logMessageType: RequestType = { method: 'logMessage' }; export const readMemoryType: RequestType<[ReadMemoryArguments, Context?], ReadMemoryResult> = { method: 'readMemory' }; export const writeMemoryType: RequestType<[WriteMemoryArguments, Context?], WriteMemoryResult> = { method: 'writeMemory' }; -export const getVariablesType: RequestType = { method: 'getVariables' }; -export const storeMemoryType: RequestType = { method: 'storeMemory' }; -export const applyMemoryType: RequestType = { method: 'applyMemory' }; +export const getVariablesType: RequestType<[ReadMemoryArguments, Context?], VariableRange[]> = { method: 'getVariables' }; +export const storeMemoryType: RequestType<[StoreMemoryArguments, Context?], void> = { method: 'storeMemory' }; +export const applyMemoryType: RequestType<[ApplyMemoryArguments, Context?], ApplyMemoryResult> = { method: 'applyMemory' }; export const showAdvancedOptionsType: NotificationType = { method: 'showAdvancedOptions' }; export const getWebviewSelectionType: RequestType = { method: 'getWebviewSelection' }; diff --git a/src/plugin/adapter-registry/adapter-capabilities.ts b/src/plugin/adapter-registry/adapter-capabilities.ts index fb4e5ec..778e8ee 100644 --- a/src/plugin/adapter-registry/adapter-capabilities.ts +++ b/src/plugin/adapter-registry/adapter-capabilities.ts @@ -24,13 +24,13 @@ import { Logger } from '../logger'; /** Represents capabilities that may be achieved with particular debug adapters but are not part of the DAP */ export interface AdapterCapabilities { /** Resolve variables known to the adapter to their locations. Fallback if {@link getResidents} is not present */ - getVariables?(session: vscode.DebugSession): Promise; + getVariables?(session: vscode.DebugSession, context?: Context): Promise; /** Resolve symbols resident in the memory at the specified range. Will be preferred to {@link getVariables} if present. */ - getResidents?(session: vscode.DebugSession, params: DebugProtocol.ReadMemoryArguments): Promise; + getResidents?(session: vscode.DebugSession, params: DebugProtocol.ReadMemoryArguments, context?: Context): Promise; /** Resolves the address of a given variable in bytes withthe current context. */ - getAddressOfVariable?(session: vscode.DebugSession, variableName: string): Promise; + getAddressOfVariable?(session: vscode.DebugSession, variableName: string, context?: Context): Promise; /** Resolves the size of a given variable in bytes within the current context. */ - getSizeOfVariable?(session: vscode.DebugSession, variableName: string): Promise; + getSizeOfVariable?(session: vscode.DebugSession, variableName: string, context?: Context): Promise; initializeAdapterTracker?(session: vscode.DebugSession): vscode.DebugAdapterTracker | undefined; getContexts?(session: vscode.DebugSession): Promise; readMemory?(session: vscode.DebugSession, params: ReadMemoryArguments, context?: Context): Promise; diff --git a/src/plugin/memory-provider.ts b/src/plugin/memory-provider.ts index ffd46aa..f92d121 100644 --- a/src/plugin/memory-provider.ts +++ b/src/plugin/memory-provider.ts @@ -179,11 +179,11 @@ export class MemoryProvider { }); } - public async getVariables(variableArguments: DebugProtocol.ReadMemoryArguments): Promise { + public async getVariables([variableArguments, context]: ReadMemoryWithContext): Promise { const session = this.assertActiveSession('get variables'); const handler = this.adapterRegistry?.getHandlerForSession(session.type); - if (handler?.getResidents) { return handler.getResidents(session, variableArguments); } - return handler?.getVariables?.(session) ?? []; + if (handler?.getResidents) { return handler.getResidents(session, variableArguments, context); } + return handler?.getVariables?.(session, context) ?? []; } public async getAddressOfVariable(variableName: string): Promise { diff --git a/src/plugin/memory-webview-main.ts b/src/plugin/memory-webview-main.ts index 815d793..08bfd2a 100644 --- a/src/plugin/memory-webview-main.ts +++ b/src/plugin/memory-webview-main.ts @@ -291,7 +291,7 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider { } } - protected async getVariables(request: ReadMemoryArguments): Promise { + protected async getVariables(request: [ReadMemoryArguments, Context?]): Promise { try { return await this.memoryProvider.getVariables(request); } catch (err) { @@ -316,7 +316,7 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider { this.setMemoryViewSettings(ctx.messageParticipant, { visibleColumns }); } - protected async storeMemory(storeArguments: StoreMemoryArguments): Promise { + protected async storeMemory(storeArguments: [StoreMemoryArguments, Context?]): Promise { // Even if we disable the command in VS Code through enablement or when condition, programmatic execution is still possible. // However, we want to fail early in case the user tries to execute a disabled command if (!this.memoryProvider.createContext().canRead) { diff --git a/src/webview/memory-webview-view.tsx b/src/webview/memory-webview-view.tsx index a066e40..4aca184 100644 --- a/src/webview/memory-webview-view.tsx +++ b/src/webview/memory-webview-view.tsx @@ -336,7 +336,7 @@ class App extends React.Component<{}, MemoryAppState> { } protected storeMemory = async (): Promise => { - await messenger.sendRequest(storeMemoryType, HOST_EXTENSION, { ...this.state.activeReadArguments }); + await messenger.sendRequest(storeMemoryType, HOST_EXTENSION, [{ ...this.state.activeReadArguments }, this.state.context]); }; protected applyMemory = async (): Promise => { diff --git a/src/webview/variables/variable-decorations.ts b/src/webview/variables/variable-decorations.ts index b0ca61e..78e818f 100644 --- a/src/webview/variables/variable-decorations.ts +++ b/src/webview/variables/variable-decorations.ts @@ -48,7 +48,7 @@ export class VariableDecorator implements ColumnContribution, Decorator { async fetchData(currentViewParameters: ReadMemoryArguments): Promise { if (!this.active || !currentViewParameters.memoryReference || !currentViewParameters.count) { return; } - const visibleVariables = (await messenger.sendRequest(getVariablesType, HOST_EXTENSION, currentViewParameters)) + const visibleVariables = (await messenger.sendRequest(getVariablesType, HOST_EXTENSION, [currentViewParameters, undefined])) .map(transmissible => { const startAddress = BigInt(transmissible.startAddress); return {