diff --git a/package.json b/package.json index 3f3a852..777f809 100644 --- a/package.json +++ b/package.json @@ -142,7 +142,7 @@ "debug/variables/context": [ { "command": "memory-inspector.show-variable", - "when": "canViewMemory && memory-inspector.canRead" + "when": "canViewMemory && memory-inspector.canReadVariable" }, { "command": "memory-inspector.store-file", @@ -152,7 +152,7 @@ "view/item/context": [ { "command": "memory-inspector.show-variable", - "when": "canViewMemory && memory-inspector.canRead" + "when": "canViewMemory && memory-inspector.canReadVariable" } ], "explorer/context": [ diff --git a/src/common/messaging.ts b/src/common/messaging.ts index 8a0af09..dd10429 100644 --- a/src/common/messaging.ts +++ b/src/common/messaging.ts @@ -47,6 +47,7 @@ export interface SessionContext { sessionId?: string; canRead: boolean; canWrite: boolean; + canReadVariable: boolean; } // Notifications diff --git a/src/plugin/adapter-registry/adapter-capabilities.ts b/src/plugin/adapter-registry/adapter-capabilities.ts index 30e3d8b..85a9966 100644 --- a/src/plugin/adapter-registry/adapter-capabilities.ts +++ b/src/plugin/adapter-registry/adapter-capabilities.ts @@ -36,6 +36,7 @@ export interface AdapterCapabilities { writeMemory?(session: vscode.DebugSession, params: WriteMemoryArguments, context?: Context): Promise; getContexts?(session: vscode.DebugSession): Promise; getCurrentContext?(session: vscode.DebugSession): Promise; + supportShowVariables?(session: vscode.DebugSession): boolean; } export type WithChildren = Original & { children?: Array> }; @@ -143,6 +144,8 @@ export class AdapterVariableTracker implements vscode.DebugAdapterTracker { getContexts?(session: vscode.DebugSession): Promise; getCurrentContext?(session: vscode.DebugSession): Promise; + + supportShowVariables?(session: vscode.DebugSession): boolean; } export class VariableTracker implements AdapterCapabilities { diff --git a/src/plugin/adapter-registry/amalgamator-gdb-tracker.ts b/src/plugin/adapter-registry/amalgamator-gdb-tracker.ts index 9176ed1..46c5b0b 100644 --- a/src/plugin/adapter-registry/amalgamator-gdb-tracker.ts +++ b/src/plugin/adapter-registry/amalgamator-gdb-tracker.ts @@ -57,6 +57,10 @@ export class AmalgamatorSessionManager extends VariableTracker implements Adapte async getCurrentContext(session: vscode.DebugSession): Promise { return this.sessions.get(session.id)?.getCurrentContext?.(session); } + + supportShowVariables(_session: vscode.DebugSession): boolean { + return false; + } } export class AmalgamatorGdbVariableTransformer extends AdapterVariableTracker { diff --git a/src/plugin/memory-provider.ts b/src/plugin/memory-provider.ts index 1f0db7a..0315da1 100644 --- a/src/plugin/memory-provider.ts +++ b/src/plugin/memory-provider.ts @@ -30,6 +30,7 @@ export interface LabeledUint8Array extends Uint8Array { export class MemoryProvider { public static ReadKey = `${manifest.PACKAGE_NAME}.canRead`; public static WriteKey = `${manifest.PACKAGE_NAME}.canWrite`; + public static ReadVariableKey = `${manifest.PACKAGE_NAME}.canReadVariable`; private _onDidStopDebug = new vscode.EventEmitter(); public readonly onDidStopDebug = this._onDidStopDebug.event; @@ -105,10 +106,12 @@ export class MemoryProvider { createContext(session = vscode.debug.activeDebugSession): SessionContext { const sessionId = session?.id; const capabilities = sessionId ? this.sessionDebugCapabilities.get(sessionId) : undefined; + const canReadVariable = this.supportShowVariables(); return { sessionId, canRead: !!capabilities?.supportsReadMemoryRequest, - canWrite: !!capabilities?.supportsWriteMemoryRequest + canWrite: !!capabilities?.supportsWriteMemoryRequest, + canReadVariable: !!capabilities?.supportsReadMemoryRequest && !!canReadVariable }; } @@ -116,6 +119,7 @@ export class MemoryProvider { const newContext = this.createContext(session); vscode.commands.executeCommand('setContext', MemoryProvider.ReadKey, newContext.canRead); vscode.commands.executeCommand('setContext', MemoryProvider.WriteKey, newContext.canWrite); + vscode.commands.executeCommand('setContext', MemoryProvider.ReadVariableKey, newContext.canReadVariable); this._onDidChangeSessionContext.fire(newContext); } @@ -206,4 +210,10 @@ export class MemoryProvider { const handler = this.adapterRegistry?.getHandlerForSession(session.type); return handler?.getCurrentContext?.(session); } + + public supportShowVariables(): boolean { + const session = this.assertActiveSession('supports show variables'); + const handler = this.adapterRegistry?.getHandlerForSession(session.type); + return handler?.supportShowVariables?.(session) ?? true; + } } diff --git a/src/webview/memory-webview-view.tsx b/src/webview/memory-webview-view.tsx index a2917b2..257348e 100644 --- a/src/webview/memory-webview-view.tsx +++ b/src/webview/memory-webview-view.tsx @@ -71,7 +71,8 @@ export interface MemoryAppState extends MemoryState, MemoryDisplayConfiguration const DEFAULT_SESSION_CONTEXT: SessionContext = { canRead: false, - canWrite: false + canWrite: false, + canReadVariable: false }; const MEMORY_DISPLAY_CONFIGURATION_DEFAULTS: MemoryDisplayConfiguration = {