From 1c6babd06225e96b7aa50ead6cf0a78cf66f4886 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Mon, 12 Dec 2022 17:05:29 -0500 Subject: [PATCH] Add new command open-trace-with-path to open a trace with the given path This new command takes a path to a trace directory and opens the trace in the trace viewer. The use case is we have an extension that collects traces from target hardware, when that trace collection is complete we want to open it in the UI. Adding this new command allows us to open the trace in the viewer by passing the path to the new trace. The alternative we considered was, in our extension, connecting to the trace server and issuing a tspClient.openTrace and then tspClient.createExperiment. While this does load the trace on the server, we still need a way for the UI to refresh. Rather the providing a new command to refresh the UI we propose this new command as it also saves us from duplicating all the work to interact with the tspClient. --- .../browser/trace-viewer/trace-viewer-commands.ts | 13 +++++++++++++ .../trace-viewer/trace-viewer-contribution.ts | 14 +++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/theia-extensions/viewer-prototype/src/browser/trace-viewer/trace-viewer-commands.ts b/theia-extensions/viewer-prototype/src/browser/trace-viewer/trace-viewer-commands.ts index 06c4390a8..34b880386 100644 --- a/theia-extensions/viewer-prototype/src/browser/trace-viewer/trace-viewer-commands.ts +++ b/theia-extensions/viewer-prototype/src/browser/trace-viewer/trace-viewer-commands.ts @@ -29,3 +29,16 @@ export const OpenTraceWithRootPathCommand: Command = { id: 'open-trace-with-root-path', label: 'Open Trace With Root Path' }; + +/** + * A command to open a trace in the trace viewer. + * + * The command takes two parameters: + * + * path: a string containing the path to a trace + * options: an optional TraceViewerWidgetOpenerOptions + */ +export const OpenTraceWithPathCommand: Command = { + id: 'open-trace-with-path', + label: 'Open Trace With Path' +}; diff --git a/theia-extensions/viewer-prototype/src/browser/trace-viewer/trace-viewer-contribution.ts b/theia-extensions/viewer-prototype/src/browser/trace-viewer/trace-viewer-contribution.ts index 42daf159c..9436bc5f9 100644 --- a/theia-extensions/viewer-prototype/src/browser/trace-viewer/trace-viewer-contribution.ts +++ b/theia-extensions/viewer-prototype/src/browser/trace-viewer/trace-viewer-contribution.ts @@ -5,7 +5,15 @@ import URI from '@theia/core/lib/common/uri'; import { TraceViewerWidget, TraceViewerWidgetOptions } from './trace-viewer'; import { FileDialogService, OpenFileDialogProps } from '@theia/filesystem/lib/browser'; import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; -import { OpenTraceCommand, StartServerCommand, StopServerCommand, TraceViewerCommand, KeyboardShortcutsCommand, OpenTraceWithRootPathCommand } from './trace-viewer-commands'; +import { + OpenTraceCommand, + StartServerCommand, + StopServerCommand, + TraceViewerCommand, + KeyboardShortcutsCommand, + OpenTraceWithRootPathCommand, + OpenTraceWithPathCommand, +} from './trace-viewer-commands'; import { PortBusy, TraceServerConfigService } from '../../common/trace-server-config'; import { TracePreferences, TRACE_PATH, TRACE_ARGS } from '../trace-server-preference'; import { TspClient } from 'tsp-typescript-client/lib/protocol/tsp-client'; @@ -178,6 +186,10 @@ export class TraceViewerContribution extends WidgetOpenHandler this.launchTraceServer() }); + registry.registerCommand(OpenTraceWithPathCommand, { + isVisible: () => false, + execute: (path: string, options: TraceViewerWidgetOpenerOptions) => path && this.open(new URI(path), options), + }); registry.registerCommand(OpenTraceWithRootPathCommand, { isVisible: () => false, execute: rootPath => this.launchTraceServer(rootPath)