Add a BuildSystemDelegate which supports notifications for build settings changes

Introduce a `BuildSystemDelegate` to handle notifications from the build system

* `SourceKitServer` is the main delegate to process these notifications
* Currently limited to changes in `FileBuildSettings`
* Delegate informs the `BuildSystem` of files to watch via `registerChangeWatching(for: URL)` and `unregisterChangeWatching(for: URL)`
* In the future we could have more integration for handling changes in dependencies

Handling changes in `FileBuildSettings`

* `SourceKitServer` sends notifications to the internal LSPs informing them of any opened documents that have changes in their compiler flags
    * For clangd, we send a notification to update the compilation database
    * For SourceKit/sourcekitd we must close and reopen the file to force a new AST with the new compiler flags
This commit is contained in:
David Goldman
2019-09-06 17:44:36 -04:00
parent c6fedf7221
commit e5caf44fda
15 changed files with 510 additions and 21 deletions

View File

@@ -30,6 +30,9 @@ public final class BuildServerBuildSystem {
var buildServer: Connection?
public private(set) var indexStorePath: AbsolutePath?
/// Delegate to handle any build system events.
public weak var delegate: BuildSystemDelegate? = nil
public init(projectRoot: AbsolutePath, buildFolder: AbsolutePath?, fileSystem: FileSystem = localFileSystem) throws {
let configPath = projectRoot.appending(component: "buildServer.json")
let config = try loadBuildServerConfig(path: configPath, fileSystem: fileSystem)
@@ -116,6 +119,19 @@ final class BuildServerHandler: LanguageServerEndpoint {
extension BuildServerBuildSystem: BuildSystem {
/// Register the given file for build-system level change notifications, such as command
/// line flag changes, dependency changes, etc.
public func registerForChangeNotifications(for url: LanguageServerProtocol.URL) {
// TODO: Implement via BSP extensions.
}
/// Unregister the given file for build-system level change notifications, such as command
/// line flag changes, dependency changes, etc.
public func unregisterForChangeNotifications(for url: LanguageServerProtocol.URL) {
// TODO: Implement via BSP extensions.
}
public var indexDatabasePath: AbsolutePath? {
return buildFolder?.appending(components: "index", "db")
}