Skip to content

Spec compliance: null vs missing values #268

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

Closed
thomasjm opened this issue Dec 17, 2020 · 4 comments
Closed

Spec compliance: null vs missing values #268

thomasjm opened this issue Dec 17, 2020 · 4 comments

Comments

@thomasjm
Copy link
Collaborator

I just noticed that some types don't perfectly obey the LSP spec regarding when a value is allowed to be missing vs. when it must be present and null.

For example, if you look at InitializeParams, the processId field has type processId: integer | null, while the locale field is written locale?: string. Thus the latter is allowed to be missing but the former is not.

All optional fields in this package seem to be represented as Maybe, and encoded to JSON with omitNothingFields = True:

https://github.com/alanz/lsp/blob/36b655d9cc538f79b14c847ca383d97ffcc18162/lsp-types/src/Language/LSP/Types/Utils.hs#L109
https://github.com/alanz/lsp/blob/36b655d9cc538f79b14c847ca383d97ffcc18162/lsp-types/src/Language/LSP/Types/Initialize.hs#L44

This caused a problem for me when trying to write a Haskell client for a Python language server powered by pygls. Upon sending an initialize message with an empty processId, I get an NPE because it assumes the value will be present:

    self._server.process_id = params.processId
AttributeError: 'Object' object has no attribute 'processId'

To be compliant with the spec, perhaps we need to replace these "required optional values" with a different Maybe-like wrapper that always encodes to null when empty?

@thomasjm
Copy link
Collaborator Author

Note: wow, I am slightly sleep deprived and didn't notice that I already filed an issue for this back in May (#246). I think this one is the better write-up so I'll close the other one :)

@banacorn
Copy link
Contributor

I wonder if there's any existing package that offers "another Maybe".
But I figure it's not too much trouble to define one anyway, like how we treat union types.

@alanz
Copy link
Collaborator

alanz commented Jan 7, 2021

@thomasjm
Copy link
Collaborator Author

thomasjm commented Jul 5, 2023

Closed by lsp-types-2.x

@thomasjm thomasjm closed this as completed Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants