Skip to content

Commit

Permalink
Use trace server manager with Open Trace command
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
PatrickTasse committed Nov 3, 2023
1 parent f0df578 commit a49572f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
21 changes: 9 additions & 12 deletions vscode-trace-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
})
);
Expand Down Expand Up @@ -196,19 +201,11 @@ export async function deactivate(): Promise<void> {
traceExtensionWebviewManager.dispose();
}

async function startTraceServerIfAvailable(pathToTrace?: string): Promise<void> {
const extensionId = 'vscode-trace-server';
async function startTraceServerIfAvailable(pathToTrace: string): Promise<void> {
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() {
Expand Down
12 changes: 2 additions & 10 deletions vscode-trace-extension/src/trace-explorer/trace-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const zoomHandler = (hasZoomedIn: boolean): void => {
TraceViewerPanel.zoomOnCurrent(hasZoomedIn);
};

const openDialog = async (): Promise<vscode.Uri | undefined> => {
export const openDialog = async (): Promise<vscode.Uri | undefined> => {
const props: vscode.OpenDialogOptions = {
title: 'Open Trace',
canSelectFolders: true,
Expand All @@ -144,15 +144,7 @@ const openDialog = async (): Promise<vscode.Uri | undefined> => {

export const fileHandler =
(analysisTree: AnalysisProvider) =>
async (context: vscode.ExtensionContext, traceUri: vscode.Uri | undefined): Promise<void> => {
// 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<void> => {
const resolvedTraceURI: vscode.Uri = traceUri;
vscode.window.withProgress(
{
Expand Down

0 comments on commit a49572f

Please sign in to comment.