Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhances the context data of the context menu #135

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -90,6 +91,7 @@ export class EditableDataColumnRow extends React.Component<EditableDataColumnRow
style={style}
key={startAddress.toString(16)}
onDoubleClick={this.setGroupEdit}
{...createGroupVscodeContext(startAddress, toOffset(startAddress, endAddress, this.props.options.bytesPerMau * 8))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*8 looked a bit off initially. But realized later that most internal calculations are still based on bits....

>
{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 @@ -66,12 +66,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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we always be sure that bigint is only used for 64-bit handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment bigint seems to be used only for memory addresses and memory data. As BigInt is not serializable directly, my intention with this replacer was that we can pass BigInt values directly into the context without worrying about that and have a consistent formatting of those values for extenders (hexadecimal).

Alternatively, we can also limit this formatting to the specific fields we currently know to be passed into the context, which would be fine too, if you prefer.

return `0x${value.toString(16)}`;
}
return value;
}

Loading