diff --git a/vscode-trace-extension/src/trace-explorer/trace-tree.ts b/vscode-trace-extension/src/trace-explorer/trace-tree.ts index 5b869da2..49febfd8 100644 --- a/vscode-trace-extension/src/trace-explorer/trace-tree.ts +++ b/vscode-trace-extension/src/trace-explorer/trace-tree.ts @@ -166,8 +166,8 @@ export const fileHandler = return; } - const uri: string = resolvedTraceURI.path; - if (!uri) { + const filePath: string = resolvedTraceURI.fsPath; + if (!filePath) { traceLogger.addLogMessage( 'Cannot open trace: could not retrieve path from URI for trace ' + resolvedTraceURI, fileHandler.name @@ -175,7 +175,7 @@ export const fileHandler = return; } - const name = uri.substring(uri.lastIndexOf('/') + 1); + const name = path.basename(filePath); const panel = TraceViewerPanel.createOrShow(context.extensionUri, name, undefined); progress.report({ message: ProgressMessages.FINDING_TRACES, increment: 10 }); @@ -187,11 +187,11 @@ export const fileHandler = if (fileStat) { if (fileStat.type === vscode.FileType.Directory) { // Find recursively CTF traces - const foundTraces = await findTraces(uri); + const foundTraces = await findTraces(filePath); foundTraces.forEach(trace => tracesArray.push(trace)); } else { // Open single trace file - tracesArray.push(uri); + tracesArray.push(filePath); } } @@ -208,7 +208,7 @@ export const fileHandler = progress.report({ message: ProgressMessages.OPENING_TRACES, increment: 20 }); const traces = new Array(); for (let i = 0; i < tracesArray.length; i++) { - const traceName = tracesArray[i].substring(tracesArray[i].lastIndexOf('/') + 1); + const traceName = path.basename(tracesArray[i]); const trace = await traceManager.openTrace(tracesArray[i], traceName); if (trace) { traces.push(trace); @@ -291,7 +291,7 @@ const findTraces = async (directory: string): Promise => { const childrenArr = await vscode.workspace.fs.readDirectory(uri); for (const child of childrenArr) { if (child[1] === vscode.FileType.Directory) { - const subTraces = await findTraces(directory + '/' + child[0]); + const subTraces = await findTraces(path.join(directory, child[0])); subTraces.forEach(trace => traces.push(trace)); } } @@ -311,8 +311,8 @@ const isCtf = async (directory: string): Promise => { }; function getProgressBarTitle(traceUri: vscode.Uri | undefined): string { - if (!traceUri || !traceUri.path) { + if (!traceUri || !traceUri.fsPath) { return 'undefined'; } - return traceUri.path.substring(traceUri.path.lastIndexOf('/') + 1); + return path.basename(traceUri.fsPath); } diff --git a/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts b/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts index 912c372d..dc9c9f68 100644 --- a/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts +++ b/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts @@ -1,4 +1,5 @@ import * as vscode from 'vscode'; +import * as path from 'path'; import { Experiment } from 'tsp-typescript-client/lib/models/experiment'; import { getTspClientUrl, getTraceServerUrl } from '../utils/tspClient'; import { TraceServerConnectionStatusService } from '../utils/trace-server-status'; @@ -115,7 +116,7 @@ export class TraceViewerPanel { private static async saveTraceCsv(csvData: string, defaultFileName: string) { const saveDialogOptions = { defaultUri: vscode.workspace.workspaceFolders - ? vscode.Uri.file(vscode.workspace.workspaceFolders[0].uri.path + '/' + defaultFileName) + ? vscode.Uri.file(path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, defaultFileName)) : undefined, saveLabel: 'Save as CSV', filters: {