Skip to content

Commit

Permalink
Enable extenders to overwrite default settings
Browse files Browse the repository at this point in the history
* Harmonizes naming of webview config
* Extracts column ids into constants
* Switches to ... menu for multiple reset options in options menu

Fixes #77
  • Loading branch information
planger committed Jun 10, 2024
1 parent 6aeccf0 commit c8c2630
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 105 deletions.
8 changes: 7 additions & 1 deletion media/options-widget.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
margin: 0.5rem 0 0.2rem 0;
}

.reset-advanced-options-icon {
.more-actions-overlay-icon {
position: absolute;
top: 12px;
right: 0;
Expand Down Expand Up @@ -204,3 +204,9 @@
color: var(--vscode-button-background);
margin-left: 0.2em;
}

.settings-contribution-message {
margin-top: 0;
margin-bottom: 0.5rem;
color: var(--vscode-descriptionForeground);
}
41 changes: 34 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@
"title": "Apply Memory from File...",
"enablement": "memory-inspector.canWrite",
"category": "Memory"
},
{
"command": "memory-inspector.reset-display-options-to-debugger-defaults",
"title": "Reset to Debugger Defaults",
"enablement": "optionsMenu && hasDebuggerDefaults",
"category": "Memory"
},
{
"command": "memory-inspector.reset-display-options",
"title": "Reset to Defaults",
"enablement": "optionsMenu",
"category": "Memory"
}
],
"menus": {
Expand Down Expand Up @@ -183,37 +195,47 @@
{
"command": "memory-inspector.toggle-variables-column",
"group": "a_display@1",
"when": "webviewId === memory-inspector.memory"
"when": "webviewId === memory-inspector.memory && !optionsMenu"
},
{
"command": "memory-inspector.toggle-ascii-column",
"group": "a_display@2",
"when": "webviewId === memory-inspector.memory"
"when": "webviewId === memory-inspector.memory && !optionsMenu"
},
{
"command": "memory-inspector.toggle-radix-prefix",
"group": "a_display@3",
"when": "webviewId === memory-inspector.memory"
"when": "webviewId === memory-inspector.memory && !optionsMenu"
},
{
"command": "memory-inspector.store-file",
"group": "c_store-and-restore@1",
"when": "webviewId === memory-inspector.memory"
"when": "webviewId === memory-inspector.memory && !optionsMenu"
},
{
"command": "memory-inspector.apply-file",
"group": "c_store-and-restore@2",
"when": "webviewId === memory-inspector.memory"
"when": "webviewId === memory-inspector.memory && !optionsMenu"
},
{
"command": "memory-inspector.show-advanced-display-options",
"group": "z_more",
"when": "webviewId === memory-inspector.memory"
"when": "webviewId === memory-inspector.memory && !optionsMenu"
},
{
"command": "memory-inspector.go-to-value",
"group": "display@7",
"when": "webviewId === memory-inspector.memory && memory-inspector.variable.isPointer"
"when": "webviewId === memory-inspector.memory && memory-inspector.variable.isPointer && !optionsMenu"
},
{
"command": "memory-inspector.reset-display-options-to-debugger-defaults",
"group": "a_reset@1",
"when": "webviewId === memory-inspector.memory && optionsMenu && hasDebuggerDefaults"
},
{
"command": "memory-inspector.reset-display-options",
"group": "a_reset@2",
"when": "webviewId === memory-inspector.memory && optionsMenu"
}
]
},
Expand Down Expand Up @@ -407,6 +429,11 @@
"type": "boolean",
"default": true,
"description": "Display the radix prefix (e.g., '0x' for hexadecimal, '0b' for binary) before memory addresses."
},
"memory-inspector.allowDebuggerOverwriteSettings": {
"type": "boolean",
"default": true,
"description": "Allow debuggers to overwrite the default memory display settings."
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/common/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,9 @@ export const CONFIG_SHOW_RADIX_PREFIX = 'showRadixPrefix';
export const DEFAULT_SHOW_RADIX_PREFIX = true;

// Columns
export const CONFIG_SHOW_VARIABLES_COLUMN = 'columns.variables';
export const CONFIG_SHOW_ASCII_COLUMN = 'columns.ascii';
export const CONFIG_SHOW_VARIABLES_COLUMN = 'variables';
export const CONFIG_SHOW_ASCII_COLUMN = 'ascii';
export const DEFAULT_VISIBLE_COLUMNS = [CONFIG_SHOW_VARIABLES_COLUMN, CONFIG_SHOW_ASCII_COLUMN];

// Extension Settings
export const CONFIG_ALLOW_DEBUGGER_OVERWRITE_SETTINGS = 'allowDebuggerOverwriteSettings';
1 change: 0 additions & 1 deletion src/common/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export interface SessionContext {
// Notifications
export const readyType: NotificationType<void> = { method: 'ready' };
export const setMemoryViewSettingsType: NotificationType<Partial<MemoryViewSettings>> = { method: 'setMemoryViewSettings' };
export const resetMemoryViewSettingsType: NotificationType<void> = { method: 'resetMemoryViewSettings' };
export const setTitleType: NotificationType<string> = { method: 'setTitle' };
export const memoryWrittenType: NotificationType<WrittenMemory> = { method: 'memoryWritten' };
export const sessionContextChangedType: NotificationType<SessionContext> = { method: 'sessionContextChanged' };
Expand Down
31 changes: 22 additions & 9 deletions src/common/webview-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,44 @@ import { WebviewIdMessageParticipant } from 'vscode-messenger-common';
import { Endianness, GroupsPerRowOption, PeriodicRefresh, RefreshOnStop } from './manifest';
import { Radix } from './memory-range';

/** The memory display configuration that can be specified for the memory widget. */
export interface MemoryDisplayConfiguration {
/** Specifies the settings for displaying memory addresses in the memory data table. */
export interface MemoryAddressDisplaySettings {
addressPadding: AddressPadding;
addressRadix: Radix;
showRadixPrefix: boolean;
}

export type AddressPadding = 'Min' | 0 | 32 | 64;

/** Specifies the settings for displaying memory data in the memory data table, including the memory addresses. */
export interface MemoryDataDisplaySettings extends MemoryAddressDisplaySettings {
bytesPerMau: number;
mausPerGroup: number;
groupsPerRow: GroupsPerRowOption;
endianness: Endianness;
scrollingBehavior: ScrollingBehavior;
addressPadding: AddressPadding;
addressRadix: Radix;
showRadixPrefix: boolean;
refreshOnStop: RefreshOnStop;
periodicRefresh: PeriodicRefresh;
periodicRefreshInterval: number;
}

export type ScrollingBehavior = 'Paginate' | 'Grow' | 'Auto-Append';

export type AddressPadding = 'Minimal' | number;

export interface ColumnVisibilityStatus {
/** Specifies the display settings of the memory data table, including the memory data and addresses. */
export interface MemoryDisplaySettings extends MemoryDataDisplaySettings {
visibleColumns: string[];
}

/** An extender's contribution to the `MemoryDisplaySettings` via the `AdapterCapabilities`. */
export interface MemoryDisplaySettingsContribution {
message?: string;
settings?: Partial<MemoryDisplaySettings>;
}

/** All settings related to memory view that can be specified for the webview from the extension "main". */
export interface MemoryViewSettings extends ColumnVisibilityStatus, MemoryDisplayConfiguration {
export interface MemoryViewSettings extends MemoryDisplaySettings {
title: string
messageParticipant: WebviewIdMessageParticipant;
hasDebuggerDefaults?: boolean;
contributionMessage?: string;
}
6 changes: 4 additions & 2 deletions src/common/webview-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
********************************************************************************/

import { WebviewIdMessageParticipant } from 'vscode-messenger-common';
import * as manifest from '../common/manifest';
import { Endianness } from './manifest';
import { VariableMetadata } from './memory-range';
import { ReadMemoryArguments } from './messaging';
Expand All @@ -25,6 +26,7 @@ export interface WebviewContext {
showAsciiColumn: boolean
showVariablesColumn: boolean,
showRadixPrefix: boolean,
hasDebuggerDefaults?: boolean,
endianness: Endianness,
bytesPerMau: number,
activeReadArguments: Required<ReadMemoryArguments>
Expand All @@ -46,10 +48,10 @@ export interface WebviewVariableContext extends WebviewCellContext {
export function getVisibleColumns(context: WebviewContext): string[] {
const columns = [];
if (context.showAsciiColumn) {
columns.push('ascii');
columns.push(manifest.CONFIG_SHOW_ASCII_COLUMN);
}
if (context.showVariablesColumn) {
columns.push('variables');
columns.push(manifest.CONFIG_SHOW_VARIABLES_COLUMN);
}
return columns;
}
Expand Down
4 changes: 4 additions & 0 deletions src/plugin/adapter-registry/adapter-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DebugProtocol } from '@vscode/debugprotocol';
import * as vscode from 'vscode';
import { isDebugRequest, isDebugResponse } from '../../common/debug-requests';
import { VariableRange } from '../../common/memory-range';
import { MemoryDisplaySettingsContribution } from '../../common/webview-configuration';
import { Logger } from '../logger';

/** Represents capabilities that may be achieved with particular debug adapters but are not part of the DAP */
Expand All @@ -30,6 +31,9 @@ export interface AdapterCapabilities {
getAddressOfVariable?(session: vscode.DebugSession, variableName: string): Promise<string | undefined>;
/** Resolves the size of a given variable in bytes within the current context. */
getSizeOfVariable?(session: vscode.DebugSession, variableName: string): Promise<bigint | undefined>;
/** Retrieve the enforced default display settings for the memory view. */
getMemoryDisplaySettings?(session: vscode.DebugSession): Promise<Partial<MemoryDisplaySettingsContribution>>;
/** Initialize the trackers of this adapter's for the debug session. */
initializeAdapterTracker?(session: vscode.DebugSession): vscode.DebugAdapterTracker | undefined;
}

Expand Down
9 changes: 8 additions & 1 deletion src/plugin/memory-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { sendRequest } from '../common/debug-requests';
import { stringToBytesMemory } from '../common/memory';
import { VariableRange } from '../common/memory-range';
import { ReadMemoryResult, WriteMemoryResult } from '../common/messaging';
import { MemoryDisplaySettingsContribution } from '../common/webview-configuration';
import { AdapterRegistry } from './adapter-registry/adapter-registry';
import { isSessionEvent, SessionTracker } from './session-tracker';

Expand Down Expand Up @@ -84,8 +85,14 @@ export class MemoryProvider {
}

public async getSizeOfVariable(variableName: string): Promise<bigint | undefined> {
const session = this.sessionTracker.assertActiveSession('get address of variable');
const session = this.sessionTracker.assertActiveSession('get size of variable');
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
return handler?.getSizeOfVariable?.(session, variableName);
}

public async getMemoryDisplaySettingsContribution(): Promise<MemoryDisplaySettingsContribution> {
const session = this.sessionTracker.assertActiveSession('get memory display settings contribution');
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
return handler?.getMemoryDisplaySettings?.(session) ?? {};
}
}
Loading

0 comments on commit c8c2630

Please sign in to comment.