@@ -2624,96 +2624,85 @@ final class BackgroundIndexingTests: XCTestCase {
2624
2624
let symbols = try await project. testClient. send ( WorkspaceSymbolsRequest ( query: " myTestFu " ) )
2625
2625
XCTAssertEqual ( symbols? . count, 1 )
2626
2626
}
2627
- }
2628
2627
2629
- // WIP, not ready for review
2630
- // func testBuildServerUsesCustomTaskBatchSize() async throws {
2631
- // final class BuildServer: CustomBuildServer {
2632
- // let inProgressRequestsTracker = CustomBuildServerInProgressRequestTracker()
2633
- // private let projectRoot: URL
2634
- // private var testFileURL: URL { projectRoot.appendingPathComponent("test.swift").standardized }
2635
-
2636
- // nonisolated(unsafe) var preparedTargetBatches = [[BuildTargetIdentifier]]()
2637
-
2638
- // required init(projectRoot: URL, connectionToSourceKitLSP: any LanguageServerProtocol.Connection) {
2639
- // self.projectRoot = projectRoot
2640
- // }
2641
-
2642
- // func initializeBuildRequest(_ request: InitializeBuildRequest) async throws -> InitializeBuildResponse {
2643
- // return try initializationResponseSupportingBackgroundIndexing(
2644
- // projectRoot: projectRoot,
2645
- // outputPathsProvider: false,
2646
- // )
2647
- // }
2648
-
2649
- // func buildTargetSourcesRequest(_ request: BuildTargetSourcesRequest) async throws -> BuildTargetSourcesResponse {
2650
- // var dummyTargets = [BuildTargetIdentifier]()
2651
- // for i in 0..<10 {
2652
- // dummyTargets.append(BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-\(i)")))
2653
- // }
2654
- // return BuildTargetSourcesResponse(items: dummyTargets.map {
2655
- // SourcesItem(target: $0, sources: [SourceItem(uri: URI(testFileURL), kind: .file, generated: false)])
2656
- // })
2657
- // }
2658
-
2659
- // func textDocumentSourceKitOptionsRequest(
2660
- // _ request: TextDocumentSourceKitOptionsRequest
2661
- // ) async throws -> TextDocumentSourceKitOptionsResponse? {
2662
- // return TextDocumentSourceKitOptionsResponse(compilerArguments: [request.textDocument.uri.pseudoPath])
2663
- // }
2664
-
2665
- // func prepareTarget(_ request: BuildTargetPrepareRequest) async throws -> VoidResponse {
2666
- // preparedTargetBatches.append(request.targets.sorted { $0.uri.stringValue < $1.uri.stringValue })
2667
- // return VoidResponse()
2668
- // }
2669
- // }
2670
-
2671
- // let project = try await CustomBuildServerTestProject(
2672
- // files: [
2673
- // "test.swift": """
2674
- // func testFunction() {}
2675
- // """
2676
- // ],
2677
- // buildServer: BuildServer.self,
2678
- // enableBackgroundIndexing: true,
2679
- // )
2680
-
2681
- // // Wait for indexing to finish without elevating the priority
2682
- // // Otherwise, task re-scheduling would cause the test to become flaky
2683
- // let semaphore = WrappedSemaphore(name: "Indexing finished")
2684
- // let testClient = project.testClient
2685
- // Task(priority: .low) {
2686
- // await assertNoThrow {
2687
- // try await testClient.send(SynchronizeRequest(index: true))
2688
- // }
2689
- // semaphore.signal()
2690
- // }
2691
- // try semaphore.waitOrThrow()
2692
-
2693
- // let buildServer = try project.buildServer()
2694
- // let preparedBatches = buildServer.preparedTargetBatches.sorted { $0[0].uri.stringValue < $1[0].uri.stringValue }
2695
- // XCTAssertEqual(preparedBatches, [
2696
- // [
2697
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-0")),
2698
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-1")),
2699
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-2")),
2700
- // ],
2701
- // [
2702
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-3")),
2703
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-4")),
2704
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-5")),
2705
- // ],
2706
- // [
2707
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-6")),
2708
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-7")),
2709
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-8")),
2710
- // ],
2711
- // [
2712
- // BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy-9")),
2713
- // ]
2714
- // ])
2715
- // }
2716
- // }
2628
+ func testBuildServerUsesCustomTaskBatchSize( ) async throws {
2629
+ final class BuildServer : CustomBuildServer {
2630
+ let inProgressRequestsTracker = CustomBuildServerInProgressRequestTracker ( )
2631
+ private let projectRoot : URL
2632
+ private var testFileURL : URL { projectRoot. appendingPathComponent ( " test.swift " ) . standardized }
2633
+
2634
+ nonisolated ( unsafe) var preparedTargetBatches = [ [ BuildTargetIdentifier] ] ( )
2635
+
2636
+ required init ( projectRoot: URL , connectionToSourceKitLSP: any LanguageServerProtocol . Connection ) {
2637
+ self . projectRoot = projectRoot
2638
+ }
2639
+
2640
+ func initializeBuildRequest( _ request: InitializeBuildRequest ) async throws -> InitializeBuildResponse {
2641
+ return try initializationResponseSupportingBackgroundIndexing (
2642
+ projectRoot: projectRoot,
2643
+ outputPathsProvider: false ,
2644
+ multiTargetPreparation: MultiTargetPreparationSupport ( supported: true , batchSize: 3 )
2645
+ )
2646
+ }
2647
+
2648
+ func buildTargetSourcesRequest( _ request: BuildTargetSourcesRequest ) async throws -> BuildTargetSourcesResponse {
2649
+ var dummyTargets = [ BuildTargetIdentifier] ( )
2650
+ for i in 0 ..< 10 {
2651
+ dummyTargets. append ( BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy- \( i) " ) ) )
2652
+ }
2653
+ return BuildTargetSourcesResponse ( items: dummyTargets. map {
2654
+ SourcesItem ( target: $0, sources: [ SourceItem ( uri: URI ( testFileURL) , kind: . file, generated: false ) ] )
2655
+ } )
2656
+ }
2657
+
2658
+ func textDocumentSourceKitOptionsRequest(
2659
+ _ request: TextDocumentSourceKitOptionsRequest
2660
+ ) async throws -> TextDocumentSourceKitOptionsResponse ? {
2661
+ return TextDocumentSourceKitOptionsResponse ( compilerArguments: [ request. textDocument. uri. pseudoPath] )
2662
+ }
2663
+
2664
+ func prepareTarget( _ request: BuildTargetPrepareRequest ) async throws -> VoidResponse {
2665
+ preparedTargetBatches. append ( request. targets. sorted { $0. uri. stringValue < $1. uri. stringValue } )
2666
+ return VoidResponse ( )
2667
+ }
2668
+ }
2669
+
2670
+ let project = try await CustomBuildServerTestProject (
2671
+ files: [
2672
+ " test.swift " : """
2673
+ func testFunction() {}
2674
+ """
2675
+ ] ,
2676
+ buildServer: BuildServer . self,
2677
+ enableBackgroundIndexing: true ,
2678
+ )
2679
+
2680
+ try await project. testClient. send ( SynchronizeRequest ( index: true ) )
2681
+
2682
+ let buildServer = try project. buildServer ( )
2683
+ let preparedBatches = buildServer. preparedTargetBatches. sorted { $0 [ 0 ] . uri. stringValue < $1 [ 0 ] . uri. stringValue }
2684
+ XCTAssertEqual ( preparedBatches, [
2685
+ [
2686
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-0 " ) ) ,
2687
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-1 " ) ) ,
2688
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-2 " ) ) ,
2689
+ ] ,
2690
+ [
2691
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-3 " ) ) ,
2692
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-4 " ) ) ,
2693
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-5 " ) ) ,
2694
+ ] ,
2695
+ [
2696
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-6 " ) ) ,
2697
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-7 " ) ) ,
2698
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-8 " ) ) ,
2699
+ ] ,
2700
+ [
2701
+ BuildTargetIdentifier ( uri: try ! URI ( string: " dummy://dummy-9 " ) ) ,
2702
+ ]
2703
+ ] )
2704
+ }
2705
+ }
2717
2706
2718
2707
extension HoverResponseContents {
2719
2708
var markupContent : MarkupContent ? {
0 commit comments