Skip to content

Commit

Permalink
Fix bigint support in messages sent between webviews and vscode
Browse files Browse the repository at this point in the history
TODO: JSONBig.parse() doesn't create bigint if numbers are small. This
has to be addressed when deserializing messages. Re-use the normalizer
of the tsp-typescript-client to do that.

The following branch in the tps-typescript-client is introducing an
utility class and, if accepted, it can be used to solve the
deserialization issue:

eclipse-cdt-cloud/tsp-typescript-client#56

Contributes to fixing eclipse-cdt-cloud#35

Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
bhufmann committed Sep 23, 2022
1 parent 1da10e7 commit f17d5da
Show file tree
Hide file tree
Showing 10 changed files with 2,180 additions and 1,585 deletions.
2 changes: 2 additions & 0 deletions vscode-trace-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"ag-grid-community": "^20.2.0",
"ag-grid-react": "^20.2.0",
"chart.js": "^2.8.0",
"json-bigint": "sidorares/json-bigint#2c0a5f896d7888e68e5f4ae3c7ea5cd42fd54473",
"lodash": "^4.17.15",
"terser": "4.8.1",
"traceviewer-base": "next",
Expand All @@ -110,6 +111,7 @@
},
"devDependencies": {
"@types/jest": "^23.3.13",
"@types/json-bigint": "^1.0.1",
"@types/node": "^10.1.2",
"@types/vscode": "^1.52.0",
"@typescript-eslint/eslint-plugin": "^3.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { getTspClientUrl, getTraceServerUrl } from '../../utils/tspClient';
import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import { OpenedTracesUpdatedSignalPayload } from 'traceviewer-base/lib/signals/opened-traces-updated-signal-payload';
import JSONBigConfig from 'json-bigint';

const JSONBig = JSONBigConfig({
useNativeBigInt: true,
});

export class TraceExplorerOpenedTracesViewProvider implements vscode.WebviewViewProvider {

Expand Down Expand Up @@ -56,25 +61,30 @@ export class TraceExplorerOpenedTracesViewProvider implements vscode.WebviewView
webviewView.webview.postMessage({command: 'set-tspClient', data: getTspClientUrl()});
return;
case 'reopenTrace':
if (message.data && message.data.experiment) {
const panel = TraceViewerPanel.createOrShow(this._extensionUri, message.data.experiment.name);
panel.setExperiment(message.data.experiment);
if (message.data && message.data.wrapper) {
// FIXME: JSONBig.parse() create bigint if numbers are small
const experiment = JSONBig.parse(message.data.wrapper);
const panel = TraceViewerPanel.createOrShow(this._extensionUri, experiment.name);
panel.setExperiment(experiment);
}
return;
case 'closeTrace':
if (message.data && message.data.experiment) {
TraceViewerPanel.disposePanel(this._extensionUri, message.data.experiment.name);
if (message.data && message.data.wrapper) {
// FIXME: JSONBig.parse() create bigint if numbers are small
TraceViewerPanel.disposePanel(this._extensionUri, JSONBig.parse(message.data.wrapper).name);
}
return;
case 'deleteTrace':
if (message.data && message.data.experiment) {
if (message.data && message.data.wrapper) {
// FIXME: JSONBig.parse() create bigint if numbers are small
// just remove the panel here
TraceViewerPanel.disposePanel(this._extensionUri, message.data.experiment.name);
TraceViewerPanel.disposePanel(this._extensionUri, JSONBig.parse(message.data.wrapper).name);
}
return;
case 'experimentSelected': {
if (message.data && message.data.experiment) {
signalManager().fireExperimentSelectedSignal(message.data.experiment);
if (message.data && message.data.wrapper) {
// FIXME: JSONBig.parse() create bigint if numbers are small
signalManager().fireExperimentSelectedSignal(JSONBig.parse(message.data.wrapper));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-mana
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import { TraceViewerPanel } from '../../trace-viewer-panel/trace-viewer-webview-panel';
import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor';
import JSONBigConfig from 'json-bigint';

const JSONBig = JSONBigConfig({
useNativeBigInt: true,
});

export class TraceExplorerAvailableViewsProvider implements vscode.WebviewViewProvider {

Expand Down Expand Up @@ -46,19 +51,22 @@ export class TraceExplorerAvailableViewsProvider implements vscode.WebviewViewPr
return;
case 'outputAdded':
if (message.data && message.data.descriptor) {
const descriptor: OutputDescriptor = message.data.descriptor as OutputDescriptor;
// FIXME: JSONBig.parse() create bigint if numbers are small
const descriptor = JSONBig.parse(message.data.descriptor) as OutputDescriptor;
// TODO: Don't use static current panel, i.e. find better design to add output...

TraceViewerPanel.addOutputToCurrent(descriptor);
// const panel = TraceViewerPanel.createOrShow(this._extensionUri, message.data.experiment.name);
// panel.setExperiment(message.data.experiment);
}
return;
case 'experimentSelected': {
if (message.data && message.data.experiment) {
if (message.data && message.data.wrapper) {
try {
// Avoid endless forwarding of signal
this._selectionOngoing = true;
signalManager().fireExperimentSelectedSignal(message.data.experiment);
// FIXME: JSONBig.parse() create bigint if numbers are small
signalManager().fireExperimentSelectedSignal(JSONBig.parse(message.data.wrapper));
} finally {
this._selectionOngoing = false;
}
Expand All @@ -75,7 +83,8 @@ export class TraceExplorerAvailableViewsProvider implements vscode.WebviewViewPr

protected doHandleExperimentSelectedSignal(experiment: Experiment | undefined): void {
if (!this._selectionOngoing && this._view) {
this._view.webview.postMessage({command: 'experimentSelected', data: experiment});
const wrapper: string = JSONBig.stringify(experiment);
this._view.webview.postMessage({command: 'experimentSelected', data: wrapper});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { getTspClientUrl, getTraceServerUrl } from '../utils/tspClient';
import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor';
import { handleStatusMessage, handleRemoveMessage, setStatusFromPanel } from '../common/trace-message';
import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager';
import JSONBigConfig from 'json-bigint';

const JSONBig = JSONBigConfig({
useNativeBigInt: true,
});

// TODO: manage mutiple panels (currently just a hack around, need to be fixed)

Expand Down Expand Up @@ -115,7 +120,8 @@ export class TraceViewerPanel {
// Post the tspTypescriptClient
this._panel.webview.postMessage({command: 'set-tspClient', data: getTspClientUrl()});
if (this._experiment) {
this._panel.webview.postMessage({command: 'set-experiment', data: this._experiment});
const wrapper: string = JSONBig.stringify(this._experiment);
this._panel.webview.postMessage({command: 'set-experiment', data: wrapper});
}
return;
}
Expand Down Expand Up @@ -152,11 +158,13 @@ export class TraceViewerPanel {

setExperiment(experiment: Experiment): void {
this._experiment = experiment;
this._panel.webview.postMessage({command: 'set-experiment', data: experiment});
const wrapper: string = JSONBig.stringify(experiment);
this._panel.webview.postMessage({command: 'set-experiment', data: wrapper});
}

addOutput(descriptor: OutputDescriptor): void {
this._panel.webview.postMessage({command: 'add-output', data: descriptor});
const wrapper: string = JSONBig.stringify(descriptor);
this._panel.webview.postMessage({command: 'add-output', data: wrapper});
}

private _getHtmlForWebview() {
Expand Down
2 changes: 2 additions & 0 deletions vscode-trace-webviews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@fortawesome/fontawesome-svg-core": "^1.2.17",
"@fortawesome/free-solid-svg-icons": "^5.8.1",
"@fortawesome/react-fontawesome": "^0.1.4",
"json-bigint": "sidorares/json-bigint#2c0a5f896d7888e68e5f4ae3c7ea5cd42fd54473",
"lodash": "^4.17.15",
"lodash.debounce": "^4.0.8",
"react": "^16.3.2",
Expand All @@ -30,6 +31,7 @@
},
"devDependencies": {
"@types/jest": "^23.3.13",
"@types/json-bigint": "^1.0.1",
"@types/node": "^10.1.2",
"@types/react": "^16.3.14",
"@types/react-dom": "^16.0.5",
Expand Down
24 changes: 19 additions & 5 deletions vscode-trace-webviews/src/common/vscode-message-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as Messages from 'traceviewer-base/lib/message-manager';
import { OutputAddedSignalPayload } from 'traceviewer-base/lib/signals/output-added-signal-payload';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import JSONBigConfig from 'json-bigint';

const JSONBig = JSONBigConfig({
useNativeBigInt: true,
});

/* eslint-disable @typescript-eslint/no-explicit-any */
interface vscode {
Expand Down Expand Up @@ -39,22 +44,31 @@ export class VsCodeMessageManager extends Messages.MessageManager {
* Trace Explorer React APP
*************************************************************************/
reOpenTrace(experiment: Experiment): void {
vscode.postMessage({command: 'reopenTrace', data: {experiment}});
const wrapper: string = JSONBig.stringify(experiment);
vscode.postMessage({command: 'reopenTrace', data: {wrapper}});
}

closeTrace(experiment: Experiment): void {
vscode.postMessage({command: 'closeTrace', data: {experiment}});
const wrapper: string = JSONBig.stringify(experiment);
vscode.postMessage({command: 'closeTrace', data: {wrapper}});
}

deleteTrace(experiment: Experiment): void {
vscode.postMessage({command: 'deleteTrace', data: {experiment}});
const wrapper: string = JSONBig.stringify(experiment);
vscode.postMessage({command: 'deleteTrace', data: {wrapper}});
}

experimentSelected(experiment: Experiment | undefined): void {
vscode.postMessage({command: 'experimentSelected', data: {experiment}});
let wrapper = undefined;
if (experiment) {
wrapper = JSONBig.stringify(experiment);
}
vscode.postMessage({command: 'experimentSelected', data: {wrapper}});
}

outputAdded(payload: OutputAddedSignalPayload): void {
vscode.postMessage({command: 'outputAdded', data: {experiment: payload.getExperiment(), descriptor: payload.getOutputDescriptor() }});
const expWrapper = JSONBig.stringify(payload.getExperiment());
const descWrapper = JSONBig.stringify(payload.getOutputDescriptor());
vscode.postMessage({command: 'outputAdded', data: {data: expWrapper, descriptor: descWrapper }});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TraceExplorerOpenedTraces extends React.Component<{}, OpenedTracesAppState
<Menu id={MENU_ID} theme={'dark'} animation={'fade'}>
<Item id="open-id" onClick={this.handleItemClick}>Open Trace</Item>
<Item id="close-id" onClick={this.handleItemClick}>Close Trace</Item>
<Item id="delete-id" onClick={this.handleItemClick}>Delete Trace</Item>
<Item id="remove-id" onClick={this.handleItemClick}>Remove Trace</Item>
</Menu>
</>
);
Expand All @@ -122,10 +122,10 @@ class TraceExplorerOpenedTraces extends React.Component<{}, OpenedTracesAppState
case 'close-id':
this._signalHandler.closeTrace(args.props.experiment as Experiment);
return;
case 'delete-id':
case 'remove-id':
this._signalHandler.deleteTrace(args.props.experiment as Experiment);
if (this._experimentManager) {
this._experimentManager.closeExperiment((args.props.experiment as Experiment).UUID);
this._experimentManager.deleteExperiment((args.props.experiment as Experiment).UUID);
}

return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/* eslint-disable @typescript-eslint/ban-types */
import * as React from 'react';
import { OutputAddedSignalPayload } from 'traceviewer-base/lib/signals/output-added-signal-payload';
import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager';
import { ITspClientProvider } from 'traceviewer-base/lib/tsp-client-provider';
import { ReactAvailableViewsWidget } from 'traceviewer-react-components/lib/trace-explorer/trace-explorer-views-widget';
import * as React from 'react';
import 'traceviewer-react-components/style/trace-explorer.css';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import { TspClientProvider } from '../../common/tsp-client-provider-impl';
import { VsCodeMessageManager } from '../../common/vscode-message-manager';
import '../../style/trace-viewer.css';
import 'traceviewer-react-components/style/trace-explorer.css';
import '../../style/react-contextify.css';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import '../../style/trace-viewer.css';
import JSONBigConfig from 'json-bigint';

const JSONBig = JSONBigConfig({
useNativeBigInt: true,
});

interface AvailableViewsAppState {
tspClientProvider: ITspClientProvider | undefined;
Expand Down Expand Up @@ -39,7 +44,7 @@ class TraceExplorerViewsWidget extends React.Component<{}, AvailableViewsAppStat
break;
case 'experimentSelected':
if (message.data) {
signalManager().fireExperimentSelectedSignal(message.data);
signalManager().fireExperimentSelectedSignal(JSONBig.parse(message.data));
}
break;
}
Expand Down
Loading

0 comments on commit f17d5da

Please sign in to comment.