From 8000fdb8599c7a023c62a9121ac186d62836f815 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Thu, 11 Dec 2025 12:38:58 -0500 Subject: [PATCH 1/2] Ignore `--scratch-path` when calling `swift package plugin --list` If the user has a `swift.buildPath` set, and they've got backgroundCompilation turned on, the extension will attempt to list their package's plugins with a `--scratch-path`, which `swift package plugin --list` does not accept. This causes the command to fail. Omit this argument from the command. --- src/extension.ts | 7 ++-- src/toolchain/BuildFlags.ts | 36 +++++++++++++------- test/unit-tests/toolchain/BuildFlags.test.ts | 31 +++++++++++++++++ 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index ab9760e81..a3415ab7d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -222,10 +222,9 @@ function handleFolderEvent(logger: SwiftLogger): (event: FolderEvent) => Promise // function called when a folder is added. I broke this out so we can trigger it // without having to await for it. async function folderAdded(folder: FolderContext, workspace: WorkspaceContext) { - if ( - !configuration.folder(folder.workspaceFolder).disableAutoResolve || - configuration.backgroundCompilation.enabled - ) { + const disableAutoResolve = configuration.folder(folder.workspaceFolder).disableAutoResolve; + const backgroundCompilationEnabled = configuration.backgroundCompilation.enabled; + if (!disableAutoResolve || backgroundCompilationEnabled) { // if background compilation is set then run compile at startup unless // this folder is a sub-folder of the workspace folder. This is to avoid // kicking off compile for multiple projects at the same time diff --git a/src/toolchain/BuildFlags.ts b/src/toolchain/BuildFlags.ts index cd7512186..dcb5d162c 100644 --- a/src/toolchain/BuildFlags.ts +++ b/src/toolchain/BuildFlags.ts @@ -44,20 +44,27 @@ export class BuildFlags { private withSwiftSDKFlags(args: string[]): string[] { switch (args[0]) { case "package": { - const subcommand = args.splice(0, 2).concat(this.buildPathFlags()); - switch (subcommand[1]) { - case "dump-symbol-graph": - case "diagnose-api-breaking-changes": - case "resolve": { - // These two tools require building the package, so SDK - // flags are needed. Destination control flags are - // required to be placed before subcommand options. - return [...subcommand, ...this.swiftpmSDKFlags(), ...args]; + switch (args[1]) { + case "plugin": + // Don't append build path flags for `swift package plugin` commands + return args; + default: { + const subcommand = args.splice(0, 2).concat(this.buildPathFlags()); + switch (subcommand[1]) { + case "dump-symbol-graph": + case "diagnose-api-breaking-changes": + case "resolve": { + // These two tools require building the package, so SDK + // flags are needed. Destination control flags are + // required to be placed before subcommand options. + return [...subcommand, ...this.swiftpmSDKFlags(), ...args]; + } + default: + // Other swift-package subcommands operate on the host, + // so it doesn't need to know about the destination. + return subcommand.concat(args); + } } - default: - // Other swift-package subcommands operate on the host, - // so it doesn't need to know about the destination. - return subcommand.concat(args); } } case "build": @@ -212,6 +219,9 @@ export class BuildFlags { const disableSandboxFlags = ["--disable-sandbox", "-Xswiftc", "-disable-sandbox"]; switch (args[0]) { case "package": { + if (args[1] === "plugin") { + return args; + } return [args[0], ...disableSandboxFlags, ...args.slice(1)]; } case "build": diff --git a/test/unit-tests/toolchain/BuildFlags.test.ts b/test/unit-tests/toolchain/BuildFlags.test.ts index 2c6793303..10b833e6b 100644 --- a/test/unit-tests/toolchain/BuildFlags.test.ts +++ b/test/unit-tests/toolchain/BuildFlags.test.ts @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// import { expect } from "chai"; +import { beforeEach } from "mocha"; import * as sinon from "sinon"; import configuration from "@src/configuration"; @@ -242,6 +243,13 @@ suite("BuildFlags Test Suite", () => { suite("withAdditionalFlags", () => { const sdkConfig = mockGlobalValue(configuration, "sdk"); + const buildPathConfig = mockGlobalValue(configuration, "buildPath"); + + beforeEach(() => { + buildPathConfig.setValue(""); + sdkConfig.setValue(""); + sandboxConfig.setValue(false); + }); test("package", () => { for (const sub of ["dump-symbol-graph", "diagnose-api-breaking-changes", "resolve"]) { @@ -284,6 +292,29 @@ suite("BuildFlags Test Suite", () => { ]); }); + test("package plugin", () => { + buildPathConfig.setValue(""); + sdkConfig.setValue(""); + expect( + buildFlags.withAdditionalFlags(["package", "plugin", "my-plugin"]) + ).to.deep.equal(["package", "plugin", "my-plugin"]); + + buildPathConfig.setValue("/some/build/path"); + expect( + buildFlags.withAdditionalFlags(["package", "plugin", "my-plugin", "--verbose"]) + ).to.deep.equal(["package", "plugin", "my-plugin", "--verbose"]); + + sdkConfig.setValue("/some/full/path/to/sdk"); + expect( + buildFlags.withAdditionalFlags(["package", "plugin", "my-plugin"]) + ).to.deep.equal(["package", "plugin", "my-plugin"]); + + sandboxConfig.setValue(true); + expect( + buildFlags.withAdditionalFlags(["package", "plugin", "my-plugin"]) + ).to.deep.equal(["package", "plugin", "my-plugin"]); + }); + test("build", () => { sdkConfig.setValue(""); expect( From 5f5b41d344f69805f6400538bf3c4e7f0de878f9 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Thu, 11 Dec 2025 12:42:49 -0500 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bab867d4d..f2e384e44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - When editing .sourcekit-lsp/config.json use the JSON schema from the toolchain ([#1979](https://github.com/swiftlang/vscode-swift/pull/1979)) +### Fixed + +- Omit `--scratch-path` when enumerating plugins with `swift package plugin --list` ([#1996](https://github.com/swiftlang/vscode-swift/pull/1996)) + ## 2.14.2 - 2025-12-07 ### Fixed