No such module 'PackagePlugin' while editing package plugins
Swift version
swiftlang-6.0.2.1.2 clang-1600.0.26.4
Platform
macOS 15.3.2
Editor
Visual Studio Code with Swift extension 2.2.0
Description
I noticed that module resolution stopped working recently in a Swift plugin project I've been working on. Swift analyzer displays No such module 'PackagePlugin' and stops any further code syntax analysis (code completion and documentation for other modules work but both became slower).
I'm noticing the same issue after setting up a new empty plugin project:
// Package.swift
// swift-tools-version: 6.0
import PackageDescription // No such module 'PackageDescription'
let package = Package(
name: "PrintMessage",
platforms: [.macOS(.v14)],
products: [
.plugin(
name: "PrintMessage",
targets: ["PrintMessage"]
)
],
targets: [
.plugin(
name: "PrintMessage",
capability: .command(
intent: .custom(
verb: "print-message",
description: "Prints message"
)
)
)
]
)
// Plugins/PrintMessage/Plugin.swift
import PackagePlugin // No such module 'PackagePlugin'
@main
struct PrintMessagePlugin: CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) throws {
print("Message")
}
}
The plugin command runs without any issues but not being able to see syntax analysis in the editor severely decreases the ability to develop projects that include plugins.
Steps to Reproduce
No response
Logging
sourcekit-lsp-diagnose-2025-04-16T16-30-38+02-00.zip
Not sure if I should've attached the entire directory that the diagnose command produced. Let me know, if there's more logs data that'd be helpful.
Given the version, I suspect this is https://github.com/swiftlang/sourcekit-lsp/issues/1704. Would you be able to try 6.1/a recent nightly @tomwyr? If you still hit this, would you be able to enable extended logging (https://github.com/swiftlang/sourcekit-lsp/blob/main/Documentation/Enable%20Extended%20Logging.md) and attach another diagnose?
I tried 6.1 and nightly (6.2-dev) using swiftly to install the toolchain but with no luck.
Here's the lsp diagnose output logged for 6.2-dev: sourcekit-lsp-diagnose-2025-04-26T11-08-29+02-00.zip
The issue appears to be this FIXME
https://github.com/swiftlang/swift-package-manager/blob/e0afabb43ea2081ab276e5cef80d43872e62e8b7/Sources/SourceKitLSPAPI/PluginTargetBuildDescription.swift#L76
As far as I can tell, we use the compiler arguments for the package manifest for files in package plugins. And the package manifest compiler arguments don’t contain an include path to usr/lib/swift/pm/PluginAPI, which contains PackagePlugin.swiftmodule.