From 2fb835b81b2d2afcf2e3c70ee2cb27d98e7f394c Mon Sep 17 00:00:00 2001 From: Samodya Abeysiriwardane Date: Thu, 25 Jul 2024 23:14:15 -0500 Subject: [PATCH 1/4] use latest speedscope patches --- external/speedscope | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/speedscope b/external/speedscope index 26f39c5..ce4a737 160000 --- a/external/speedscope +++ b/external/speedscope @@ -1 +1 @@ -Subproject commit 26f39c529a3e5b22f6afc0d703ccd66ff2cf74ed +Subproject commit ce4a7372a26efaf22f2e1208595d405d6ad60d56 From 8856deac61c97a08137edcffd1334d268aba900f Mon Sep 17 00:00:00 2001 From: Samodya Abeysiriwardane Date: Thu, 25 Jul 2024 23:15:35 -0500 Subject: [PATCH 2/4] support relative path string input --- src/commands.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index e648d04..c62169c 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -20,9 +20,37 @@ export class Commands { return; } uri = uris[0]; - } - if (typeof uri === "string") { - uri = vscode.Uri.file(uri); + } else if (typeof uri === "string" || uri instanceof String) { + if (uri.startsWith('.')) { + // Resolve relative path using workspace folders + if (!vscode.workspace.workspaceFolders) { + vscode.window.showErrorMessage(`No workspace found to resolve relative path: ${uri}`); + return; + } + // Try to find the file in any of the workspace folders + try { + uri = await Promise.any( + vscode.workspace.workspaceFolders.map(async (folder) => { + const maybeUri = vscode.Uri.joinPath(folder.uri, uri as string); + await vscode.workspace.fs.stat(maybeUri); + return maybeUri; + }), + ); + } + catch (e) { + vscode.window.showErrorMessage(`File not found in any workspace: ${uri}`); + return; + } + } + else { + try { + uri = vscode.Uri.file(uri as string); + await vscode.workspace.fs.stat(uri); + } catch (e) { + vscode.window.showErrorMessage(`File not found: ${uri}`); + return; + } + } } await vscode.commands.executeCommand( "vscode.openWith", From 7dc00955109b8658eccb553fe9ccc00435003086 Mon Sep 17 00:00:00 2001 From: Samodya Abeysiriwardane Date: Thu, 25 Jul 2024 23:16:27 -0500 Subject: [PATCH 3/4] Show progress indicator --- src/editor-provider.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/editor-provider.ts b/src/editor-provider.ts index 3ec6ade..2a8ecd4 100644 --- a/src/editor-provider.ts +++ b/src/editor-provider.ts @@ -95,16 +95,25 @@ export class SpeedscopeEditorProvider if (e.clientEvent === "ready") { this.logger.info(`Speedscope view for ${document.uri} is ready`); this.logger.info(`Trying to load document: ${document.uri}`); - const docbytes = await vscode.workspace.fs.readFile(document.uri); - let filename = document.uri.path; - if (filename.includes("/")) { - filename = filename.slice(filename.lastIndexOf("/") + 1); - } - webviewPanel.webview.postMessage({ - serverCommand: "openFile", - filename, - docbytes: new Uint8Array(docbytes), - }); + await vscode.window.withProgress( + { + location: vscode.ProgressLocation.Notification, + title: "Loading profile...", + cancellable: false, + }, + async () => { + const docbytes = await vscode.workspace.fs.readFile(document.uri); + let filename = document.uri.path; + if (filename.includes("/")) { + filename = filename.slice(filename.lastIndexOf("/") + 1); + } + webviewPanel.webview.postMessage({ + serverCommand: "openFile", + filename, + docbytes: new Uint8Array(docbytes), + }); + }, + ); } else if (e.clientCommand === "console") { const prefix = `speedscope view: console.${e.method}:`; switch (e.method) { From d727b126c2af525c362aeaccf80e72383a130ec7 Mon Sep 17 00:00:00 2001 From: Samodya Abeysiriwardane Date: Thu, 25 Jul 2024 23:23:43 -0500 Subject: [PATCH 4/4] Add test --- src/test/suite/extension.test.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 6575a56..75a323f 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -54,7 +54,7 @@ suite("Extension Test Suite", () => { // openSpeedscope command should accept string argument as well as Uri // this is necessary to support adding keybindings for example - test("Test openSpeedscope command with string argument", async () => { + test("Test openSpeedscope command with absolute path string argument", async () => { const filePath = path.join(workspaceUri.path, "simple.prof"); await vscode.commands.executeCommand( `${extensionName}.openSpeedscope`, @@ -65,4 +65,17 @@ suite("Extension Test Suite", () => { const extensionApi: PublicApi = vscode.extensions.getExtension(extensionId)!.exports; }); + + // Test if the extension can open a file with a relative path + test("Test openSpeedscope command with relative path string argument", async () => { + const filePath = "./simple.prof"; + await vscode.commands.executeCommand( + `${extensionName}.openSpeedscope`, + filePath, + ); + + // Testing if the extension activated + const extensionApi: PublicApi = + vscode.extensions.getExtension(extensionId)!.exports; + }); });