Skip to content

Commit

Permalink
Also accept plain string as command arg
Browse files Browse the repository at this point in the history
  • Loading branch information
sransara committed Jul 25, 2024
1 parent 031267e commit 43e61d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
});
});

0 comments on commit 43e61d1

Please sign in to comment.