@@ -2666,6 +2666,106 @@ final class BackgroundIndexingTests: XCTestCase {
26662666 ]
26672667 )
26682668 }
2669+
2670+ func testIndexingProgressDoesNotGetStuckIfThereAreNoSourceFilesInTarget( ) async throws {
2671+ actor BuildServer : CustomBuildServer {
2672+ let inProgressRequestsTracker = CustomBuildServerInProgressRequestTracker ( )
2673+ private let projectRoot : URL
2674+
2675+ init ( projectRoot: URL , connectionToSourceKitLSP: any Connection ) {
2676+ self . projectRoot = projectRoot
2677+ }
2678+
2679+ func initializeBuildRequest( _ request: InitializeBuildRequest ) async throws -> InitializeBuildResponse {
2680+ return try initializationResponseSupportingBackgroundIndexing (
2681+ projectRoot: projectRoot,
2682+ outputPathsProvider: false
2683+ )
2684+ }
2685+
2686+ func workspaceBuildTargetsRequest(
2687+ _ request: WorkspaceBuildTargetsRequest
2688+ ) async throws -> WorkspaceBuildTargetsResponse {
2689+ return WorkspaceBuildTargetsResponse ( targets: [
2690+ BuildTarget (
2691+ id: . dummy,
2692+ capabilities: BuildTargetCapabilities ( ) ,
2693+ languageIds: [ ] ,
2694+ dependencies: [ ]
2695+ )
2696+ ] )
2697+ }
2698+
2699+ func buildTargetSourcesRequest( _ request: BuildTargetSourcesRequest ) throws -> BuildTargetSourcesResponse {
2700+ return BuildTargetSourcesResponse ( items: [
2701+ SourcesItem (
2702+ target: . dummy,
2703+ sources: [ ]
2704+ )
2705+ ] )
2706+ }
2707+
2708+ func textDocumentSourceKitOptionsRequest(
2709+ _ request: TextDocumentSourceKitOptionsRequest
2710+ ) -> TextDocumentSourceKitOptionsResponse ? {
2711+ var arguments = [ request. textDocument. uri. pseudoPath]
2712+ if let defaultSDKPath {
2713+ arguments += [ " -sdk " , defaultSDKPath]
2714+ }
2715+ return TextDocumentSourceKitOptionsResponse ( compilerArguments: arguments)
2716+ }
2717+
2718+ func prepareTarget( _ request: BuildTargetPrepareRequest ) async throws -> VoidResponse {
2719+ return VoidResponse ( )
2720+ }
2721+ }
2722+
2723+ let expectation = self . expectation ( description: " Did receive indexing work done progress " )
2724+ let hooks = Hooks (
2725+ indexHooks: IndexHooks ( buildGraphGenerationDidStart: {
2726+ // Defer build graph generation long enough so the the debouncer has time to start a work done progress for
2727+ // indexing.
2728+ do {
2729+ try await fulfillmentOfOrThrow ( expectation)
2730+ } catch {
2731+ XCTFail ( " \( error) " )
2732+ }
2733+ } )
2734+ )
2735+ let project = try await CustomBuildServerTestProject (
2736+ files: [
2737+ " Test.swift " : """
2738+ func 1️⃣myTestFunc() {}
2739+ """
2740+ ] ,
2741+ buildServer: BuildServer . self,
2742+ capabilities: ClientCapabilities ( window: WindowClientCapabilities ( workDoneProgress: true ) ) ,
2743+ hooks: hooks,
2744+ enableBackgroundIndexing: true ,
2745+ pollIndex: false ,
2746+ preInitialization: { testClient in
2747+ testClient. handleMultipleRequests { ( request: CreateWorkDoneProgressRequest ) in
2748+ return VoidResponse ( )
2749+ }
2750+ }
2751+ )
2752+ let startIndexing = try await project. testClient. nextNotification ( ofType: WorkDoneProgress . self) { notification in
2753+ guard case . begin( let value) = notification. value else {
2754+ return false
2755+ }
2756+ return value. title == " Indexing "
2757+ }
2758+ expectation. fulfill ( )
2759+ _ = try await project. testClient. nextNotification ( ofType: WorkDoneProgress . self) { notification in
2760+ guard notification. token == startIndexing. token else {
2761+ return false
2762+ }
2763+ guard case . end = notification. value else {
2764+ return false
2765+ }
2766+ return true
2767+ }
2768+ }
26692769}
26702770
26712771extension HoverResponseContents {
0 commit comments