From c7b44dac44953e1bf1e2574019e8e4d082cafe57 Mon Sep 17 00:00:00 2001 From: Manuel M T Chakravarty Date: Tue, 9 Dec 2025 12:39:41 +0100 Subject: [PATCH] Optional message wrapping This change introduces an optional argument to the initializer, such that the caller can decide whether to apply message wrapping to the data channel. This is, for example, useful in cases, where an altready wrapped channel is being passed to the initializer. --- .../Client/JSONRPCServerConnection.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift b/Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift index afe4666..36cad32 100644 --- a/Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift +++ b/Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift @@ -7,10 +7,15 @@ public actor JSONRPCServerConnection: ServerConnection { private var eventTask: Task? private let session: JSONRPCSession - - /// NOTE: The channel will wrapped with message framing - public init(dataChannel: DataChannel) { - self.session = JSONRPCSession(channel: dataChannel.withMessageFraming()) + + /// Create a JSON-RPC server connection from a data channel. + /// + /// - Parameters: + /// - dataChannel: The data channel use by the server connection for communication. + /// - framing: Whether to wrap the channel with message framing. The default is to perform wrapping. + /// + public init(dataChannel: DataChannel, addMessageFraming framing: Bool = true) { + self.session = JSONRPCSession(channel: framing ? dataChannel.withMessageFraming() : dataChannel) (self.eventSequence, self.eventContinuation) = EventSequence.makeStream()