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

Switch to AntD TreeTable and remove deprecated code #32

Merged
merged 12 commits into from
Dec 17, 2024
91 changes: 14 additions & 77 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
"@floating-ui/react": "^0.26.17",
"@vscode/codicons": "0.0.20",
"@vscode/webview-ui-toolkit": "^1.4.0",
"antd": "^5.22.1",
"jszip": "^3.10.1",
"node-fetch": "^2.6.7",
"throttle-debounce": "5.0.2",
"primeflex": "^3.3.1",
"primereact": "^10.8.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.1",
Expand All @@ -56,6 +57,7 @@
},
"devDependencies": {
"@types/node": "^12.20.0",
"@types/throttle-debounce": "5.0.2",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@types/vscode": "^1.63.2",
Expand Down Expand Up @@ -83,7 +85,7 @@
"debug": [
{
"type": "webview",
"id": "peripheral-inspector.peripheral-tree",
"id": "peripheral-inspector.peripheral-treetable",
"name": "Peripherals",
"when": "peripheral-inspector.svd.hasData"
}
Expand Down Expand Up @@ -191,91 +193,19 @@
"view/title": [
{
"command": "peripheral-inspector.svd.refreshAll",
"when": "view == peripheral-inspector.peripheral-tree && debugState == stopped",
"when": "view =~ /peripheral-inspector.peripheral-*/ && debugState == stopped",
"group": "navigation"
},
{
"command": "peripheral-inspector.svd.collapseAll",
"when": "view == peripheral-inspector.peripheral-tree && debugState == stopped",
"group": "navigation"
}
],
"view/item/context": [
{
"command": "peripheral-inspector.svd.updateNode",
"when": "view == peripheral-inspector.svd && viewItem == field",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.updateNode",
"when": "view == peripheral-inspector.svd && viewItem == fieldWO",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.updateNode",
"when": "view == peripheral-inspector.svd && viewItem == registerRW",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.copyValue",
"when": "view == peripheral-inspector.svd && viewItem == field",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.copyValue",
"when": "view == peripheral-inspector.svd && viewItem == fieldRO",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.copyValue",
"when": "view == peripheral-inspector.svd && viewItem == registerRW",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.copyValue",
"when": "view == peripheral-inspector.svd && viewItem == registerRO",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.forceRefresh",
"when": "view == peripheral-inspector.svd && viewItem == registerRW",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.forceRefresh",
"when": "view == peripheral-inspector.svd && viewItem == register",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.forceRefresh",
"when": "view == peripheral-inspector.svd && viewItem == registerRO",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.forceRefresh",
"when": "view == peripheral-inspector.svd && viewItem =~ /peripheral.*/",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.pin",
"when": "view == peripheral-inspector.svd && viewItem == peripheral",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.unpin",
"when": "view == peripheral-inspector.svd && viewItem == peripheral.pinned",
"group": "inline"
},
{
"command": "peripheral-inspector.svd.setFormat",
"when": "view == peripheral-inspector.svd",
"when": "view =~ /peripheral-inspector.peripheral-*/ && debugState == stopped",
"group": "navigation"
}
],
"webview/context": [
{
"command": "peripheral-inspector.svd.setFormat",
"when": "webviewId == peripheral-inspector.peripheral-tree && webviewSection == tree-item",
"when": "webviewId =~ /peripheral-inspector.peripheral-*/ && webviewSection == tree-item",
"group": "navigation"
}
]
Expand Down Expand Up @@ -315,6 +245,13 @@
"type": "boolean",
"default": true,
"description": "Save layout of peripheral view between sessions"
},
"peripheral-inspector.ignorePeripherals": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of case insensitive peripherals names to ignore"
martin-fleck-at marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
********************************************************************************/

import * as vscode from 'vscode';
import { NumberFormat } from './common';
import { NumberFormat } from './common/format';
import { TreeNotificationContext } from './common/notification';
import { PERIPHERAL_ID_SEP } from './common/peripheral-dto';
import { CTDTreeWebviewContext } from './components/tree/types';
import { Commands } from './manifest';
import { PeripheralBaseNode } from './plugin/peripheral/nodes';
import { PeripheralDataTracker } from './plugin/peripheral/tree/peripheral-data-tracker';
import { Commands } from './manifest';
import { CTDTreeWebviewContext } from './components/tree/types';

export class PeripheralCommands {
public constructor(
Expand All @@ -19,35 +21,33 @@ export class PeripheralCommands {

public async activate(context: vscode.ExtensionContext): Promise<void> {
context.subscriptions.push(
vscode.commands.registerCommand(Commands.UPDATE_NODE_COMMAND.commandId, node => this.peripheralsUpdateNode(node)),
vscode.commands.registerCommand(Commands.COPY_VALUE_COMMAND.commandId, node => this.peripheralsCopyValue(node)),
vscode.commands.registerCommand(Commands.SET_FORMAT_COMMAND.commandId, node => this.peripheralsSetFormat(node)),
vscode.commands.registerCommand(Commands.FORCE_REFRESH_COMMAND.commandId, node => this.peripheralsForceRefresh(node)),
vscode.commands.registerCommand(Commands.PIN_COMMAND.commandId, node => this.peripheralsTogglePin(node)),
vscode.commands.registerCommand(Commands.UNPIN_COMMAND.commandId, node => this.peripheralsTogglePin(node)),
vscode.commands.registerCommand(Commands.UPDATE_NODE_COMMAND.commandId, (node, value) => this.peripheralsUpdateNode(node, value)),
vscode.commands.registerCommand(Commands.COPY_VALUE_COMMAND.commandId, (node, value) => this.peripheralsCopyValue(node, value)),
vscode.commands.registerCommand(Commands.SET_FORMAT_COMMAND.commandId, (node) => this.peripheralsSetFormat(node)),
vscode.commands.registerCommand(Commands.FORCE_REFRESH_COMMAND.commandId, (node) => this.peripheralsForceRefresh(node)),
vscode.commands.registerCommand(Commands.PIN_COMMAND.commandId, (node, _, context) => this.peripheralsTogglePin(node, context)),
vscode.commands.registerCommand(Commands.UNPIN_COMMAND.commandId, (node, _, context) => this.peripheralsTogglePin(node, context)),
vscode.commands.registerCommand(Commands.REFRESH_ALL_COMMAND.commandId, () => this.peripheralsForceRefresh()),
vscode.commands.registerCommand(Commands.COLLAPSE_ALL_COMMAND.commandId, () => this.collapseAll()),
);
}

private async peripheralsUpdateNode(node: PeripheralBaseNode): Promise<void> {
private async peripheralsUpdateNode(node: PeripheralBaseNode, value?: unknown): Promise<void> {
try {
const result = await node.performUpdate();
const result = await node.performUpdate(value);
if (result) {
await this.peripheralsForceRefresh();
} else {
this.dataTracker.refresh();
// Update the tree view
this.dataTracker.fireOnDidChange();
}

} catch (error) {
vscode.debug.activeDebugConsole.appendLine(`Unable to update value: ${(error as Error).message}`);
}
}

private peripheralsCopyValue(node: PeripheralBaseNode): void {
const cv = node.getCopyValue();
if (cv) {
vscode.env.clipboard.writeText(cv);
private peripheralsCopyValue(_node: PeripheralBaseNode, value?: string): void {
if (value) {
vscode.env.clipboard.writeText(value);
}
}

Expand All @@ -68,13 +68,13 @@ export class PeripheralCommands {

let node: PeripheralBaseNode;
if (CTDTreeWebviewContext.is(context)) {
node = this.dataTracker.getNodeByPath(context.cdtTreeItemPath);
node = this.dataTracker.getNodeByPath(context.cdtTreeItemId.split(PERIPHERAL_ID_SEP));
} else {
node = context;
}

node.format = result.value;
this.dataTracker.refresh();
this.dataTracker.fireOnDidChange();
}

private async peripheralsForceRefresh(node?: PeripheralBaseNode): Promise<void> {
Expand All @@ -84,13 +84,13 @@ export class PeripheralCommands {
await p.updateData();
}

this.dataTracker.refresh();
this.dataTracker.fireOnDidChange();
} else {
await this.dataTracker.updateData();
}
}

private peripheralsTogglePin(node: PeripheralBaseNode): void {
this.dataTracker.togglePin(node);
private peripheralsTogglePin(node: PeripheralBaseNode, context?: TreeNotificationContext): void {
this.dataTracker.togglePin(node, context);
}
}
31 changes: 11 additions & 20 deletions src/common.ts → src/common/format.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/********************************************************************************
* Copyright (C) 2023 Marcel Ball, Arm Limited and others.
* Copyright (C) 2023-2024 Marcel Ball, Arm Limited and others.
*
* This program and the accompanying materials are made available under the
* terms of the MIT License as outlined in the LICENSE File
********************************************************************************/

import { binaryFormat, hexFormat } from '../utils';

export enum NumberFormat {
Auto = 0,
Expand All @@ -13,11 +14,15 @@ export enum NumberFormat {
Binary
}

export interface NodeSetting {
node: string;
expanded?: boolean;
format?: NumberFormat;
pinned?: boolean;
export function formatValue(value: number, hexLength: number, format: NumberFormat): string {
switch (format) {
case NumberFormat.Decimal:
return value.toString();
case NumberFormat.Binary:
return binaryFormat(value, hexLength * 4);
default:
return hexFormat(value, hexLength, true);
}
}

export function toStringDecHexOctBin(val: number/* should be an integer*/): string {
haydar-metin marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -58,17 +63,3 @@ export function toStringDecHexOctBin(val: number/* should be an integer*/): stri
return ret;
}


export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }

export interface CommandDefinition {
commandId: string;
icon: string;
title?: string;
}

export interface VscodeContext {
'data-vscode-context': string;
}

export type MaybePromise<T> = T | Promise<T>
13 changes: 13 additions & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/********************************************************************************
* Copyright (C) 2024 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the MIT License as outlined in the LICENSE File
********************************************************************************/

export * from './format';
export * from './notification';
export * from './peripheral-sort';
export * from './peripheral-dto';
export * from './utils';
export * from './vscode';
18 changes: 18 additions & 0 deletions src/common/notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/********************************************************************************
* Copyright (C) 2024 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the MIT License as outlined in the LICENSE File
********************************************************************************/

export interface TreeNotificationContext {
/**
* If true or undefined, the tree will be resynced.
*/
resync?: boolean;
}

export interface TreeNotification<T> {
context?: TreeNotificationContext;
data: T;
}
Loading
Loading