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

Refactor for SignalManager changes #277

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion vscode-trace-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"dependencies": {
"json-bigint": "sidorares/json-bigint#2c0a5f896d7888e68e5f4ae3c7ea5cd42fd54473",
"traceviewer-base": "^0.4.4",
"traceviewer-base": "^0.5.0",
"tsp-typescript-client": "^0.5.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions vscode-trace-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@
"json-bigint": "sidorares/json-bigint#2c0a5f896d7888e68e5f4ae3c7ea5cd42fd54473",
"lodash": "^4.17.15",
"terser": "4.8.1",
"traceviewer-base": "^0.4.4",
"traceviewer-react-components": "^0.4.4",
"traceviewer-base": "^0.5.0",
"traceviewer-react-components": "^0.5.0",
"vscode-trace-common": "0.3.2"
},
"devDependencies": {
Expand Down
30 changes: 25 additions & 5 deletions vscode-trace-extension/src/external-api/external-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TraceViewerPanel } from '../trace-viewer-panel/trace-viewer-webview-pan
import * as vscode from 'vscode';
import { traceExtensionWebviewManager, traceServerManager } from '../extension';
import { TraceServerContributor } from '../utils/trace-server-manager';
import { signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { SignalArgs, signalManager, Signals, SignalType } from 'traceviewer-base/lib/signals/signal-manager';
import { TraceExplorerResourceTypeHandler } from '../utils/trace-explorer-resource-type-handler';

export interface ExternalAPI {
Expand All @@ -17,8 +17,18 @@ export interface ExternalAPI {
getActiveWebviews(): vscode.WebviewView[];
onWebviewCreated(listener: (data: vscode.WebviewView) => void): void;
onWebviewPanelCreated(listener: (data: vscode.WebviewPanel) => void): void;
onSignalManagerSignal(event: string | symbol, listener: (...args: unknown[]) => void): void;
offSignalManagerSignal(event: string | symbol, listener: (...args: unknown[]) => void): void;
onSignalManagerSignal<K extends SignalType>(
event: K,
listener: (
...args: SignalArgs<Signals[K]> extends [] ? [] : [...SignalArgs<Signals[K]>]
) => void | Promise<void>
): void;
offSignalManagerSignal<K extends SignalType>(
event: K,
listener: (
...args: SignalArgs<Signals[K]> extends [] ? [] : [...SignalArgs<Signals[K]>]
) => void | Promise<void>
): void;
addTraceServerContributor(contributor: TraceServerContributor): void;
setHandleTraceResourceType(handleFiles: boolean, handleFolders: boolean): void;
}
Expand Down Expand Up @@ -75,7 +85,12 @@ export const traceExtensionAPI: ExternalAPI = {
* @param event event for which a listener should be attached
* @param listener event listener
*/
onSignalManagerSignal(event: string | symbol, listener: (...args: unknown[]) => void): void {
onSignalManagerSignal<K extends SignalType>(
event: K,
listener: (
...args: SignalArgs<Signals[K]> extends [] ? [] : [...SignalArgs<Signals[K]>]
) => void | Promise<void>
): void {
signalManager().on(event, listener);
},

Expand All @@ -85,7 +100,12 @@ export const traceExtensionAPI: ExternalAPI = {
* @param event event for which a listener should be removed
* @param listener event listener to remove
*/
offSignalManagerSignal(event: string | symbol, listener: (...args: unknown[]) => void): void {
offSignalManagerSignal<K extends SignalType>(
event: K,
listener: (
...args: SignalArgs<Signals[K]> extends [] ? [] : [...SignalArgs<Signals[K]>]
) => void | Promise<void>
): void {
signalManager().off(event, listener);
},

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import JSONBigConfig from 'json-bigint';
import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager';
import { signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -51,7 +51,7 @@ export class TraceExplorerAvailableViewsProvider extends AbstractTraceExplorerPr
data: getTspClientUrl()
});
if (this._selectedExperiment !== undefined) {
signalManager().fireExperimentSelectedSignal(this._selectedExperiment);
signalManager().emit('EXPERIMENT_SELECTED', this._selectedExperiment);
}
return;
case VSCODE_MESSAGES.OUTPUT_ADDED:
Expand All @@ -75,7 +75,7 @@ export class TraceExplorerAvailableViewsProvider extends AbstractTraceExplorerPr
} else {
this._selectedExperiment = undefined;
}
signalManager().fireExperimentSelectedSignal(this._selectedExperiment);
signalManager().emit('EXPERIMENT_SELECTED', this._selectedExperiment);
} finally {
this._selectionOngoing = false;
}
Expand All @@ -86,11 +86,11 @@ export class TraceExplorerAvailableViewsProvider extends AbstractTraceExplorerPr
this._disposables
);

signalManager().on(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected);
signalManager().on('EXPERIMENT_SELECTED', this._onExperimentSelected);
}

protected dispose() {
signalManager().off(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected);
signalManager().off('EXPERIMENT_SELECTED', this._onExperimentSelected);
super.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import JSONBigConfig from 'json-bigint';
import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager';
import { signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import * as vscode from 'vscode';
import { convertSignalExperiment } from 'vscode-trace-common/lib/signals/vscode-signal-converter';
Expand Down Expand Up @@ -51,7 +51,7 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer
// Note that the open-traces webview will send experimentSelectedSignal signal to update the
// available-views view. If the webview is not visible (e.g. it's minimized) then send the signal
// here to update the available-views view.
signalManager().fireExperimentSelectedSignal(this._selectedExperiment);
signalManager().emit('EXPERIMENT_SELECTED', this._selectedExperiment);
}
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer
if (this._selectedExperiment !== undefined) {
// tabActivatedSignal will select the experiment in the opened-traces view
// which will then update available-views view
signalManager().fireTraceViewerTabActivatedSignal(this._selectedExperiment);
signalManager().emit('TRACEVIEWERTAB_ACTIVATED', this._selectedExperiment);
}
return;
case VSCODE_MESSAGES.RE_OPEN_TRACE:
Expand All @@ -110,7 +110,7 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer
if (data && data.wrapper) {
// just remove the panel here
TraceViewerPanel.disposePanel(this._extensionUri, JSONBig.parse(data.wrapper).name);
signalManager().fireExperimentSelectedSignal(undefined);
signalManager().emit('EXPERIMENT_SELECTED', undefined);
}
return;
case VSCODE_MESSAGES.OPENED_TRACES_UPDATED:
Expand All @@ -126,22 +126,22 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer
} else {
experiment = undefined;
}
signalManager().fireExperimentSelectedSignal(experiment);
signalManager().emit('EXPERIMENT_SELECTED', experiment);
}
}
},
undefined,
this._disposables
);

signalManager().on(Signals.TRACEVIEWERTAB_ACTIVATED, this._onOpenedTracesWidgetActivated);
signalManager().on(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected);
signalManager().on(Signals.EXPERIMENT_OPENED, this._onExperimentOpened);
signalManager().on('TRACEVIEWERTAB_ACTIVATED', this._onOpenedTracesWidgetActivated);
signalManager().on('EXPERIMENT_SELECTED', this._onExperimentSelected);
signalManager().on('EXPERIMENT_OPENED', this._onExperimentOpened);
}
protected dispose() {
signalManager().off(Signals.TRACEVIEWERTAB_ACTIVATED, this._onOpenedTracesWidgetActivated);
signalManager().off(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected);
signalManager().off(Signals.EXPERIMENT_OPENED, this._onExperimentOpened);
signalManager().off('TRACEVIEWERTAB_ACTIVATED', this._onOpenedTracesWidgetActivated);
signalManager().off('EXPERIMENT_SELECTED', this._onExperimentSelected);
signalManager().off('EXPERIMENT_OPENED', this._onExperimentOpened);
super.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
***************************************************************************************/
import * as vscode from 'vscode';
import { AbstractTraceExplorerProvider } from '../abstract-trace-explorer-provider';
import { Signals, signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { VSCODE_MESSAGES } from 'vscode-trace-common/lib/messages/vscode-message-manager';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import { ItemPropertiesSignalPayload } from 'traceviewer-base/lib/signals/item-properties-signal-payload';
Expand Down Expand Up @@ -56,26 +56,23 @@ export class TraceExplorerItemPropertiesProvider extends AbstractTraceExplorerPr
}
});

signalManager().on(Signals.ITEM_PROPERTIES_UPDATED, this.handleUpdatedProperties);
signalManager().on(Signals.EXPERIMENT_SELECTED, this.handleExperimentChanged);
signalManager().on(Signals.CLOSE_TRACEVIEWERTAB, this.handleTabClosed);
signalManager().on('ITEM_PROPERTIES_UPDATED', this.handleUpdatedProperties);
signalManager().on('EXPERIMENT_SELECTED', this.handleExperimentChanged);
signalManager().on('CLOSE_TRACEVIEWERTAB', this.handleTabClosed);
return;
}

handleExperimentChanged = (exp: Experiment) => {
const props = this.propertiesMap.get(exp?.UUID);
if (props) {
this.handleUpdatedProperties(props);
} else {
const emptyPayload = new ItemPropertiesSignalPayload({});
this.handleUpdatedProperties(emptyPayload);
}
handleExperimentChanged = (exp?: Experiment) => {
const payload = exp
? this.propertiesMap.get(exp.UUID) || new ItemPropertiesSignalPayload({})
: new ItemPropertiesSignalPayload({});
this.handleUpdatedProperties(payload);
};

protected dispose(): void {
signalManager().off(Signals.ITEM_PROPERTIES_UPDATED, this.handleUpdatedProperties);
signalManager().off(Signals.EXPERIMENT_SELECTED, this.handleExperimentChanged);
signalManager().off(Signals.CLOSE_TRACEVIEWERTAB, this.handleTabClosed);
signalManager().off('ITEM_PROPERTIES_UPDATED', this.handleUpdatedProperties);
signalManager().off('EXPERIMENT_SELECTED', this.handleExperimentChanged);
signalManager().off('CLOSE_TRACEVIEWERTAB', this.handleTabClosed);
}

handleTabClosed = (expUUID: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import JSONBigConfig from 'json-bigint';
import { Signals, signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { TimeRangeUpdatePayload } from 'traceviewer-base/lib/signals/time-range-data-signal-payloads';
import { TimeRangeDataMap } from 'traceviewer-react-components/lib/components/utils/time-range-data-map';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class TraceExplorerTimeRangeDataProvider extends AbstractTraceExplorerPro

switch (command) {
case VSCODE_MESSAGES.REQUEST_SELECTION_RANGE_CHANGE:
signalManager().fireRequestSelectionRangeChange(parsedData);
signalManager().emit('REQUEST_SELECTION_RANGE_CHANGE', parsedData);
break;
}
},
Expand All @@ -56,21 +56,21 @@ export class TraceExplorerTimeRangeDataProvider extends AbstractTraceExplorerPro
}
});

signalManager().on(Signals.VIEW_RANGE_UPDATED, this.onViewRangeUpdated);
signalManager().on(Signals.SELECTION_RANGE_UPDATED, this.onSelectionRangeUpdated);
signalManager().on(Signals.EXPERIMENT_SELECTED, this.onExperimentSelected);
signalManager().on(Signals.EXPERIMENT_UPDATED, this.onExperimentUpdated);
signalManager().on(Signals.EXPERIMENT_CLOSED, this.onExperimentClosed);
signalManager().on(Signals.CLOSE_TRACEVIEWERTAB, this.onExperimentTabClosed);
signalManager().on('VIEW_RANGE_UPDATED', this.onViewRangeUpdated);
signalManager().on('SELECTION_RANGE_UPDATED', this.onSelectionRangeUpdated);
signalManager().on('EXPERIMENT_SELECTED', this.onExperimentSelected);
signalManager().on('EXPERIMENT_UPDATED', this.onExperimentUpdated);
signalManager().on('EXPERIMENT_CLOSED', this.onExperimentClosed);
signalManager().on('CLOSE_TRACEVIEWERTAB', this.onExperimentTabClosed);
}

protected dispose() {
signalManager().off(Signals.VIEW_RANGE_UPDATED, this.onViewRangeUpdated);
signalManager().off(Signals.SELECTION_RANGE_UPDATED, this.onSelectionRangeUpdated);
signalManager().off(Signals.EXPERIMENT_SELECTED, this.onExperimentSelected);
signalManager().off(Signals.EXPERIMENT_UPDATED, this.onExperimentUpdated);
signalManager().off(Signals.EXPERIMENT_CLOSED, this.onExperimentClosed);
signalManager().off(Signals.CLOSE_TRACEVIEWERTAB, this.onExperimentTabClosed);
signalManager().off('VIEW_RANGE_UPDATED', this.onViewRangeUpdated);
signalManager().off('SELECTION_RANGE_UPDATED', this.onSelectionRangeUpdated);
signalManager().off('EXPERIMENT_SELECTED', this.onExperimentSelected);
signalManager().off('EXPERIMENT_UPDATED', this.onExperimentUpdated);
signalManager().off('EXPERIMENT_CLOSED', this.onExperimentClosed);
signalManager().off('CLOSE_TRACEVIEWERTAB', this.onExperimentTabClosed);
super.dispose();
}

Expand Down
Loading
Loading