From 1d7858e0230ff08cbf84e3a019aa81436e0970ab Mon Sep 17 00:00:00 2001 From: Richard Howell Date: Fri, 4 Oct 2019 16:03:43 -0700 Subject: [PATCH] call delegate on build targets change --- Sources/BuildServerProtocol/BuildTargets.swift | 2 +- Sources/BuildServerProtocol/Messages.swift | 2 +- Sources/SKCore/BuildServerBuildSystem.swift | 5 +++++ Sources/SKCore/BuildSystemDelegate.swift | 10 ++++++++-- Sources/SourceKit/SourceKitServer.swift | 5 +++++ Tests/SKCoreTests/BuildServerBuildSystemTests.swift | 4 ++++ 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Sources/BuildServerProtocol/BuildTargets.swift b/Sources/BuildServerProtocol/BuildTargets.swift index 6ca21a59..03ebf045 100644 --- a/Sources/BuildServerProtocol/BuildTargets.swift +++ b/Sources/BuildServerProtocol/BuildTargets.swift @@ -211,7 +211,7 @@ public struct OutputsItem: Codable, Hashable { /// The build target changed notification is sent from the server to the client /// to signal a change in a build target. The server communicates during the /// initialize handshake whether this method is supported or not. -public struct BuildTargetChangedNotification: NotificationType { +public struct BuildTargetsChangedNotification: NotificationType { public static let method: String = "buildTarget/didChange" public var changes: [BuildTargetEvent] diff --git a/Sources/BuildServerProtocol/Messages.swift b/Sources/BuildServerProtocol/Messages.swift index d8259644..9feee786 100644 --- a/Sources/BuildServerProtocol/Messages.swift +++ b/Sources/BuildServerProtocol/Messages.swift @@ -22,7 +22,7 @@ fileprivate let requestTypes: [_RequestType.Type] = [ ] fileprivate let notificationTypes: [NotificationType.Type] = [ - BuildTargetChangedNotification.self, + BuildTargetsChangedNotification.self, ExitBuildNotification.self, FileOptionsChangedNotification.self, InitializedBuildNotification.self, diff --git a/Sources/SKCore/BuildServerBuildSystem.swift b/Sources/SKCore/BuildServerBuildSystem.swift index 11695dca..7d9cc90f 100644 --- a/Sources/SKCore/BuildServerBuildSystem.swift +++ b/Sources/SKCore/BuildServerBuildSystem.swift @@ -126,9 +126,14 @@ final class BuildServerHandler: LanguageServerEndpoint { public weak var delegate: BuildSystemDelegate? = nil override func _registerBuiltinHandlers() { + _register(BuildServerHandler.handleBuildTargetsChanged) _register(BuildServerHandler.handleFileOptionsChanged) } + func handleBuildTargetsChanged(_ notification: Notification) { + self.delegate?.buildTargetsChanged(notification.params.changes) + } + func handleFileOptionsChanged(_ notification: Notification) { // TODO: add delegate method to include the changed settings directly self.delegate?.fileBuildSettingsChanged([notification.params.uri]) diff --git a/Sources/SKCore/BuildSystemDelegate.swift b/Sources/SKCore/BuildSystemDelegate.swift index 0407fbce..1eb2192f 100644 --- a/Sources/SKCore/BuildSystemDelegate.swift +++ b/Sources/SKCore/BuildSystemDelegate.swift @@ -9,15 +9,21 @@ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// - +import BuildServerProtocol import LanguageServerProtocol import TSCBasic /// Handles build system events, such as file build settings changes. public protocol BuildSystemDelegate: AnyObject { + /// Notify the delegate that the build targets have changed. + /// + /// The callee should request new sources and outputs for the build targets of + /// interest. + func buildTargetsChanged(_ changes: [BuildTargetEvent]) /// Notify the delegate that the given files' build settings have changed. /// - /// The callee should request new build settings for any of the given files that they are interested in. + /// The callee should request new build settings for any of the given files + /// that they are interested in. func fileBuildSettingsChanged(_ changedFiles: Set) } diff --git a/Sources/SourceKit/SourceKitServer.swift b/Sources/SourceKit/SourceKitServer.swift index 0da0f93b..864def61 100644 --- a/Sources/SourceKit/SourceKitServer.swift +++ b/Sources/SourceKit/SourceKitServer.swift @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +import BuildServerProtocol import LanguageServerProtocol import SKCore import SKSupport @@ -238,6 +239,10 @@ public final class SourceKitServer: LanguageServer { // MARK: - Build System Delegate extension SourceKitServer: BuildSystemDelegate { + public func buildTargetsChanged(_ changes: [BuildTargetEvent]) { + // TODO: do something with these changes once build target support is in place + } + public func fileBuildSettingsChanged(_ changedFiles: Set) { guard let workspace = self.workspace else { return diff --git a/Tests/SKCoreTests/BuildServerBuildSystemTests.swift b/Tests/SKCoreTests/BuildServerBuildSystemTests.swift index 8b636ad7..64ad23ea 100644 --- a/Tests/SKCoreTests/BuildServerBuildSystemTests.swift +++ b/Tests/SKCoreTests/BuildServerBuildSystemTests.swift @@ -165,6 +165,10 @@ final class TestDelegate: BuildSystemDelegate { self.expectations = expectations } + func buildTargetsChanged(_ changes: [BuildTargetEvent]) { + + } + func fileBuildSettingsChanged(_ changedFiles: Set) { for url in changedFiles { expectations[url]?.fulfill()