The following updated test case fails
There are two reasons for this:
- SwiftPM returns the path to the compiler in the
sourceKitOptions response, which thus gets interpreted as another input file
- Even with that resolved, background indexing fails with the following error:
error: wrong number of '-serialize-diagnostics-path' arguments (expected 2, got 1)
func testPackagePlugin() async throws {
let project = try await SwiftPMTestProject(
files: [
"Test.swift": "",
"Plugins/PrintMessage/Plugin.swift": """
import PackagePlugin
func 1️⃣callMe() {
}
@main
struct PrintMessagePlugin: CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) throws {
let x: String = 1
}
}
""",
"Plugins/PrintMessage/Other.swift": """
func test() {
callMe()
}
""",
],
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'"]
)
let references = try await project.testClient.send(
ReferencesRequest(
textDocument: TextDocumentIdentifier(uri),
position: project.position(of: "1️⃣", in: "Plugin.swift"),
context: ReferencesContext(includeDeclaration: false)
)
)
XCTAssertGreaterThan(references.count, 0)
}
The following updated test case fails
There are two reasons for this:
sourceKitOptionsresponse, which thus gets interpreted as another input fileerror: wrong number of '-serialize-diagnostics-path' arguments (expected 2, got 1)