ebkalderon / tower-lsp

Language Server Protocol implementation written in Rust
Apache License 2.0
962 stars 54 forks source link

Refactor ::serve to multiple variants #347

Closed silvanshade closed 1 year ago

silvanshade commented 2 years ago

@ebkalderon This PR refactors the Server::serve function into multiple variants, one of which allows for passing a I: Stream<Item = Message> and O: Sink<Message> rather than just I: AsyncRead and O: AsyncWrite.

This change was motivated by my experience working with tower-lsp for a wasm target in the tower-lsp-web-demo project and is also relevant to #341.

Since in that case no data was actually be processed over stdin/stdout, there was no real justification to use byte-based framed IO with messages delimited by Content-Length headers, and a significant amount of code was needed just to convert from the underlying web ReadableStream and WritableStream based data structures used internally for server client communication into something that could interface with tower-lsp.

With this PR, instead I could simply use Server::serve_messages from tower-lsp for that project.