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

@@ -23,6 +23,9 @@ public final class CompilationDatabaseBuildSystem {
/// The compilation database.
var compdb: CompilationDatabase? = nil
/// Delegate to handle any build system events.
public weak var delegate: BuildSystemDelegate? = nil
let fileSystem: FileSystem
public init(projectRoot: AbsolutePath? = nil, fileSystem: FileSystem = localFileSystem) {
@@ -50,6 +53,12 @@ extension CompilationDatabaseBuildSystem: BuildSystem {
public func toolchain(for: URL, _ language: Language) -> Toolchain? { return nil }
/// We don't support change watching.
public func registerForChangeNotifications(for: URL) {}
/// We don't support change watching.
public func unregisterForChangeNotifications(for: URL) {}
func database(for url: URL) -> CompilationDatabase? {
if let path = try? AbsolutePath(validating: url.path) {
return database(for: path)