Skip to content

Commit 97310ef

Browse files
committed
Enable extenders to overwrite default settings
* Harmonizes naming of webview config * Extracts column ids into constants * Switches to ... menu for multiple reset options in options menu Fixes #77
1 parent 6aeccf0 commit 97310ef

19 files changed

+213
-107
lines changed

media/options-widget.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
margin: 0.5rem 0 0.2rem 0;
173173
}
174174

175-
.reset-advanced-options-icon {
175+
.more-actions-overlay-icon {
176176
position: absolute;
177177
top: 12px;
178178
right: 0;
@@ -204,3 +204,9 @@
204204
color: var(--vscode-button-background);
205205
margin-left: 0.2em;
206206
}
207+
208+
.settings-contribution-message {
209+
margin-top: 0;
210+
margin-bottom: 0.5rem;
211+
color: var(--vscode-descriptionForeground);
212+
}

package.json

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@
126126
"title": "Apply Memory from File...",
127127
"enablement": "memory-inspector.canWrite",
128128
"category": "Memory"
129+
},
130+
{
131+
"command": "memory-inspector.reset-display-options-to-debugger-defaults",
132+
"title": "Reset to Debugger Defaults",
133+
"enablement": "optionsMenu && hasDebuggerDefaults",
134+
"category": "Memory"
135+
},
136+
{
137+
"command": "memory-inspector.reset-display-options",
138+
"title": "Reset to Defaults",
139+
"enablement": "optionsMenu",
140+
"category": "Memory"
129141
}
130142
],
131143
"menus": {
@@ -183,37 +195,47 @@
183195
{
184196
"command": "memory-inspector.toggle-variables-column",
185197
"group": "a_display@1",
186-
"when": "webviewId === memory-inspector.memory"
198+
"when": "webviewId === memory-inspector.memory && !optionsMenu"
187199
},
188200
{
189201
"command": "memory-inspector.toggle-ascii-column",
190202
"group": "a_display@2",
191-
"when": "webviewId === memory-inspector.memory"
203+
"when": "webviewId === memory-inspector.memory && !optionsMenu"
192204
},
193205
{
194206
"command": "memory-inspector.toggle-radix-prefix",
195207
"group": "a_display@3",
196-
"when": "webviewId === memory-inspector.memory"
208+
"when": "webviewId === memory-inspector.memory && !optionsMenu"
197209
},
198210
{
199211
"command": "memory-inspector.store-file",
200212
"group": "c_store-and-restore@1",
201-
"when": "webviewId === memory-inspector.memory"
213+
"when": "webviewId === memory-inspector.memory && !optionsMenu"
202214
},
203215
{
204216
"command": "memory-inspector.apply-file",
205217
"group": "c_store-and-restore@2",
206-
"when": "webviewId === memory-inspector.memory"
218+
"when": "webviewId === memory-inspector.memory && !optionsMenu"
207219
},
208220
{
209221
"command": "memory-inspector.show-advanced-display-options",
210222
"group": "z_more",
211-
"when": "webviewId === memory-inspector.memory"
223+
"when": "webviewId === memory-inspector.memory && !optionsMenu"
212224
},
213225
{
214226
"command": "memory-inspector.go-to-value",
215227
"group": "display@7",
216-
"when": "webviewId === memory-inspector.memory && memory-inspector.variable.isPointer"
228+
"when": "webviewId === memory-inspector.memory && memory-inspector.variable.isPointer && !optionsMenu"
229+
},
230+
{
231+
"command": "memory-inspector.reset-display-options-to-debugger-defaults",
232+
"group": "a_reset@1",
233+
"when": "webviewId === memory-inspector.memory && optionsMenu && hasDebuggerDefaults"
234+
},
235+
{
236+
"command": "memory-inspector.reset-display-options",
237+
"group": "a_reset@2",
238+
"when": "webviewId === memory-inspector.memory && optionsMenu"
217239
}
218240
]
219241
},
@@ -407,6 +429,11 @@
407429
"type": "boolean",
408430
"default": true,
409431
"description": "Display the radix prefix (e.g., '0x' for hexadecimal, '0b' for binary) before memory addresses."
432+
},
433+
"memory-inspector.allowDebuggerOverwriteSettings": {
434+
"type": "boolean",
435+
"default": true,
436+
"description": "Allow debuggers to overwrite the default memory display settings."
410437
}
411438
}
412439
}

src/common/manifest.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,9 @@ export const CONFIG_SHOW_RADIX_PREFIX = 'showRadixPrefix';
7474
export const DEFAULT_SHOW_RADIX_PREFIX = true;
7575

7676
// Columns
77-
export const CONFIG_SHOW_VARIABLES_COLUMN = 'columns.variables';
78-
export const CONFIG_SHOW_ASCII_COLUMN = 'columns.ascii';
77+
export const CONFIG_SHOW_VARIABLES_COLUMN = 'variables';
78+
export const CONFIG_SHOW_ASCII_COLUMN = 'ascii';
79+
export const DEFAULT_VISIBLE_COLUMNS = [CONFIG_SHOW_VARIABLES_COLUMN, CONFIG_SHOW_ASCII_COLUMN];
80+
81+
// Extension Settings
82+
export const CONFIG_ALLOW_DEBUGGER_OVERWRITE_SETTINGS = 'allowDebuggerOverwriteSettings';

src/common/messaging.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export interface SessionContext {
4848
// Notifications
4949
export const readyType: NotificationType<void> = { method: 'ready' };
5050
export const setMemoryViewSettingsType: NotificationType<Partial<MemoryViewSettings>> = { method: 'setMemoryViewSettings' };
51-
export const resetMemoryViewSettingsType: NotificationType<void> = { method: 'resetMemoryViewSettings' };
5251
export const setTitleType: NotificationType<string> = { method: 'setTitle' };
5352
export const memoryWrittenType: NotificationType<WrittenMemory> = { method: 'memoryWritten' };
5453
export const sessionContextChangedType: NotificationType<SessionContext> = { method: 'sessionContextChanged' };

src/common/webview-configuration.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,44 @@ import { WebviewIdMessageParticipant } from 'vscode-messenger-common';
1717
import { Endianness, GroupsPerRowOption, PeriodicRefresh, RefreshOnStop } from './manifest';
1818
import { Radix } from './memory-range';
1919

20-
/** The memory display configuration that can be specified for the memory widget. */
21-
export interface MemoryDisplayConfiguration {
20+
/** Specifies the settings for displaying memory addresses in the memory data table. */
21+
export interface MemoryAddressDisplaySettings {
22+
addressPadding: AddressPadding;
23+
addressRadix: Radix;
24+
showRadixPrefix: boolean;
25+
}
26+
27+
export type AddressPadding = 'Min' | 0 | 32 | 64;
28+
29+
/** Specifies the settings for displaying memory data in the memory data table, including the memory addresses. */
30+
export interface MemoryDataDisplaySettings extends MemoryAddressDisplaySettings {
2231
bytesPerMau: number;
2332
mausPerGroup: number;
2433
groupsPerRow: GroupsPerRowOption;
2534
endianness: Endianness;
2635
scrollingBehavior: ScrollingBehavior;
27-
addressPadding: AddressPadding;
28-
addressRadix: Radix;
29-
showRadixPrefix: boolean;
3036
refreshOnStop: RefreshOnStop;
3137
periodicRefresh: PeriodicRefresh;
3238
periodicRefreshInterval: number;
3339
}
3440

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

37-
export type AddressPadding = 'Minimal' | number;
38-
39-
export interface ColumnVisibilityStatus {
43+
/** Specifies the display settings of the memory data table, including the memory data and addresses. */
44+
export interface MemoryDisplaySettings extends MemoryDataDisplaySettings {
4045
visibleColumns: string[];
4146
}
4247

48+
/** An extender's contribution to the `MemoryDisplaySettings` via the `AdapterCapabilities`. */
49+
export interface MemoryDisplaySettingsContribution {
50+
message?: string;
51+
settings?: Partial<MemoryDisplaySettings>;
52+
}
53+
4354
/** All settings related to memory view that can be specified for the webview from the extension "main". */
44-
export interface MemoryViewSettings extends ColumnVisibilityStatus, MemoryDisplayConfiguration {
55+
export interface MemoryViewSettings extends MemoryDisplaySettings {
4556
title: string
4657
messageParticipant: WebviewIdMessageParticipant;
58+
hasDebuggerDefaults?: boolean;
59+
contributionMessage?: string;
4760
}

src/common/webview-context.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
********************************************************************************/
1616

1717
import { WebviewIdMessageParticipant } from 'vscode-messenger-common';
18+
import * as manifest from '../common/manifest';
1819
import { Endianness } from './manifest';
1920
import { VariableMetadata } from './memory-range';
2021
import { ReadMemoryArguments } from './messaging';
@@ -25,6 +26,7 @@ export interface WebviewContext {
2526
showAsciiColumn: boolean
2627
showVariablesColumn: boolean,
2728
showRadixPrefix: boolean,
29+
hasDebuggerDefaults?: boolean,
2830
endianness: Endianness,
2931
bytesPerMau: number,
3032
activeReadArguments: Required<ReadMemoryArguments>
@@ -46,10 +48,10 @@ export interface WebviewVariableContext extends WebviewCellContext {
4648
export function getVisibleColumns(context: WebviewContext): string[] {
4749
const columns = [];
4850
if (context.showAsciiColumn) {
49-
columns.push('ascii');
51+
columns.push(manifest.CONFIG_SHOW_ASCII_COLUMN);
5052
}
5153
if (context.showVariablesColumn) {
52-
columns.push('variables');
54+
columns.push(manifest.CONFIG_SHOW_VARIABLES_COLUMN);
5355
}
5456
return columns;
5557
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { DebugProtocol } from '@vscode/debugprotocol';
1818
import * as vscode from 'vscode';
1919
import { isDebugRequest, isDebugResponse } from '../../common/debug-requests';
2020
import { VariableRange } from '../../common/memory-range';
21+
import { MemoryDisplaySettingsContribution } from '../../common/webview-configuration';
2122
import { Logger } from '../logger';
2223

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

src/plugin/memory-provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { sendRequest } from '../common/debug-requests';
2020
import { stringToBytesMemory } from '../common/memory';
2121
import { VariableRange } from '../common/memory-range';
2222
import { ReadMemoryResult, WriteMemoryResult } from '../common/messaging';
23+
import { MemoryDisplaySettingsContribution } from '../common/webview-configuration';
2324
import { AdapterRegistry } from './adapter-registry/adapter-registry';
2425
import { isSessionEvent, SessionTracker } from './session-tracker';
2526

@@ -84,8 +85,14 @@ export class MemoryProvider {
8485
}
8586

8687
public async getSizeOfVariable(variableName: string): Promise<bigint | undefined> {
87-
const session = this.sessionTracker.assertActiveSession('get address of variable');
88+
const session = this.sessionTracker.assertActiveSession('get size of variable');
8889
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
8990
return handler?.getSizeOfVariable?.(session, variableName);
9091
}
92+
93+
public async getMemoryDisplaySettingsContribution(): Promise<MemoryDisplaySettingsContribution> {
94+
const session = this.sessionTracker.assertActiveSession('get memory display settings contribution');
95+
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
96+
return handler?.getMemoryDisplaySettings?.(session) ?? {};
97+
}
9198
}

0 commit comments

Comments
 (0)