Skip to content

Commit

Permalink
Conditional 'Show In Memory Inspector' for Variable
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
WyoTwT committed May 28, 2024
1 parent e400b97 commit 9ecd716
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"debug/variables/context": [
{
"command": "memory-inspector.show-variable",
"when": "canViewMemory && memory-inspector.canRead"
"when": "canViewMemory && memory-inspector.canReadVariable"
},
{
"command": "memory-inspector.go-to-value",
Expand All @@ -162,7 +162,7 @@
"view/item/context": [
{
"command": "memory-inspector.show-variable",
"when": "canViewMemory && memory-inspector.canRead"
"when": "canViewMemory && memory-inspector.canReadVariable"
}
],
"explorer/context": [
Expand Down
1 change: 1 addition & 0 deletions src/common/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface SessionContext {
canRead: boolean;
canWrite: boolean;
stopped?: boolean;
canReadVariable: boolean;
}

// Notifications
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/adapter-registry/adapter-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface AdapterCapabilities {
writeMemory?(session: vscode.DebugSession, params: WriteMemoryArguments, context?: Context): Promise<WriteMemoryResult>;
getContexts?(session: vscode.DebugSession): Promise<Context[]>;
getCurrentContext?(session: vscode.DebugSession): Promise<Context | undefined>;
supportShowVariables?(session: vscode.DebugSession): boolean;
}

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

getContexts?(session: vscode.DebugSession): Promise<Context[]>;
getCurrentContext?(session: vscode.DebugSession): Promise<Context | undefined>;

supportShowVariables?(session: vscode.DebugSession): boolean;
}

export class VariableTracker implements AdapterCapabilities {
Expand Down
4 changes: 4 additions & 0 deletions src/plugin/adapter-registry/amalgamator-gdb-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export class AmalgamatorSessionManager extends VariableTracker implements Adapte
async getCurrentContext(session: vscode.DebugSession): Promise<Context | undefined> {
return this.sessions.get(session.id)?.getCurrentContext?.(session);
}

supportShowVariables(_session: vscode.DebugSession): boolean {
return false;
}
}

export class AmalgamatorGdbVariableTransformer extends AdapterVariableTracker {
Expand Down
6 changes: 6 additions & 0 deletions src/plugin/memory-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,10 @@ export class MemoryProvider {
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
return handler?.getCurrentContext?.(session);
}

public supportShowVariables(): boolean {
const session = this.sessionTracker.assertActiveSession('supports show variables');
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
return handler?.supportShowVariables?.(session) ?? true;
}
}
5 changes: 4 additions & 1 deletion src/plugin/memory-webview-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,14 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {

protected createContext(session = this.sessionTracker.activeSession): SessionContext {
const sessionId = session?.id;
const canReadVariables = !!this.sessionTracker.hasDebugCapability(session, 'supportsReadMemoryRequest') &&
!!this.memoryProvider.supportShowVariables();
return {
sessionId,
canRead: !!this.sessionTracker.hasDebugCapability(session, 'supportsReadMemoryRequest'),
canWrite: !!this.sessionTracker.hasDebugCapability(session, 'supportsWriteMemoryRequest'),
stopped: this.sessionTracker.isStopped(session)
stopped: this.sessionTracker.isStopped(session),
canReadVariable: !!this.sessionTracker.hasDebugCapability(session, 'supportsReadMemoryRequest') && !!canReadVariables
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/webview/memory-webview-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export interface MemoryAppState extends MemoryState, MemoryDisplayConfiguration

export const DEFAULT_SESSION_CONTEXT: SessionContext = {
canRead: false,
canWrite: false
canWrite: false,
canReadVariable: false
};

export const DEFAULT_MEMORY_DISPLAY_CONFIGURATION: MemoryDisplayConfiguration = {
Expand Down

0 comments on commit 9ecd716

Please sign in to comment.