-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
remove defaults from optional fields #198
remove defaults from optional fields #198
Conversation
These aren't defined in the spec
I found a handful more places where pygls inserts defaults that are not given by the LSP specification, and removed them. If this second commit is more controversial than the first then happy to separate the two, but hopefully that's not the case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check inline comments, I am not sure about default values from the specs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works good, thanks!
@dimbleby it seems this broke progress notification #231 . It seems to be that in this pull request all default values were removed, so maybe it would also be OK to "keep" this code in |
I think it would be preferable to use pydantic features. Currently we explicitly exclude defaults from serialization - Line 382 in 720da69
I expect that not doing that should address this? Then I think we will need to suppress That is, I think you want this: diff --git a/pygls/protocol.py b/pygls/protocol.py
index 38d49b0..fa03031 100644
--- a/pygls/protocol.py
+++ b/pygls/protocol.py
@@ -379,7 +379,7 @@ class JsonRPCProtocol(asyncio.Protocol):
return
try:
- body = data.json(by_alias=True, exclude_unset=True, encoder=default_serializer)
+ body = data.json(by_alias=True, exclude_none=True, encoder=default_serializer)
logger.info('Sending data: %s', body)
body = body.encode(self.CHARSET) |
This addresses #217 and #231. I am still new to the project, so I may not have the full story. But it started with a somewhat far-reaching merge to remove defaults from all serialisable fields in the API: #198. This had the knock-on effect of regressing progress notifications, as reported by @MatejKastak in #217. One of their suggestions is to not use `exclude_unset=True`. Some months later @dimbleby suggested that `exclude_none=True` would also fix the issue[1]. Considering those 2 suggestions, let's replace `exclude_unset=True` with `exclude_none=True`. 1. #198 (comment)
This addresses #217 and #231. I am still new to the project, so I may not have the full story. But it started with a somewhat far-reaching merge to remove defaults from all serialisable fields in the API: #198. This had the knock-on effect of regressing progress notifications, as reported by @MatejKastak in #217. One of their suggestions is to not use `exclude_unset=True`. Some months later @dimbleby suggested that `exclude_none=True` would also fix the issue[1]. Considering those 2 suggestions, let's replace `exclude_unset=True` with `exclude_none=True`. 1. #198 (comment)
This addresses #217 and #231. I am still new to the project, so I may not have the full story. But it started with a somewhat far-reaching merge to remove defaults from all serialisable fields in the API: #198. This had the knock-on effect of regressing progress notifications, as reported by @MatejKastak in #217. One of their suggestions is to not use `exclude_unset=True`. Some months later @dimbleby suggested that `exclude_none=True` would also fix the issue[1]. Considering those 2 suggestions, let's replace `exclude_unset=True` with `exclude_none=True`. 1. #198 (comment)
Fixes #217, #231. I am still new to the project, so I may not have the full story. But it started with a somewhat far-reaching merge to remove defaults from all serialisable fields in the API: #198. This had the knock-on effect of regressing progress notifications, as reported by @MatejKastak in #217. One of their suggestions is to not use `exclude_unset=True`. Some months later @dimbleby suggested that `exclude_none=True` would also fix the issue[1]. Considering those 2 suggestions, let's replace `exclude_unset=True` with `exclude_none=True`. 1. #198 (comment)
Fixes #217, #231. I am still new to the project, so I may not have the full story. But it started with a somewhat far-reaching merge to remove defaults from all serialisable fields in the API: #198. This had the knock-on effect of regressing progress notifications, as reported by @MatejKastak in #217. One of their suggestions is to not use `exclude_unset=True`. Some months later @dimbleby suggested that `exclude_none=True` would also fix the issue[1]. Considering those 2 suggestions, let's replace `exclude_unset=True` with `exclude_none=True`. 1. #198 (comment)
Fixes #217, #231. I am still new to the project, so I may not have the full story. But it started with a somewhat far-reaching merge to remove defaults from all serialisable fields in the API: #198. This had the knock-on effect of regressing progress notifications, as reported by @MatejKastak in #217. One of their suggestions is to not use `exclude_unset=True`. Some months later @dimbleby suggested that `exclude_none=True` would also fix the issue[1]. Considering those 2 suggestions, let's replace `exclude_unset=True` with `exclude_none=True`. 1. #198 (comment)
Fixes #217, #231. I am still new to the project, so I may not have the full story. But it started with a somewhat far-reaching merge to remove defaults from all serialisable fields in the API: #198. This had the knock-on effect of regressing progress notifications, as reported by @MatejKastak in #217. One of their suggestions is to not use `exclude_unset=True`. Some months later @dimbleby suggested that `exclude_none=True` would also fix the issue[1]. Considering those 2 suggestions, let's replace `exclude_unset=True` with `exclude_none=True`. 1. #198 (comment)
This undoes the change in openlawlibrary#236 as well as bring back the explicit setting of non `None` default fields as suggested in [1] This commit also introduces serialization test cases that hopefully cover all the scenarios raised in openlawlibrary#245, openlawlibrary#231 and openlawlibrary#198 [1]: openlawlibrary#245 (comment)
This undoes the change in openlawlibrary#236 as well as bring back the explicit setting of non `None` default fields as suggested in [1] This commit also introduces serialization test cases that hopefully cover all the scenarios raised in openlawlibrary#245, openlawlibrary#231 and openlawlibrary#198 [1]: openlawlibrary#245 (comment)
This undoes the change in openlawlibrary#236 as well as bring back the explicit setting of non `None` default fields as suggested in [1] This commit also introduces serialization test cases that hopefully cover all the scenarios raised in openlawlibrary#245, openlawlibrary#231 and openlawlibrary#198 [1]: openlawlibrary#245 (comment)
This undoes the change in #236 as well as bring back the explicit setting of non `None` default fields as suggested in [1] This commit also introduces serialization test cases that hopefully cover all the scenarios raised in #245, #231 and #198 [1]: #245 (comment)
pygls is serializing too many fields
pygls 0.11.0 serializes certain optional fields, regardless of whether the server has explicitly set them - or whether the client has declared support for them.
Updating jedi-language-server to take pygls 0.11.0 I see that we are now returning various fields that we previously didn't eg on
CompletionItem
we always setdeprecated
andpreselect
. I'm pretty sure that this is wrong: not least, there aredeprecatedSupport
andpreselectSupport
onCompletionClientCapabilities
: if the client has not declared support for these things then presumably we're not supposed to return them.The approach I have taken is to remove all defaults for Optional fields:
None
, this had the effect of making the field not optional after all, as aboveNone
it was redundant to declare it as such, so it's just more compact not to botherThis pull request partially undoes f248002. I'm not sure what the motivation for that was, but flagging it in case I've broken something.
Code review checklist (for code reviewer to complete)