Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate serde into LanguageServerCodec #215

Merged
merged 2 commits into from
Aug 20, 2020

Conversation

ebkalderon
Copy link
Owner

Changed

  • Change LanguageServerCodec to encode/decode T: Serialize + DeserializeOwned items instead of String objects.
  • Simplify Server code a bit, now that LanguageServerCodec handles JSON de/serialization directly.
  • Move incoming and outgoing message trace!() logs from transport.rs to codec.rs.

Fixed

  • Fix decoder infinite loop upon encountering invalid UTF-8 in an otherwise valid LSP message.

Instead of processing message headers in codec.rs and de/serializing JSON separately in transport.rs, both now occur in one step inside the codec's Encoder and Decoder implementations. This simplification happened to also uncover a bug in the codec's parse error recovery, which has been fixed.

@ebkalderon ebkalderon self-assigned this Aug 20, 2020
@ebkalderon ebkalderon force-pushed the integrate-serde-into-codec branch from b20c154 to 135417a Compare August 20, 2020 18:48
Rather than handling serialization and deserialization in a second step
after decoding the message header, we can instead integrate `serde_json`
directly into the message encoding/decoding steps. This simplifies the
`Server` code a bit.
When decoding an incoming message, we must always advance the byte
stream and reset `remaining_msg_bytes` to 0, or else we will get stuck
in an infinite loop. This commit fixes an incorrect `?` which would halt
parsing early upon encountering invalid UTF-8 sequences inside an
otherwise valid LSP message. Aborting early without advancing the byte
stream would get `FramedRead` in `transport.rs` stuck trying to decode
the same message over and over, leading to the aforementioned infinite
loop.
@ebkalderon ebkalderon force-pushed the integrate-serde-into-codec branch from 135417a to ff65a7b Compare August 20, 2020 18:52
@ebkalderon ebkalderon merged commit 5ad00e7 into master Aug 20, 2020
@ebkalderon ebkalderon deleted the integrate-serde-into-codec branch August 20, 2020 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant