Skip to content

Background indexing of package plugins fails #2755

Description

@ahoppen

The following updated test case fails

There are two reasons for this:

  1. SwiftPM returns the path to the compiler in the sourceKitOptions response, which thus gets interpreted as another input file
  2. 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)
  }

Activity

  1. added theissue type on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions