From 0c673313002d6eb334b8f4a2ae9bebef96f13b61 Mon Sep 17 00:00:00 2001 From: Adam Ward Date: Fri, 12 Dec 2025 13:52:26 -0500 Subject: [PATCH] Add new `swiftPlayPath` setting to make development easier Purposefully do not want in package.json as don't want to advertise Issue: #1782 --- src/commands/runPlayground.ts | 9 ++++++++- src/configuration.ts | 7 +++++++ src/playgrounds/PlaygroundProvider.ts | 8 ++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/commands/runPlayground.ts b/src/commands/runPlayground.ts index 0435007db..0f3151ced 100644 --- a/src/commands/runPlayground.ts +++ b/src/commands/runPlayground.ts @@ -11,10 +11,12 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +import { dirname } from "path"; import * as vscode from "vscode"; import { Location, Range } from "vscode-languageclient"; import { FolderContext } from "../FolderContext"; +import configuration from "../configuration"; import { createSwiftTask } from "../tasks/SwiftTaskProvider"; import { TaskManager } from "../tasks/TaskManager"; import { packageName } from "../utilities/tasks"; @@ -50,7 +52,12 @@ export async function runPlayground( packageName: packageName(folderContext), presentationOptions: { reveal: vscode.TaskRevealKind.Always }, }, - folderContext.toolchain + folderContext.toolchain, + configuration.swiftPlayPath + ? { + PATH: `${dirname(configuration.swiftPlayPath)}${process.platform === "win32" ? ";" : ":"}${process.env["PATH"]}`, + } + : undefined ); await tasks.executeTaskAndWait(task); diff --git a/src/configuration.ts b/src/configuration.ts index 9d77c7a12..82402af1f 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -366,6 +366,13 @@ const configuration = { /* Put in worker queue */ }); }, + // TODO Remove when swift-play is in the toolchain + /** Only for development purposes for testing a local build of SwiftPM with swift-play */ + get swiftPlayPath(): string { + return substituteVariablesInString( + vscode.workspace.getConfiguration("swift").get("swiftPlayPath", "") + ); + }, /** swift build arguments */ get buildArguments(): string[] { return vscode.workspace diff --git a/src/playgrounds/PlaygroundProvider.ts b/src/playgrounds/PlaygroundProvider.ts index 554f7cfaf..8a93c22a1 100644 --- a/src/playgrounds/PlaygroundProvider.ts +++ b/src/playgrounds/PlaygroundProvider.ts @@ -15,6 +15,7 @@ import * as vscode from "vscode"; import { FolderContext } from "../FolderContext"; import { FolderOperation, WorkspaceContext } from "../WorkspaceContext"; +import configuration from "../configuration"; import { SwiftLogger } from "../logging/SwiftLogger"; import { LSPPlaygroundsDiscovery, Playground } from "./LSPPlaygroundsDiscovery"; @@ -120,8 +121,11 @@ export class PlaygroundProvider implements vscode.Disposable { await this.fetchPromise; return; } - if (!(await this.lspPlaygroundDiscovery.supportsPlaygrounds())) { - this.logger.debug( + if ( + !configuration.swiftPlayPath && + !(await this.lspPlaygroundDiscovery.supportsPlaygrounds()) + ) { + this.logger.warn( `Fetching playgrounds not supported by the language server`, this.folderContext.name );