Skip to content

Commit d2fef45

Browse files
committed
Conditional 'Show In Memory Inspector' for Variable
Add new conditional for context menu showing Memory Inspector for a variable because some DAPs may not support it. Signed-off-by: Thor Thayer <[email protected]>
1 parent b531f77 commit d2fef45

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
"debug/variables/context": [
143143
{
144144
"command": "memory-inspector.show-variable",
145-
"when": "canViewMemory && memory-inspector.canRead"
145+
"when": "canViewMemory && memory-inspector.canReadVariable"
146146
},
147147
{
148148
"command": "memory-inspector.store-file",
@@ -152,7 +152,7 @@
152152
"view/item/context": [
153153
{
154154
"command": "memory-inspector.show-variable",
155-
"when": "canViewMemory && memory-inspector.canRead"
155+
"when": "canViewMemory && memory-inspector.canReadVariable"
156156
}
157157
],
158158
"explorer/context": [

src/common/messaging.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface SessionContext {
4747
sessionId?: string;
4848
canRead: boolean;
4949
canWrite: boolean;
50+
canReadVariable: boolean;
5051
}
5152

5253
// Notifications

src/plugin/adapter-registry/adapter-capabilities.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface AdapterCapabilities {
3636
writeMemory?(session: vscode.DebugSession, params: WriteMemoryArguments, context?: Context): Promise<WriteMemoryResult>;
3737
getContexts?(session: vscode.DebugSession): Promise<Context[]>;
3838
getCurrentContext?(session: vscode.DebugSession): Promise<Context | undefined>;
39+
supportShowVariables?(session: vscode.DebugSession): boolean;
3940
}
4041

4142
export type WithChildren<Original> = Original & { children?: Array<WithChildren<DebugProtocol.Variable>> };
@@ -143,6 +144,8 @@ export class AdapterVariableTracker implements vscode.DebugAdapterTracker {
143144

144145
getContexts?(session: vscode.DebugSession): Promise<Context[]>;
145146
getCurrentContext?(session: vscode.DebugSession): Promise<Context | undefined>;
147+
148+
supportShowVariables?(session: vscode.DebugSession): boolean;
146149
}
147150

148151
export class VariableTracker implements AdapterCapabilities {

src/plugin/adapter-registry/amalgamator-gdb-tracker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export class AmalgamatorSessionManager extends VariableTracker implements Adapte
5757
async getCurrentContext(session: vscode.DebugSession): Promise<Context | undefined> {
5858
return this.sessions.get(session.id)?.getCurrentContext?.(session);
5959
}
60+
61+
supportShowVariables(_session: vscode.DebugSession): boolean {
62+
return false;
63+
}
6064
}
6165

6266
export class AmalgamatorGdbVariableTransformer extends AdapterVariableTracker {

src/plugin/memory-provider.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface LabeledUint8Array extends Uint8Array {
3030
export class MemoryProvider {
3131
public static ReadKey = `${manifest.PACKAGE_NAME}.canRead`;
3232
public static WriteKey = `${manifest.PACKAGE_NAME}.canWrite`;
33+
public static ReadVariableKey = `${manifest.PACKAGE_NAME}.canReadVariable`;
3334

3435
private _onDidStopDebug = new vscode.EventEmitter<vscode.DebugSession>();
3536
public readonly onDidStopDebug = this._onDidStopDebug.event;
@@ -105,17 +106,20 @@ export class MemoryProvider {
105106
createContext(session = vscode.debug.activeDebugSession): SessionContext {
106107
const sessionId = session?.id;
107108
const capabilities = sessionId ? this.sessionDebugCapabilities.get(sessionId) : undefined;
109+
const canReadVariable = this.supportShowVariables();
108110
return {
109111
sessionId,
110112
canRead: !!capabilities?.supportsReadMemoryRequest,
111-
canWrite: !!capabilities?.supportsWriteMemoryRequest
113+
canWrite: !!capabilities?.supportsWriteMemoryRequest,
114+
canReadVariable: !!capabilities?.supportsReadMemoryRequest && !!canReadVariable
112115
};
113116
}
114117

115118
protected setContext(session?: vscode.DebugSession): void {
116119
const newContext = this.createContext(session);
117120
vscode.commands.executeCommand('setContext', MemoryProvider.ReadKey, newContext.canRead);
118121
vscode.commands.executeCommand('setContext', MemoryProvider.WriteKey, newContext.canWrite);
122+
vscode.commands.executeCommand('setContext', MemoryProvider.ReadVariableKey, newContext.canReadVariable);
119123
this._onDidChangeSessionContext.fire(newContext);
120124
}
121125

@@ -206,4 +210,10 @@ export class MemoryProvider {
206210
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
207211
return handler?.getCurrentContext?.(session);
208212
}
213+
214+
public supportShowVariables(): boolean {
215+
const session = this.assertActiveSession('supports show variables');
216+
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
217+
return handler?.supportShowVariables?.(session) ?? true;
218+
}
209219
}

src/webview/memory-webview-view.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export interface MemoryAppState extends MemoryState, MemoryDisplayConfiguration
7171

7272
const DEFAULT_SESSION_CONTEXT: SessionContext = {
7373
canRead: false,
74-
canWrite: false
74+
canWrite: false,
75+
canReadVariable: false
7576
};
7677

7778
const MEMORY_DISPLAY_CONFIGURATION_DEFAULTS: MemoryDisplayConfiguration = {

0 commit comments

Comments
 (0)