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
* Start and end address of the memory data
* Start and end address of the memory data groups
  • Loading branch information
planger committed May 6, 2024
1 parent b0046d4 commit c111b49
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 2 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,7 @@ export interface WebviewContext {
showAsciiColumn: boolean
showVariablesColumn: boolean,
showRadixPrefix: boolean,
endianness: Endianness,
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 @@ -90,6 +91,7 @@ export class EditableDataColumnRow extends React.Component<EditableDataColumnRow
style={style}
key={startAddress.toString(16)}
onDoubleClick={this.setGroupEdit}
{...createGroupVscodeContext(startAddress, endAddress)}
>
{maus}
</span>;
Expand Down
1 change: 1 addition & 0 deletions src/webview/components/memory-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class MemoryWidget extends React.Component<MemoryWidgetProps, MemoryWidge
showRadixPrefix: this.props.showRadixPrefix,
showAsciiColumn: visibleColumns.includes('ascii'),
showVariablesColumn: visibleColumns.includes('variables'),
endianness: this.props.endianness,
activeReadArguments: this.props.activeReadArguments
});

Expand Down
29 changes: 28 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,35 @@ export function createAppVscodeContext(context: Omit<WebviewContext, 'webviewSec
return createVscodeContext({ ...context, webviewSection: 'app', preventDefaultContextMenuItems: true });
}

export function createDataVscodeContext(startAddress: BigInt, endAddress: BigInt): VscodeContext {
return createVscodeContext({
memoryData: {
startAddress,
endAddress
}
});
}

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

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 value.toString(16);
}
return value;
}

0 comments on commit c111b49

Please sign in to comment.