Skip to content

Commit 8610916

Browse files
committed
Context command to run playground
1 parent 4614c8f commit 8610916

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,11 @@
15271527
"command": "swift.coverAllTests",
15281528
"when": "view == projectPanel && viewItem == 'test_runnable'",
15291529
"group": "inline@3"
1530+
},
1531+
{
1532+
"command": "swift.play",
1533+
"when": "view == projectPanel && viewItem == 'playground'",
1534+
"group": "inline@1"
15301535
}
15311536
]
15321537
},

src/commands.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { switchPlatform } from "./commands/switchPlatform";
5151
import { extractTestItemsAndCount, runTestMultipleTimes } from "./commands/testMultipleTimes";
5252
import { SwiftLogger } from "./logging/SwiftLogger";
5353
import { SwiftToolchain } from "./toolchain/toolchain";
54-
import { PackageNode } from "./ui/ProjectPanelProvider";
54+
import { PackageNode, PlaygroundNode } from "./ui/ProjectPanelProvider";
5555
import { showToolchainSelectionQuickPick } from "./ui/ToolchainSelection";
5656

5757
/**
@@ -153,7 +153,11 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
153153
if (!folder || !target) {
154154
return false;
155155
}
156-
return await runPlayground(folder, ctx.tasks, target);
156+
return await runPlayground(
157+
folder,
158+
ctx.tasks,
159+
PlaygroundNode.isPlaygroundNode(target) ? target.playground : target
160+
);
157161
}),
158162
vscode.commands.registerCommand(Commands.CLEAN_BUILD, async () => await cleanBuild(ctx)),
159163
vscode.commands.registerCommand(

src/ui/ProjectPanelProvider.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,36 @@ class TargetNode {
400400
}
401401
}
402402

403-
class PlaygroundNode {
403+
export class PlaygroundNode {
404404
constructor(
405405
public playground: Playground,
406406
private folder: FolderContext,
407407
private activeTasks: Set<string>
408408
) {}
409409

410+
/**
411+
* "instanceof" has a bad effect in our nightly tests when the VSIX
412+
* bundled source is used. For example:
413+
*
414+
* ```
415+
* vscode.commands.registerCommand(Commands.PLAY, async (item, folder) => {
416+
* if (item instanceof PlaygroundNode) {
417+
* return await runPlayground(item.playground);
418+
* }
419+
* }),
420+
* ```
421+
*
422+
* So instead we'll check for this set boolean property. Even if the implementation of the
423+
* {@link PlaygroundNode} class changes, this property should not need to change
424+
*/
425+
static isPlaygroundNode = (item: { __isPlaygroundNode?: boolean }) =>
426+
item.__isPlaygroundNode ?? false;
427+
__isPlaygroundNode = true;
428+
410429
get name(): string {
411430
return this.playground.label ?? this.playground.id;
412431
}
413432

414-
get args(): string[] {
415-
return [this.name];
416-
}
417-
418433
toTreeItem(): vscode.TreeItem {
419434
const name = this.name;
420435
const item = new vscode.TreeItem(this.name, vscode.TreeItemCollapsibleState.None);

0 commit comments

Comments
 (0)