Skip to content

Commit

Permalink
Enhances the context data of the context menu
Browse files Browse the repository at this point in the history
* Endianess setting
* Bytes per MAU setting
* Start address and length of the memory data groups
  • Loading branch information
planger committed Jun 4, 2024
1 parent b5109dd commit 57338e7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/common/webview-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { WebviewIdMessageParticipant } from 'vscode-messenger-common';
import { VariableMetadata } from './memory-range';
import { Endianness, VariableMetadata } from './memory-range';
import { ReadMemoryArguments } from './messaging';

export interface WebviewContext {
Expand All @@ -24,6 +24,8 @@ export interface WebviewContext {
showAsciiColumn: boolean
showVariablesColumn: boolean,
showRadixPrefix: boolean,
endianness: Endianness,
bytesPerMau: number,
activeReadArguments: Required<ReadMemoryArguments>
}

Expand Down
2 changes: 2 additions & 0 deletions src/webview/columns/data-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { writeMemoryType } from '../../common/messaging';
import type { MemorySizeOptions } from '../components/memory-table';
import { decorationService } from '../decorations/decoration-service';
import { Disposable, FullNodeAttributes } from '../utils/view-types';
import { createGroupVscodeContext } from '../utils/vscode-contexts';
import { characterWidthInContainer, elementInnerWidth } from '../utils/window';
import { messenger } from '../view-messenger';
import { ColumnContribution, TableRenderOptions } from './column-contribution-service';
Expand Down Expand Up @@ -87,6 +88,7 @@ export class EditableDataColumnRow extends React.Component<EditableDataColumnRow
data-range={`${startAddress}-${endAddress}`}
key={startAddress.toString(16)}
onDoubleClick={this.setGroupEdit}
{...createGroupVscodeContext(startAddress, toOffset(startAddress, endAddress, this.props.options.bytesPerMau * 8))}
>
{maus}
</span>;
Expand Down
9 changes: 6 additions & 3 deletions src/webview/components/memory-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ export class MemoryWidget extends React.Component<MemoryWidgetProps, MemoryWidge

protected createVscodeContext(): VscodeContext {
const visibleColumns = this.props.columns.filter(candidate => candidate.active).map(column => column.contribution.id);
const { messageParticipant, showRadixPrefix, endianness, bytesPerMau, activeReadArguments } = this.props;
return createAppVscodeContext({
messageParticipant: this.props.messageParticipant,
showRadixPrefix: this.props.showRadixPrefix,
messageParticipant,
showRadixPrefix,
showAsciiColumn: visibleColumns.includes('ascii'),
showVariablesColumn: visibleColumns.includes('variables'),
activeReadArguments: this.props.activeReadArguments
endianness,
bytesPerMau,
activeReadArguments
});

}
Expand Down
13 changes: 12 additions & 1 deletion src/webview/utils/vscode-contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface VscodeContext {
export type WebviewSection = 'optionsWidget' | 'advancedOptionsOverlay' | 'memoryTable';

export function createVscodeContext<C extends {}>(context: C): VscodeContext {
return { 'data-vscode-context': JSON.stringify(includeFlatKeys(context)) };
return { 'data-vscode-context': JSON.stringify(includeFlatKeys(context), replacerForBigInt) };
}

function includeFlatKeys(src: object): Record<string, unknown> {
Expand Down Expand Up @@ -60,8 +60,19 @@ export function createAppVscodeContext(context: Omit<WebviewContext, 'webviewSec
return createVscodeContext({ ...context, webviewSection: 'app', preventDefaultContextMenuItems: true });
}

export function createGroupVscodeContext(startAddress: BigInt, length: number): VscodeContext {
return createVscodeContext({ memoryData: { group: { startAddress, length } } });
}

export function createVariableVscodeContext(variable: BigIntVariableRange): VscodeContext {
const { name, type, value, isPointer } = variable;
return createVscodeContext({ variable: { name, type, value, isPointer } });
}

function replacerForBigInt(_: string, value: unknown): unknown {
if (typeof value === 'bigint') {
return `0x${value.toString(16)}`;
}
return value;
}

0 comments on commit 57338e7

Please sign in to comment.