From 16176fa854f3df4624fe69a469dd2f9c64482d40 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Thu, 2 Apr 2026 13:46:33 +0200 Subject: [PATCH 1/2] Start passing `pluginConfiguration` to `BuildDescription` initializer in SwiftPMBuildServer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To stage in https://github.com/swiftlang/swift-package-manager/pull/9583 because SwiftPM doesn’t support cross-PR testing. --- Sources/BuildServerIntegration/SwiftPMBuildServer.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/BuildServerIntegration/SwiftPMBuildServer.swift b/Sources/BuildServerIntegration/SwiftPMBuildServer.swift index 042cf6177..d888de9d3 100644 --- a/Sources/BuildServerIntegration/SwiftPMBuildServer.swift +++ b/Sources/BuildServerIntegration/SwiftPMBuildServer.swift @@ -511,7 +511,7 @@ package actor SwiftPMBuildServer: BuiltInBuildServer { signposter.emitEvent("Finished generating build plan", id: signpostID) - buildDescription = BuildDescription(buildPlan: plan) + buildDescription = BuildDescription(buildPlan: plan, pluginConfiguration: self.pluginConfiguration) } /// Make sure to execute any throwing statements before setting any @@ -982,3 +982,10 @@ fileprivate extension SourceKitLSPOptions.BackgroundPreparationMode { } #endif + +extension SourceKitLSPAPI.BuildDescription { + @_disfavoredOverload + init(buildPlan: Build.BuildPlan, pluginConfiguration: PluginConfiguration) { + self.init(buildPlan: buildPlan) + } +} From 1d755bf7733b5bc00c572a25f9cacd1524b0599f Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Sat, 10 Jan 2026 12:26:31 +0100 Subject: [PATCH 2/2] Adopt changed SourceKitLSPAPI to return build settings for build plugins Companion of https://github.com/swiftlang/swift-package-manager/pull/9583. Fixes #2115 --- .../SwiftPMBuildServer.swift | 7 --- .../SwiftPMIntegrationTests.swift | 52 +++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Sources/BuildServerIntegration/SwiftPMBuildServer.swift b/Sources/BuildServerIntegration/SwiftPMBuildServer.swift index d888de9d3..0c8431430 100644 --- a/Sources/BuildServerIntegration/SwiftPMBuildServer.swift +++ b/Sources/BuildServerIntegration/SwiftPMBuildServer.swift @@ -982,10 +982,3 @@ fileprivate extension SourceKitLSPOptions.BackgroundPreparationMode { } #endif - -extension SourceKitLSPAPI.BuildDescription { - @_disfavoredOverload - init(buildPlan: Build.BuildPlan, pluginConfiguration: PluginConfiguration) { - self.init(buildPlan: buildPlan) - } -} diff --git a/Tests/SourceKitLSPTests/SwiftPMIntegrationTests.swift b/Tests/SourceKitLSPTests/SwiftPMIntegrationTests.swift index c04583dac..15ba5f50e 100644 --- a/Tests/SourceKitLSPTests/SwiftPMIntegrationTests.swift +++ b/Tests/SourceKitLSPTests/SwiftPMIntegrationTests.swift @@ -902,4 +902,56 @@ final class SwiftPMIntegrationTests: SourceKitLSPTestCase { let xSymbol = try XCTUnwrap(fooSymbol.children?.first(where: { $0.name == "x" })) XCTAssertEqual(xSymbol.kind, .property) } + + func testPackagePlugin() async throws { + let project = try await SwiftPMTestProject( + files: [ + "Test.swift": "", + "Plugins/PrintMessage/Plugin.swift": """ + import PackagePlugin + + @main + struct PrintMessagePlugin: CommandPlugin { + func performCommand(context: PluginContext, arguments: [String]) throws { + print("Message") + let x: String = 1 + } + } + """, + ], + manifest: """ + import PackageDescription + + let package = Package( + name: "PrintMessage", + platforms: [.macOS(.v14)], + products: [ + .plugin( + name: "PrintMessage", + targets: ["PrintMessage"] + ) + ], + targets: [ + .target(name: "MyLibrary"), + .plugin( + name: "PrintMessage", + capability: .command( + intent: .custom( + verb: "print-message", + description: "Prints message" + ) + ) + ) + ] + ) + """, + // enableBackgroundIndexing: true + ) + let (uri, _) = try! project.openDocument("Plugin.swift") + let diags = try await project.testClient.send(DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))) + XCTAssertEqual( + diags.fullReport?.items.map(\.message), + ["Cannot convert value of type 'Int' to specified type 'String'"] + ) + } }