Implement a syntactic workspace-wide test index

This workspace-wide syntactic test index is used for two purposes:
- It is used for XCTests instead of the semantic index for files that have on-disk or in-memory modifications to files
- It is uses for swift-testing tests, which are only discovered syntactically.

rdar://119191037
This commit is contained in:
Alex Hoppen
2024-04-15 17:05:03 -07:00
parent 17c0a44ac5
commit a799da39aa
25 changed files with 1320 additions and 124 deletions

View File

@@ -39,6 +39,9 @@ public actor CompilationDatabaseBuildSystem {
/// Delegate to handle any build system events.
public weak var delegate: BuildSystemDelegate? = nil
/// Callbacks that should be called if the list of possible test files has changed.
public var testFilesDidChangeCallbacks: [() async -> Void] = []
public func setDelegate(_ delegate: BuildSystemDelegate?) async {
self.delegate = delegate
}
@@ -167,6 +170,9 @@ extension CompilationDatabaseBuildSystem: BuildSystem {
if let delegate = self.delegate {
await delegate.fileBuildSettingsChanged(self.watchedFiles)
}
for testFilesDidChangeCallback in testFilesDidChangeCallbacks {
await testFilesDidChangeCallback()
}
}
public func filesDidChange(_ events: [FileEvent]) async {
@@ -185,4 +191,12 @@ extension CompilationDatabaseBuildSystem: BuildSystem {
return .unhandled
}
}
public func testFiles() async -> [DocumentURI] {
return compdb?.allCommands.map { DocumentURI($0.url) } ?? []
}
public func addTestFilesDidChangeCallback(_ callback: @escaping () async -> Void) async {
testFilesDidChangeCallbacks.append(callback)
}
}