Skip to content

Commit

Permalink
Merge commit '122061523a761cd551e928f7a1aadd12ddf89afd' into planger/…
Browse files Browse the repository at this point in the history
…issues/77
  • Loading branch information
planger committed Jun 6, 2024
2 parents 4c2f098 + 1220615 commit 4230b54
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
"type": "number",
"default": 500,
"minimum": 500,
"markdownDescription": "Controls the delay in milliseconds after which a Memory Inspector is refrehsed automatically. Only applies when `#memory-inspector.periodicRefresh#` is enabled."
"markdownDescription": "Controls the delay in milliseconds after which a Memory Inspector is refreshed automatically. Only applies when `#memory-inspector.periodicRefresh#` is enabled."
},
"memory-inspector.groupings.bytesPerMAU": {
"type": "number",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/common/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import type { DebugProtocol } from '@vscode/debugprotocol';
import type { NotificationType, RequestType } from 'vscode-messenger-common';
import { URI } from 'vscode-uri';
import { VariablesView } from '../plugin/external-views';
import { DebugRequestTypes } from './debug-requests';
import { VariablesView } from './external-views';
import type { VariableRange, WrittenMemory } from './memory-range';
import { MemoryViewSettings } from './webview-configuration';
import { WebviewContext } from './webview-context';
Expand Down
3 changes: 3 additions & 0 deletions src/common/webview-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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 @@ -26,6 +27,8 @@ export interface WebviewContext {
showVariablesColumn: boolean,
showRadixPrefix: boolean,
hasDebuggerDefaults?: boolean,
endianness: Endianness,
bytesPerMau: number,
activeReadArguments: Required<ReadMemoryArguments>
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugin/memory-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import MemoryMap from 'nrf-intel-hex';
import * as vscode from 'vscode';
import { URI, Utils } from 'vscode-uri';
import { isVariablesContext } from '../common/external-views';
import { IntelHEX } from '../common/intel-hex';
import * as manifest from '../common/manifest';
import {
Expand All @@ -26,7 +27,6 @@ import {
import { toHexStringWithRadixMarker } from '../common/memory-range';
import { ApplyMemoryArguments, ApplyMemoryResult, MemoryOptions, StoreMemoryArguments } from '../common/messaging';
import { isWebviewContext } from '../common/webview-context';
import { isVariablesContext } from './external-views';
import { MemoryProvider } from './memory-provider';

export const StoreCommandType = `${manifest.PACKAGE_NAME}.store-file`;
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/memory-webview-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import * as vscode from 'vscode';
import { Messenger } from 'vscode-messenger';
import { WebviewIdMessageParticipant } from 'vscode-messenger-common';
import { isVariablesContext } from '../common/external-views';
import * as manifest from '../common/manifest';
import { VariableRange } from '../common/memory-range';
import {
Expand Down Expand Up @@ -46,7 +47,6 @@ import {
import { MemoryDisplaySettings, MemoryDisplaySettingsContribution, MemoryViewSettings, ScrollingBehavior } from '../common/webview-configuration';
import { getVisibleColumns, isWebviewVariableContext, WebviewContext } from '../common/webview-context';
import { AddressPaddingOptions } from '../webview/utils/view-types';
import { isVariablesContext } from './external-views';
import { outputChannelLogger } from './logger';
import { MemoryProvider } from './memory-provider';
import { ApplyCommandType, StoreCommandType } from './memory-storage';
Expand Down Expand Up @@ -296,8 +296,8 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
const sessionId = session?.id;
return {
sessionId,
canRead: !!this.sessionTracker.hasDebugCapabilitiy(session, 'supportsReadMemoryRequest'),
canWrite: !!this.sessionTracker.hasDebugCapabilitiy(session, 'supportsWriteMemoryRequest'),
canRead: !!this.sessionTracker.hasDebugCapability(session, 'supportsReadMemoryRequest'),
canWrite: !!this.sessionTracker.hasDebugCapability(session, 'supportsWriteMemoryRequest'),
stopped: this.sessionTracker.isStopped(session)
};
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugin/session-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,23 @@ export class SessionTracker implements vscode.DebugAdapterTrackerFactory {
return !!session && !!this.sessionInfo(session).stopped;
}

hasDebugCapabilitiy(session = this.activeSession, capability: DebugCapability): boolean {
hasDebugCapability(session = this.activeSession, capability: DebugCapability): boolean {
return !!session && !!this.sessionInfo(session).debugCapabilities?.[capability];
}

assertDebugCapability(session = this.assertActiveSession(), capability: DebugCapability, action: string = 'execute action'): vscode.DebugSession {
if (!this.hasDebugCapabilitiy(session, capability)) {
if (!this.hasDebugCapability(session, capability)) {
throw new Error(`Cannot ${action}. Session does not have capability '${capability}'.`);
}
return session;
}

hasClientCapabilitiy(session: vscode.DebugSession | undefined, capability: ClientCapability): boolean {
hasClientCapability(session: vscode.DebugSession | undefined, capability: ClientCapability): boolean {
return !!session && !!this.sessionInfo(session).clientCapabilities?.[capability];
}

assertClientCapability(session = this.assertActiveSession(), capability: ClientCapability, action: string = 'execute action'): vscode.DebugSession {
if (!this.hasClientCapabilitiy(session, capability)) {
if (!this.hasClientCapability(session, capability)) {
throw new Error(`Cannot ${action}. Client does not have capability '${capability}'.`);
}
return session;
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
11 changes: 7 additions & 4 deletions src/webview/components/memory-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ 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, hasDebuggerDefaults } = this.props;
return createAppVscodeContext({
messageParticipant: this.props.messageParticipant,
showRadixPrefix: this.props.showRadixPrefix,
messageParticipant,
showRadixPrefix,
showAsciiColumn: visibleColumns.includes(manifest.CONFIG_SHOW_ASCII_COLUMN),
showVariablesColumn: visibleColumns.includes(manifest.CONFIG_SHOW_VARIABLES_COLUMN),
activeReadArguments: this.props.activeReadArguments,
hasDebuggerDefaults: this.props.hasDebuggerDefaults,
activeReadArguments,
hasDebuggerDefaults,
endianness,
bytesPerMau,
});

}
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 @@ -64,8 +64,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 4230b54

Please sign in to comment.