lsp: Skip serializing of params if unit type#46027
lsp: Skip serializing of params if unit type#46027SomeoneToIgnore merged 1 commit intozed-industries:mainfrom
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @Spirrwell on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
We require contributors to sign our Contributor License Agreement, and we don't have @Spirrwell on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
Thank you for the PR, I will come back to this next week most probably, one note after skimming: we do send both Shutdown and Exit messages with Line 950 in 5505e63 Line 988 in 5505e63 I'd expect we change this particular layer to accept If I search for |
|
I can look closer at potentially leaving the public API unchanged. It also looks like I missed the testing framework completely, so there is certainly more work to be done than I thought. I will put this in Draft until I iron those things out. I will probably have something more complete by next weekend. |
e29413b to
9b0470a
Compare
So, there are two things here I'm not sure how to tackle if we wanted to not change the public API.
Rust has the ability to have optionals of reference type, yes? To minimize additional overhead from going from I have updated my fork to make sure the tests build (I hope I got them all, the project diagnostics in Zed made that pretty easy if so!) However, I have noticed some run to run variance in tests passing. But, that seems to hold true even if I run them on the main branch of Zed, not in my fork. I'll wait for some more thoughts before I remove the Draft status. |
|
Both cases are our Prettier "protocol" and our tests, so I still do not understand why should we care and change half of the world for that. |
|
Well, I have a different solution that doesn't change half the world. I have updated the OP to reflect that. I suppose there are some restrictions by adding the There does exist code with what appears to be a similar purpose here: zed/crates/context_server/src/client.rs Line 71 in d4f6ca4 That I think would also work, but I believe that would incur the cost of serializing twice. Which since, there are only two things with no params, it seems silly to do. I'm gonna mark this as ready, and hope this is okay! |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Finally got the time to focus on reviews, sorry for dragging.
This is definitely a great way to solve things, better than the one I've been talking about.
'static in this context means that we do not borrow T (it has no ref, &'a, types) and seems totally fine: we do use various lsp::InlayHintFooRequest-like objects across the codebase.
Given it compiles and it's not a change in gpui public library code, it's totally fine and we can adjust it later any other way we need.
Than you!
Closes zed-industries#45994 Per the JSON-RPC specification, `params` "MUST be provided as a Structured value" or the member "MAY be omitted." See specification here: https://www.jsonrpc.org/specification#request_object The code was passing in unit `()` for params which serde_json was serializing to `null` which is not valid. This pulls request adds an `is_unit` function and annotates the `params` fields in the `Request` and `Notification` structs with the following: ```rs #[serde(default, skip_serializing_if = "is_unit")] ``` so that the field will be omitted if the type is unit. This does also introduce a `'static` bound to these structs. > [!WARNING] > While this seems to me like a simple change, I am not super familiar with Rust, please look at this PR with extra scrutiny. The last thing I want to do is break everyone's LSP integration. Release Notes: - LSP integrations: send language server shutdown requests with correct parameters
Closes #45994
Per the JSON-RPC specification,
params"MUST be provided as a Structured value" or the member "MAY be omitted." See specification here: https://www.jsonrpc.org/specification#request_objectThe code was passing in unit
()for params which serde_json was serializing tonullwhich is not valid.This pulls request adds an
is_unitfunction and annotates theparamsfields in theRequestandNotificationstructs with the following:#[serde(default, skip_serializing_if = "is_unit")]so that the field will be omitted if the type is unit. This does also introduce a
'staticbound to these structs.Warning
While this seems to me like a simple change, I am not super familiar with Rust, please look at this PR with extra scrutiny. The last thing I want to do is break everyone's LSP integration.
Release Notes: