Skip to content

Decide if we want to index products of package dependencies #2427

@ahoppen

Description

@ahoppen

We currently index all products of a package’s dependencies. This matches the fact that you can build all all targets referenced by a dependency’s product on the command line (eg. you can run swift build --product swift-driver from within SourceKit-LSP. Most users probably never use this fact though and we already don’t index all code in package dependencies (eg. test targets of dependencies aren’t indexed). Based on initial measurements, we could save about another minute (relative to 2:45 min) on the total indexing time of SourceKit-LSP if we didn’t index products of dependencies.

If we want to go this way, we’d likely need to check if a product is in graph.reachableProducts here: https://github.com/swiftlang/swift-package-manager/blob/3a4ba00c1fbdf119512f2293a51d79521e664518/Sources/Build/BuildPlan/BuildPlan.swift#L980-L984

Stub for a test case
func testFoo() async throws {
  let project = try await MultiFileTestProject(
    files: [
      // MyLibrary
      "MyDependency/Sources/MyDependency/MyDependency.swift": """
      public func makeHello() -> String { "" }
      """,
      "MyDependency/Sources/swift-help/swift-help.swift": "",
      "MyDependency/Package.swift": """
      // swift-tools-version: 5.7

      import PackageDescription

      let package = Package(
        name: "MyDependency",
        products: [
          .library(name: "MyDependency", targets: ["MyDependency"]),
          .executable(name: "swift-help", targets: ["swift-help"]),
        ],
        targets: [
          .target(name: "MyDependency"),
          .executableTarget(name: "swift-help")
        ]
      )
      """,

      // MyPackage
      "MyPackage/Sources/MyPackage/MyPackage.swift": """
      import MyDependency

      func test() {
        let x: Void = makeHello()
      }
      """,
      "MyPackage/Package.swift": """
      // swift-tools-version: 5.7

      import PackageDescription

      let package = Package(
        name: "MyPackage",
        dependencies: [
          .package(path: "../MyDependency"),
        ],
        targets: [.target(name: "MyPackage", dependencies: [.product(name: "MyDependency", package: "MyDependency")])]
      )
      """,
    ],
    workspaces: { scratchDirectory in
      return [WorkspaceFolder(uri: DocumentURI(scratchDirectory.appending(component: "MyPackage")))]
    },
    enableBackgroundIndexing: true
  )
  try await project.testClient.send(SynchronizeRequest(index: true))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions