From f10e5c5d8d736fc4a91dd0b82b01570065edf2fd Mon Sep 17 00:00:00 2001 From: JCWasmx86 Date: Wed, 19 Apr 2023 06:57:44 +0200 Subject: [PATCH] Send token with WorkDoneProgress --- .../Notifications/WorkDoneProgress.swift | 15 ++++++++++++++- .../CodingTests.swift | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Sources/LanguageServerProtocol/Notifications/WorkDoneProgress.swift b/Sources/LanguageServerProtocol/Notifications/WorkDoneProgress.swift index b84cf4df6..03922c738 100644 --- a/Sources/LanguageServerProtocol/Notifications/WorkDoneProgress.swift +++ b/Sources/LanguageServerProtocol/Notifications/WorkDoneProgress.swift @@ -10,9 +10,22 @@ // //===----------------------------------------------------------------------===// -public enum WorkDoneProgress: NotificationType, Hashable { +public struct WorkDoneProgress: NotificationType, Hashable { public static var method: String = "$/progress" + /// The progress token provided by the client or server. + public var token: ProgressToken + + /// The progress data. + public var value: WorkDoneProgressKind + + public init(token: ProgressToken, value: WorkDoneProgressKind) { + self.token = token + self.value = value + } +} + +public enum WorkDoneProgressKind: Codable, Hashable { case begin(WorkDoneProgressBegin) case report(WorkDoneProgressReport) case end(WorkDoneProgressEnd) diff --git a/Tests/LanguageServerProtocolTests/CodingTests.swift b/Tests/LanguageServerProtocolTests/CodingTests.swift index b37673b30..eba951522 100644 --- a/Tests/LanguageServerProtocolTests/CodingTests.swift +++ b/Tests/LanguageServerProtocolTests/CodingTests.swift @@ -1034,21 +1034,33 @@ final class CodingTests: XCTestCase { } func testWorkDoneProgress() { - checkCoding(WorkDoneProgress.begin(WorkDoneProgressBegin(title: "My Work")), json: """ + checkCoding(WorkDoneProgress(token: ProgressToken.integer(3), value: WorkDoneProgressKind.begin(WorkDoneProgressBegin(title: "My Work"))), json: """ + { + "token" : 3, + "value" : { + "kind" : "begin", + "title" : "My Work" + } + } + """) + } + + func testWorkDoneProgressType() { + checkCoding(WorkDoneProgressKind.begin(WorkDoneProgressBegin(title: "My Work")), json: """ { "kind" : "begin", "title" : "My Work" } """) - checkCoding(WorkDoneProgress.report(WorkDoneProgressReport(message: "Still working")), json: """ + checkCoding(WorkDoneProgressKind.report(WorkDoneProgressReport(message: "Still working")), json: """ { "kind" : "report", "message" : "Still working" } """) - checkCoding(WorkDoneProgress.end(WorkDoneProgressEnd()), json: """ + checkCoding(WorkDoneProgressKind.end(WorkDoneProgressEnd()), json: """ { "kind" : "end" }