From 43e61d16a8340fe8a20c262b9b014dea8fe7f8cf Mon Sep 17 00:00:00 2001 From: Samodya Abeysiriwardane Date: Thu, 25 Jul 2024 06:26:28 -0500 Subject: [PATCH] Also accept plain string as command arg --- src/commands.ts | 5 ++++- src/test/suite/extension.test.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/commands.ts b/src/commands.ts index ca223e2..e648d04 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -8,7 +8,7 @@ export class Commands { ) { const commandName = `${extensionName}.openSpeedscope`; - const handler = async (uri?: vscode.Uri) => { + const handler = async (uri?: vscode.Uri | string) => { if (!uri) { const uris = await vscode.window.showOpenDialog({ canSelectFiles: true, @@ -21,6 +21,9 @@ export class Commands { } uri = uris[0]; } + if (typeof uri === "string") { + uri = vscode.Uri.file(uri); + } await vscode.commands.executeCommand( "vscode.openWith", uri, diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 5278b39..6575a56 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -1,4 +1,5 @@ import * as assert from "assert"; +import * as path from "path"; // You can import and use all API from the 'vscode' module // as well as import your extension to test it @@ -50,4 +51,18 @@ suite("Extension Test Suite", () => { }); assert.strictEqual(success, true); }); + + // 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 () => { + const filePath = path.join(workspaceUri.path, "simple.prof"); + await vscode.commands.executeCommand( + `${extensionName}.openSpeedscope`, + filePath, + ); + + // Testing if the extension activated + const extensionApi: PublicApi = + vscode.extensions.getExtension(extensionId)!.exports; + }); });