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

remove defaults from optional fields #198

Merged
merged 3 commits into from
Jun 21, 2021
Merged

remove defaults from optional fields #198

merged 3 commits into from
Jun 21, 2021

Conversation

dimbleby
Copy link
Contributor

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 set deprecated and preselect. I'm pretty sure that this is wrong: not least, there are deprecatedSupport and preselectSupport on CompletionClientCapabilities: 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:

  • when the default was not None, this had the effect of making the field not optional after all, as above
  • when the default was None it was redundant to declare it as such, so it's just more compact not to bother

This 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)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly
  • CONTRIBUTORS.md was updated, as appropriate
  • Changelog has been updated, as needed (see CHANGELOG.md)

These aren't defined in the spec
@dimbleby
Copy link
Contributor Author

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.

Copy link
Contributor

@danixeee danixeee left a 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.

Copy link
Contributor

@danixeee danixeee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works good, thanks!

@danixeee danixeee merged commit b84098c into openlawlibrary:master Jun 21, 2021
@perrinjerome
Copy link
Contributor

This pull request partially undoes f248002. I'm not sure what the motivation for that was, but flagging it in case I've broken something.

@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 __init__ ?

@dimbleby
Copy link
Contributor Author

dimbleby commented Apr 3, 2022

I think it would be preferable to use pydantic features. Currently we explicitly exclude defaults from serialization -

body = data.json(by_alias=True, exclude_unset=True, encoder=default_serializer)
.

I expect that not doing that should address this?

Then I think we will need to suppress None defaults, but that can be done by exclude_none=True

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)

tombh added a commit that referenced this pull request May 31, 2022
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)
tombh added a commit that referenced this pull request May 31, 2022
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)
tombh added a commit that referenced this pull request May 31, 2022
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)
tombh added a commit that referenced this pull request Jun 1, 2022
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)
tombh added a commit that referenced this pull request Jun 1, 2022
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)
tombh added a commit that referenced this pull request Jun 1, 2022
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)
tombh added a commit that referenced this pull request Jun 1, 2022
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)
alcarney added a commit to alcarney/pygls that referenced this pull request Jul 4, 2022
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)
alcarney added a commit to alcarney/pygls that referenced this pull request Jul 4, 2022
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)
alcarney added a commit to alcarney/pygls that referenced this pull request Jul 4, 2022
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)
tombh pushed a commit that referenced this pull request Jul 4, 2022
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)
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.

3 participants