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

Allow inline editing of values #26

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
Expand Down
16 changes: 16 additions & 0 deletions .vscode/memory-inspector.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Copyright": {
"prefix": [
"header",
"copyright"
],
"body": "/********************************************************************************\n * Copyright (C) $CURRENT_YEAR ${YourCompany} and others.\n *\n * This program and the accompanying materials are made available under the\n * terms of the MIT License as outlined in the LICENSE File\n ********************************************************************************/\n\n$0",
"description": "Adds the copyright...",
"scope": "css,javascript,javascriptreact,typescript,typescriptreact"
},
"Import VSCode": {
"prefix": "codeimport",
"body": "import * as vscode from 'vscode';",
"scope": "typescript,javascript"
}
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// If one would like to add/remove/modify user preferences without modifying the content of the
// workspace settings file, then one would need to modify the `settings.json` under here:
// - Windows: %APPDATA%\Code\User\settings.json
// - Linux: $HOME/.config/Code/User/settings.json
// - Mac: $HOME/Library/Application Support/Code/User/settings.json
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
}
48 changes: 47 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,40 @@
"serve": "serve --cors -p 9000"
},
"dependencies": {
"@floating-ui/react": "^0.26.17",
"@vscode/codicons": "0.0.20",
"@vscode/webview-ui-toolkit": "^1.4.0",
"jszip": "^3.10.1",
"node-fetch": "^2.6.7",
"primeflex": "^3.3.1",
"primereact": "^10.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.1",
"remark-gfm": "^4.0.0",
"vscode-messenger": "^0.4.5",
"vscode-messenger-common": "^0.4.5",
"vscode-messenger-webview": "^0.4.5",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@types/node": "^12.20.0",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@types/vscode": "^1.63.2",
"@types/vscode-webview": "^1.57.0",
"@types/xml2js": "^0.4.9",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.49.0",
"@vscode/debugprotocol": "^1.59.0",
"@vscode/vsce": "^2.17.0",
"buffer": "^6.0.3",
"css-loader": "^6.9.0",
"eslint": "^8.33.0",
"path-browserify": "1.0.1",
"serve": "^14.0.1",
"stream-browserify": "^3.0.0",
"style-loader": "^3.3.4",
"timers-browserify": "^2.0.12",
"ts-loader": "^9.2.6",
"typescript": "^4.9.4",
Expand All @@ -68,6 +85,18 @@
"id": "peripheral-inspector.svd",
"name": "Peripherals",
"when": "peripheral-inspector.svd.hasData"
},
{
"type": "webview",
"id": "peripheral-inspector.peripheral-tree",
"name": "Peripherals Tree",
"when": "peripheral-inspector.svd.hasData"
},
{
"type": "webview",
"id": "peripheral-inspector.peripheral-treetable",
"name": "Peripherals Tree-table",
"when": "peripheral-inspector.svd.hasData"
}
]
},
Expand Down Expand Up @@ -106,6 +135,11 @@
"command": "peripheral-inspector.svd.refreshAll",
"title": "Refresh All",
"icon": "$(refresh)"
},
{
"command": "peripheral-inspector.svd.collapseAll",
"title": "Collapse All",
"icon": "$(collapse-all)"
}
],
"menus": {
Expand Down Expand Up @@ -168,7 +202,12 @@
"view/title": [
{
"command": "peripheral-inspector.svd.refreshAll",
"when": "view == peripheral-inspector.svd && debugState == stopped",
"when": "(view == peripheral-inspector.svd || view == peripheral-inspector.peripheral-tree || view == peripheral-inspector.peripheral-treetable) && debugState == stopped",
"group": "navigation"
},
{
"command": "peripheral-inspector.svd.collapseAll",
"when": "(view == peripheral-inspector.peripheral-tree || view == peripheral-inspector.peripheral-treetable) && debugState == stopped",
"group": "navigation"
}
],
Expand Down Expand Up @@ -243,6 +282,13 @@
"when": "view == peripheral-inspector.svd",
"group": "navigation"
}
],
"webview/context": [
{
"command": "peripheral-inspector.svd.setFormat",
"when": "(webviewId == peripheral-inspector.peripheral-tree || webviewId == peripheral-inspector.peripheral-treetable) && webviewSection == tree-item",
"group": "navigation"
}
]
},
"configuration": {
Expand Down
33 changes: 0 additions & 33 deletions src/browser/extension.ts

This file was deleted.

47 changes: 30 additions & 17 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@
********************************************************************************/

import * as vscode from 'vscode';
import * as manifest from './manifest';
import { PeripheralBaseNode } from './views/nodes/basenode';
import { PeripheralTreeProvider } from './views/peripheral';
import { NumberFormat } from './common';
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 Commands {
public constructor(protected peripheralProvider: PeripheralTreeProvider) {
export class PeripheralCommands {
public constructor(
protected readonly dataTracker: PeripheralDataTracker) {
}

public async activate(context: vscode.ExtensionContext): Promise<void> {
context.subscriptions.push(
vscode.commands.registerCommand(`${manifest.PACKAGE_NAME}.svd.updateNode`, node => this.peripheralsUpdateNode(node)),
vscode.commands.registerCommand(`${manifest.PACKAGE_NAME}.svd.copyValue`, node => this.peripheralsCopyValue(node)),
vscode.commands.registerCommand(`${manifest.PACKAGE_NAME}.svd.setFormat`, node => this.peripheralsSetFormat(node)),
vscode.commands.registerCommand(`${manifest.PACKAGE_NAME}.svd.forceRefresh`, node => this.peripheralsForceRefresh(node)),
vscode.commands.registerCommand(`${manifest.PACKAGE_NAME}.svd.pin`, node => this.peripheralsTogglePin(node)),
vscode.commands.registerCommand(`${manifest.PACKAGE_NAME}.svd.unpin`, node => this.peripheralsTogglePin(node)),
vscode.commands.registerCommand(`${manifest.PACKAGE_NAME}.svd.refreshAll`, () => this.peripheralsForceRefresh()),
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.REFRESH_ALL_COMMAND.commandId, () => this.peripheralsForceRefresh()),
vscode.commands.registerCommand(Commands.COLLAPSE_ALL_COMMAND.commandId, () => this.collapseAll()),
);
}

Expand All @@ -45,7 +48,11 @@ export class Commands {
}
}

private async peripheralsSetFormat(node: PeripheralBaseNode): Promise<void> {
private collapseAll(): void {
this.dataTracker.collapseAll();
}

private async peripheralsSetFormat(context: PeripheralBaseNode | CTDTreeWebviewContext): Promise<void> {
const result = await vscode.window.showQuickPick([
{ label: 'Auto', description: 'Automatically choose format (Inherits from parent)', value: NumberFormat.Auto },
{ label: 'Hex', description: 'Format value in hexadecimal', value: NumberFormat.Hexadecimal },
Expand All @@ -56,8 +63,15 @@ export class Commands {
return;
}

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

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

private async peripheralsForceRefresh(node?: PeripheralBaseNode): Promise<void> {
Expand All @@ -67,12 +81,11 @@ export class Commands {
await p.updateData();
}
} else {
this.peripheralProvider.updateData();
return this.dataTracker.updateData();
}
}

private peripheralsTogglePin(node: PeripheralBaseNode): void {
this.peripheralProvider.togglePinPeripheral(node);
this.peripheralProvider.refresh();
this.dataTracker.togglePin(node);
}
}
18 changes: 17 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* terms of the MIT License as outlined in the LICENSE File
********************************************************************************/


export enum NumberFormat {
Auto = 0,
Hexadecimal,
Expand Down Expand Up @@ -54,5 +55,20 @@ export function toStringDecHexOctBin(val: number/* should be an integer*/): stri
str = str.slice(0, -8);
}
ret += `\nbin: ${tmp}`;
return ret ;
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>
28 changes: 28 additions & 0 deletions src/components/tooltip/tooltip.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/********************************************************************************
* 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
********************************************************************************/

.tooltip {
background: var(--vscode-editorHoverWidget-background);
border: 1px solid var(--vscode-editorHoverWidget-border);
border-radius: 3px;
box-shadow: 0 2px 8px var(--vscode-widget-shadow);
max-width: 700px;
max-height: 375px;
padding: 0;
}

.tooltip .tooltip-content {
background: var(--vscode-editorHoverWidget-background);
color: var(--vscode-editorHoverWidget-foreground);
font-size: 12px;
padding: 2px 8px;
max-width: var(--vscode-hover-maxWidth, 500px);
word-wrap: break-word;
white-space: unset;
display: block;
flex-direction: column;
}
Loading
Loading