From a49572f322c83ac1cdc68f3279f1707dbb6118dc Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Fri, 3 Nov 2023 11:05:24 -0400 Subject: [PATCH] Use trace server manager with Open Trace command When the command 'openTraceFolder' is invoked from the Open Trace button, change the order so that the user is first prompted to select a trace folder. In order to do this, the openDialog() method is exported and is no longer called from the fileOpenHandler() method. Use the selected trace to start the trace server using the trace server manager, which will select the proper contributor to start the server, based on the trace path. Remove the execution of 'start-if-stopped' command from the startTraceServerIfAvailable() method, and make its pathToTrace parameter mandatory. The fileOpenHandler() method is called last, and its traceUri parameter is now mandatory. Fixes #183. Signed-off-by: Patrick Tasse --- vscode-trace-extension/src/extension.ts | 21 ++++++++----------- .../src/trace-explorer/trace-tree.ts | 12 ++--------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/vscode-trace-extension/src/extension.ts b/vscode-trace-extension/src/extension.ts index 117fe514..426347da 100644 --- a/vscode-trace-extension/src/extension.ts +++ b/vscode-trace-extension/src/extension.ts @@ -6,6 +6,7 @@ import { TraceExplorerTimeRangeDataProvider } from './trace-explorer/time-range/ import { TraceExplorerAvailableViewsProvider } from './trace-explorer/available-views/trace-explorer-available-views-webview-provider'; import { TraceExplorerOpenedTracesViewProvider } from './trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider'; import { + openDialog, fileHandler, openOverviewHandler, resetZoomHandler, @@ -156,9 +157,13 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI { context.subscriptions.push( vscode.commands.registerCommand('openedTraces.openTraceFolder', async () => { - await startTraceServerIfAvailable(); + const traceUri = await openDialog(); + if (!traceUri) { + return; + } + await startTraceServerIfAvailable(traceUri.fsPath); if (await isUp()) { - fileOpenHandler(context, undefined); + fileOpenHandler(context, traceUri); } }) ); @@ -196,19 +201,11 @@ export async function deactivate(): Promise { traceExtensionWebviewManager.dispose(); } -async function startTraceServerIfAvailable(pathToTrace?: string): Promise { - const extensionId = 'vscode-trace-server'; +async function startTraceServerIfAvailable(pathToTrace: string): Promise { if (await isUp()) { return; } - if (pathToTrace) { - await traceServerManager.startServer(pathToTrace); - } - const traceServerExtension = vscode.extensions.getExtension('tracecompass-community.' + extensionId); - if (!traceServerExtension) { - return; - } - await vscode.commands.executeCommand(extensionId + '.start-if-stopped'); + await traceServerManager.startServer(pathToTrace); } async function isUp() { diff --git a/vscode-trace-extension/src/trace-explorer/trace-tree.ts b/vscode-trace-extension/src/trace-explorer/trace-tree.ts index 49febfd8..24fdabf7 100644 --- a/vscode-trace-extension/src/trace-explorer/trace-tree.ts +++ b/vscode-trace-extension/src/trace-explorer/trace-tree.ts @@ -127,7 +127,7 @@ export const zoomHandler = (hasZoomedIn: boolean): void => { TraceViewerPanel.zoomOnCurrent(hasZoomedIn); }; -const openDialog = async (): Promise => { +export const openDialog = async (): Promise => { const props: vscode.OpenDialogOptions = { title: 'Open Trace', canSelectFolders: true, @@ -144,15 +144,7 @@ const openDialog = async (): Promise => { export const fileHandler = (analysisTree: AnalysisProvider) => - async (context: vscode.ExtensionContext, traceUri: vscode.Uri | undefined): Promise => { - // We need to resolve trace URI before starting the progress dialog because we rely on trace URI for dialog title - if (!traceUri) { - traceUri = await openDialog(); - if (!traceUri) { - return; - } - } - + async (context: vscode.ExtensionContext, traceUri: vscode.Uri): Promise => { const resolvedTraceURI: vscode.Uri = traceUri; vscode.window.withProgress( {