-
Notifications
You must be signed in to change notification settings - Fork 61
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
Clean up JSON-RPC types and deserialization code #379
Conversation
The blanket implementation of `Deserialize<'de>` for `Cow<'de, str>` simply creates a `Cow::Owned`, which allocates on the heap. To avoid this, we must use a simple newtype with the `#[serde(borrow)]` attribute instead.
This lets us drop the manual `Serialize` and `Deserialize` implementations for this type in favor of the more concise `serde-derive` macros.
This change should improve the developer experience and should make unit testing easier, going forward.
Besides being more flexible than `Into`, this also addresses the Clippy lint triggered in CI.
d088269
to
ced93b7
Compare
Regarding microsoft/language-server-protocol#1686: It turns out that the This also means it should be safe to add the strict |
Added
std::str::FromStr
forRequest
andResponse
.From<jsonrpc::ErrorCode>
fori64
.Changed
Version
deserialization.Version
a private struct instead ofpub(crate)
.Copy
forVersion
because it's unnecessary.jsonrpc::Result<T>
andnot_initialized_error()
with all the error stuff, re-export it to parent module for public accessSerialize
/Deserialize
implementations forErrorCode
with#[serde(into/from)]
.Request
/RequestBuilder
tosrc/jsonrpc/request.rs
submodule.Response
tosrc/jsonrpc/response.rs
submodule.lsp-types
conversions asRequest::from_{notification,request}
doc comments.This pull request contains a grab-bag of miscellaneous improvements to the
jsonrpc
module that should improve deserialization performance slightly, but mostly make the code easier to read, grok, and maintain.It was also supposed to include some major improvements to deserializing request
params
andid
s, and handling invalid JSON-RPC messages in theMessage
type (see commits in the fullimprove-jsonrpc-deserialization
branch), but I ran into an inconsistency in the official LSP spec and chose to not pursue this for now. I've asked for clarification in microsoft/language-server-protocol#1686, filed earlier today.