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 1 commit
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getTspClientUrl, getTraceServerUrl } from '../utils/backend-tsp-client-
import { TraceServerConnectionStatusService } from '../utils/trace-server-status';
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 { signalManager } from 'traceviewer-base/lib/signals/signal-manager';
import { VSCODE_MESSAGES } from 'vscode-trace-common/lib/messages/vscode-message-manager';
import { MarkerSet } from 'tsp-typescript-client/lib/models/markerset';
import JSONBigConfig from 'json-bigint';
Expand Down Expand Up @@ -219,10 +219,10 @@ export class TraceViewerPanel {
this.dispose();
TraceViewerPanel.activePanels[name] = undefined;
if (traceUUID) {
signalManager().fireCloseTraceViewerTabSignal(traceUUID);
signalManager().emit('CLOSE_TRACEVIEWERTAB', traceUUID);
}
if (isActivePanel) {
signalManager().fireExperimentSelectedSignal(undefined);
signalManager().emit('EXPERIMENT_SELECTED', undefined);
}
return this._disposables;
});
Expand All @@ -234,7 +234,7 @@ export class TraceViewerPanel {
if (this._experiment) {
// tabActivatedSignal will select the experiment in the opened-traces view
// which will then update available-views view
signalManager().fireTraceViewerTabActivatedSignal(this._experiment);
signalManager().emit('TRACEVIEWERTAB_ACTIVATED', this._experiment);
}
}
});
Expand Down Expand Up @@ -276,7 +276,8 @@ export class TraceViewerPanel {
return;
case VSCODE_MESSAGES.UPDATE_PROPERTIES:
if (message.data?.properties) {
signalManager().fireItemPropertiesSignalUpdated(
signalManager().emit(
'ITEM_PROPERTIES_UPDATED',
new ItemPropertiesSignalPayload(
message.data.properties,
message.data.experimentUUID,
Expand Down Expand Up @@ -328,22 +329,22 @@ export class TraceViewerPanel {
}
return;
case VSCODE_MESSAGES.VIEW_RANGE_UPDATED:
signalManager().fireViewRangeUpdated(JSONBig.parse(message.data));
signalManager().emit('VIEW_RANGE_UPDATED', JSONBig.parse(message.data));
break;
case VSCODE_MESSAGES.SELECTION_RANGE_UPDATED:
signalManager().fireSelectionRangeUpdated(JSONBig.parse(message.data));
signalManager().emit('SELECTION_RANGE_UPDATED', JSONBig.parse(message.data));
break;
case VSCODE_MESSAGES.EXPERIMENT_UPDATED:
const experiment = convertSignalExperiment(JSONBig.parse(message.data));
signalManager().fireExperimentUpdatedSignal(experiment);
signalManager().emit('EXPERIMENT_UPDATED', experiment);
break;
}
},
undefined,
this._disposables
);
signalManager().on(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected);
signalManager().on(Signals.REQUEST_SELECTION_RANGE_CHANGE, this._onRequestSelectionRangeChange);
signalManager().on('EXPERIMENT_SELECTED', this._onExperimentSelected);
signalManager().on('REQUEST_SELECTION_RANGE_CHANGE', this._onRequestSelectionRangeChange);
}

public doRefactor(): void {
Expand All @@ -364,8 +365,8 @@ export class TraceViewerPanel {
x.dispose();
}
}
signalManager().off(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected);
signalManager().off(Signals.REQUEST_SELECTION_RANGE_CHANGE, this._onRequestSelectionRangeChange);
signalManager().off('EXPERIMENT_SELECTED', this._onExperimentSelected);
signalManager().off('REQUEST_SELECTION_RANGE_CHANGE', this._onRequestSelectionRangeChange);
}

protected doHandleExperimentSelectedSignal(experiment: Experiment | undefined): void {
Expand All @@ -376,7 +377,7 @@ export class TraceViewerPanel {
}

protected doHandleExperimentUpdatedSignal(experiment: Experiment): void {
signalManager().fireExperimentUpdatedSignal(experiment);
signalManager().emit('EXPERIMENT_UPDATED', experiment);
}

protected doHandleRequestSelectionRangeChange(payload: TimeRangeUpdatePayload): void {
Expand All @@ -389,8 +390,8 @@ export class TraceViewerPanel {
this._experiment = experiment;
const wrapper: string = JSONBig.stringify(experiment);
this._panel.webview.postMessage({ command: VSCODE_MESSAGES.SET_EXPERIMENT, data: wrapper });
signalManager().fireExperimentOpenedSignal(experiment);
signalManager().fireTraceViewerTabActivatedSignal(experiment);
signalManager().emit('EXPERIMENT_OPENED', experiment);
signalManager().emit('TRACEVIEWERTAB_ACTIVATED', experiment);
}

addOutput(descriptor: OutputDescriptor): void {
Expand Down
Loading
Loading