Skip to content

Commit 9ecd716

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 <thor.thayer@ericsson.com>
1 parent e400b97 commit 9ecd716

7 files changed

Lines changed: 22 additions & 4 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"debug/variables/context": [
149149
{
150150
"command": "memory-inspector.show-variable",
151-
"when": "canViewMemory && memory-inspector.canRead"
151+
"when": "canViewMemory && memory-inspector.canReadVariable"
152152
},
153153
{
154154
"command": "memory-inspector.go-to-value",
@@ -162,7 +162,7 @@
162162
"view/item/context": [
163163
{
164164
"command": "memory-inspector.show-variable",
165-
"when": "canViewMemory && memory-inspector.canRead"
165+
"when": "canViewMemory && memory-inspector.canReadVariable"
166166
}
167167
],
168168
"explorer/context": [

src/common/messaging.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface SessionContext {
4848
canRead: boolean;
4949
canWrite: boolean;
5050
stopped?: boolean;
51+
canReadVariable: boolean;
5152
}
5253

5354
// 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,10 @@ export class MemoryProvider {
111111
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
112112
return handler?.getCurrentContext?.(session);
113113
}
114+
115+
public supportShowVariables(): boolean {
116+
const session = this.sessionTracker.assertActiveSession('supports show variables');
117+
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
118+
return handler?.supportShowVariables?.(session) ?? true;
119+
}
114120
}

src/plugin/memory-webview-main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,14 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
284284

285285
protected createContext(session = this.sessionTracker.activeSession): SessionContext {
286286
const sessionId = session?.id;
287+
const canReadVariables = !!this.sessionTracker.hasDebugCapability(session, 'supportsReadMemoryRequest') &&
288+
!!this.memoryProvider.supportShowVariables();
287289
return {
288290
sessionId,
289291
canRead: !!this.sessionTracker.hasDebugCapability(session, 'supportsReadMemoryRequest'),
290292
canWrite: !!this.sessionTracker.hasDebugCapability(session, 'supportsWriteMemoryRequest'),
291-
stopped: this.sessionTracker.isStopped(session)
293+
stopped: this.sessionTracker.isStopped(session),
294+
canReadVariable: !!this.sessionTracker.hasDebugCapability(session, 'supportsReadMemoryRequest') && !!canReadVariables
292295
};
293296
}
294297

src/webview/memory-webview-view.tsx

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

7575
export const DEFAULT_SESSION_CONTEXT: SessionContext = {
7676
canRead: false,
77-
canWrite: false
77+
canWrite: false,
78+
canReadVariable: false
7879
};
7980

8081
export const DEFAULT_MEMORY_DISPLAY_CONFIGURATION: MemoryDisplayConfiguration = {

0 commit comments

Comments
 (0)