Implement reloadPackageStatusCallback using BSP messages

This commit is contained in:
Alex Hoppen
2024-08-25 08:28:52 -07:00
parent 66f24e3554
commit 6cc2cc4e95
22 changed files with 425 additions and 354 deletions

View File

@@ -38,10 +38,7 @@ package actor CompilationDatabaseBuildSystem {
}
}
/// Callbacks that should be called if the list of possible test files has changed.
package var testFilesDidChangeCallbacks: [() async -> Void] = []
package weak var messageHandler: BuiltInBuildSystemMessageHandler?
package let connectionToSourceKitLSP: any Connection
package let projectRoot: AbsolutePath
@@ -72,13 +69,13 @@ package actor CompilationDatabaseBuildSystem {
package init?(
projectRoot: AbsolutePath,
searchPaths: [RelativePath],
messageHandler: (any BuiltInBuildSystemMessageHandler)?,
connectionToSourceKitLSP: any Connection,
fileSystem: FileSystem = localFileSystem
) {
self.fileSystem = fileSystem
self.projectRoot = projectRoot
self.searchPaths = searchPaths
self.messageHandler = messageHandler
self.connectionToSourceKitLSP = connectionToSourceKitLSP
if let compdb = tryLoadCompilationDatabase(directory: projectRoot, additionalSearchPaths: searchPaths, fileSystem) {
self.compdb = compdb
} else {
@@ -129,9 +126,9 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem {
return BuildTargetSourcesResponse(items: [SourcesItem(target: .dummy, sources: sources)])
}
package func didChangeWatchedFiles(notification: BuildServerProtocol.DidChangeWatchedFilesNotification) async {
package func didChangeWatchedFiles(notification: BuildServerProtocol.DidChangeWatchedFilesNotification) {
if notification.changes.contains(where: { self.fileEventShouldTriggerCompilationDatabaseReload(event: $0) }) {
await self.reloadCompilationDatabase()
self.reloadCompilationDatabase()
}
}
@@ -194,16 +191,13 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem {
/// The compilation database has been changed on disk.
/// Reload it and notify the delegate about build setting changes.
private func reloadCompilationDatabase() async {
private func reloadCompilationDatabase() {
self.compdb = tryLoadCompilationDatabase(
directory: projectRoot,
additionalSearchPaths: searchPaths,
self.fileSystem
)
await messageHandler?.sendNotificationToSourceKitLSP(DidChangeBuildTargetNotification(changes: nil))
for testFilesDidChangeCallback in testFilesDidChangeCallbacks {
await testFilesDidChangeCallback()
}
connectionToSourceKitLSP.send(DidChangeBuildTargetNotification(changes: nil))
}
}