|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
| 13 | +import BuildServerProtocol |
13 | 14 | import BuildSystemIntegration
|
14 | 15 | import LanguageServerProtocol
|
15 | 16 | import LanguageServerProtocolExtensions
|
@@ -1910,6 +1911,72 @@ final class BackgroundIndexingTests: XCTestCase {
|
1910 | 1911 | try await project.testClient.send(IsIndexingRequest()).indexing == false
|
1911 | 1912 | }
|
1912 | 1913 | }
|
| 1914 | + |
| 1915 | + func testIndexFileIfBuildTargetsChange() async throws { |
| 1916 | + let testBuildSystem = ThreadSafeBox<TestBuildSystem?>(initialValue: nil) |
| 1917 | + let project = try await MultiFileTestProject( |
| 1918 | + files: [ |
| 1919 | + "Test.swift": """ |
| 1920 | + func 1️⃣myTestFunc() {} |
| 1921 | + """ |
| 1922 | + ], |
| 1923 | + hooks: Hooks( |
| 1924 | + buildSystemHooks: BuildSystemHooks(injectBuildServer: { projectRoot, connectionToSourceKitLSP in |
| 1925 | + assert(testBuildSystem.value == nil, "Build system injector hook can only create a single TestBuildSystem") |
| 1926 | + let buildSystem = TestBuildSystem( |
| 1927 | + initializeData: SourceKitInitializeBuildResponseData( |
| 1928 | + indexDatabasePath: projectRoot.appendingPathComponent("index-db").path, |
| 1929 | + indexStorePath: projectRoot.appendingPathComponent("index-store").path, |
| 1930 | + prepareProvider: true, |
| 1931 | + sourceKitOptionsProvider: true |
| 1932 | + ), |
| 1933 | + connectionToSourceKitLSP: connectionToSourceKitLSP |
| 1934 | + ) |
| 1935 | + testBuildSystem.value = buildSystem |
| 1936 | + let connection = LocalConnection(receiverName: "TestBuildSystem") |
| 1937 | + connection.start(handler: buildSystem) |
| 1938 | + return connection |
| 1939 | + }) |
| 1940 | + ), |
| 1941 | + enableBackgroundIndexing: true |
| 1942 | + ) |
| 1943 | + let fileUrl = try XCTUnwrap(project.uri(for: "Test.swift").fileURL) |
| 1944 | + |
| 1945 | + var compilerArguments = [fileUrl.path] |
| 1946 | + if let defaultSDKPath { |
| 1947 | + compilerArguments += ["-sdk", defaultSDKPath] |
| 1948 | + } |
| 1949 | + |
| 1950 | + // We don't initially index Test.swift because we don't have build settings for it. |
| 1951 | + |
| 1952 | + try await XCTUnwrap(testBuildSystem.value).setBuildSettings( |
| 1953 | + for: DocumentURI(fileUrl), |
| 1954 | + to: TextDocumentSourceKitOptionsResponse(compilerArguments: compilerArguments) |
| 1955 | + ) |
| 1956 | + |
| 1957 | + // But once we get build settings for it, we should index the file. |
| 1958 | + |
| 1959 | + try await repeatUntilExpectedResult { |
| 1960 | + let workspaceSymbols = try await project.testClient.send(WorkspaceSymbolsRequest(query: "myTestFunc")) |
| 1961 | + guard let workspaceSymbols, !workspaceSymbols.isEmpty else { |
| 1962 | + // No results yet, indexing of the file might not have finished. |
| 1963 | + return false |
| 1964 | + } |
| 1965 | + XCTAssertEqual( |
| 1966 | + workspaceSymbols, |
| 1967 | + [ |
| 1968 | + .symbolInformation( |
| 1969 | + SymbolInformation( |
| 1970 | + name: "myTestFunc()", |
| 1971 | + kind: .function, |
| 1972 | + location: try project.location(from: "1️⃣", to: "1️⃣", in: "Test.swift") |
| 1973 | + ) |
| 1974 | + ) |
| 1975 | + ] |
| 1976 | + ) |
| 1977 | + return true |
| 1978 | + } |
| 1979 | + } |
1913 | 1980 | }
|
1914 | 1981 |
|
1915 | 1982 | extension HoverResponseContents {
|
|
0 commit comments