diff --git a/README.md b/README.md index de51e47..fa426c1 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,7 @@ For the most part, this library strives to be a straightforward version of the s - `Server`: a protocol that describes the essential server functionality - `Snippet`: makes it easier to interpret the contents of completion results - `TokenRepresentation`: maintains the state of a document's semantic tokens -- `AsyncMessageFramingSequence`: parsers an input AsyncSequence with LSP's HTTP header-based message framing (see also `MessageFraming`) -- `AsyncByteSequence`: transforms a sequence of Data into a sequence of bytes +- `DataChannel.withMessageFraming`: wraps an existing JSONRPC DataChannel up with HTTP header-based message framing ## Supported Features diff --git a/Sources/LanguageServerProtocol/Additions/AsyncByteSequence.swift b/Sources/LanguageServerProtocol/Framing/AsyncByteSequence.swift similarity index 91% rename from Sources/LanguageServerProtocol/Additions/AsyncByteSequence.swift rename to Sources/LanguageServerProtocol/Framing/AsyncByteSequence.swift index 725e810..b4c2fb6 100644 --- a/Sources/LanguageServerProtocol/Additions/AsyncByteSequence.swift +++ b/Sources/LanguageServerProtocol/Framing/AsyncByteSequence.swift @@ -1,7 +1,7 @@ import Foundation /// Converts a sequence of Data objects into a sequence of bytes. -public struct AsyncByteSequence : AsyncSequence where Base : AsyncSequence, Base.Element == Data { +struct AsyncByteSequence : AsyncSequence where Base : AsyncSequence, Base.Element == Data { public typealias Element = UInt8 public struct AsyncIterator : AsyncIteratorProtocol { diff --git a/Sources/LanguageServerProtocol/Additions/AsyncMessageFramingSequence.swift b/Sources/LanguageServerProtocol/Framing/AsyncMessageFramingSequence.swift similarity index 94% rename from Sources/LanguageServerProtocol/Additions/AsyncMessageFramingSequence.swift rename to Sources/LanguageServerProtocol/Framing/AsyncMessageFramingSequence.swift index 1f0b116..d4ed177 100644 --- a/Sources/LanguageServerProtocol/Additions/AsyncMessageFramingSequence.swift +++ b/Sources/LanguageServerProtocol/Framing/AsyncMessageFramingSequence.swift @@ -1,7 +1,7 @@ import Foundation /// Sequence that reads data framed by the LSP base protocol specification. -public struct AsyncMessageFramingSequence : AsyncSequence where Base : AsyncSequence, Base.Element == UInt8 { +struct AsyncMessageFramingSequence : AsyncSequence where Base : AsyncSequence, Base.Element == UInt8 { public typealias Element = Data public struct AsyncIterator : AsyncIteratorProtocol { diff --git a/Sources/LanguageServerProtocol/Additions/DataChannel+MessageFraming.swift b/Sources/LanguageServerProtocol/Framing/DataChannel+MessageFraming.swift similarity index 100% rename from Sources/LanguageServerProtocol/Additions/DataChannel+MessageFraming.swift rename to Sources/LanguageServerProtocol/Framing/DataChannel+MessageFraming.swift diff --git a/Sources/LanguageServerProtocol/Additions/MessageFraming.swift b/Sources/LanguageServerProtocol/Framing/MessageFraming.swift similarity index 71% rename from Sources/LanguageServerProtocol/Additions/MessageFraming.swift rename to Sources/LanguageServerProtocol/Framing/MessageFraming.swift index 5e8249a..ec673a1 100644 --- a/Sources/LanguageServerProtocol/Additions/MessageFraming.swift +++ b/Sources/LanguageServerProtocol/Framing/MessageFraming.swift @@ -7,7 +7,7 @@ enum MessageFramingError: Error { case contentLengthMissing } -public struct MessageFraming { +struct MessageFraming { public static func frame(_ data: Data) -> Data { let length = data.count @@ -24,8 +24,4 @@ public struct MessageFraming { return (name, value) } - - public static func dataChannel(stdin: FileHandle, stdout: FileHandle, stderr: FileHandle, object: AnyObject?) -> DataChannel { - DataChannel(writeHandler: { _ in }, dataSequence: AsyncStream(unfolding: { nil })) - } } diff --git a/Tests/LanguageServerProtocolTests/AsyncMessageFramingSequenceTests.swift b/Tests/LanguageServerProtocolTests/AsyncMessageFramingSequenceTests.swift index 1fcf6e3..22a1881 100644 --- a/Tests/LanguageServerProtocolTests/AsyncMessageFramingSequenceTests.swift +++ b/Tests/LanguageServerProtocolTests/AsyncMessageFramingSequenceTests.swift @@ -1,7 +1,7 @@ import XCTest -import LanguageServerProtocol +@testable import LanguageServerProtocol -struct AsyncByteSequence : AsyncSequence { +struct AsyncDataSequence : AsyncSequence { typealias Element = UInt8 struct AsyncIterator : AsyncIteratorProtocol { @@ -44,7 +44,7 @@ final class AsyncMessageFramingSequenceTests: XCTestCase { func testBasicMessageDecode() async throws { let content = "{\"jsonrpc\":\"2.0\",\"params\":\"Something\"}" let message = "Content-Length: \(content.utf8.count)\r\n\r\n\(content)" - let sequence = AsyncByteSequence(data: Data(message.utf8)) + let sequence = AsyncDataSequence(data: Data(message.utf8)) let contentSequence = AsyncMessageFramingSequence(base: sequence) var iterator = contentSequence.makeAsyncIterator() @@ -64,7 +64,7 @@ final class AsyncMessageFramingSequenceTests: XCTestCase { let header2 = "Another-Header: Something\r\n" let header3 = "And-Another: third\r\n" let message = header1 + header2 + header3 + "\r\n" + content - let sequence = AsyncByteSequence(data: Data(message.utf8)) + let sequence = AsyncDataSequence(data: Data(message.utf8)) let contentSequence = AsyncMessageFramingSequence(base: sequence) var iterator = contentSequence.makeAsyncIterator()