-
Notifications
You must be signed in to change notification settings - Fork 811
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
Clarify undefined/null vs empty array/empty object/false #355
Comments
On a related note, there seems to be some conflicting understandings of whether a optional field can be set to Is null fields allowed for |
The protocol uses the following rules: if a property can be assigned 'null' it must be explicitly listed as a type (e.g. I am reluctant to change this since I am pretty sure that causes swirls for someone else. The fact that the implementation tolerates this is insufficient error checking in the implementation. Any objection to close the issue? |
It sounds like the core question is:
|
I am not a fan of this. Consider the following example: interface CapOne {
propertyP?: {
value: number;
}
} This would mean that |
With regards to null vs the field being undefined. As far as I can tell from VS code's client it treats these the same. The rust language server as well as gluon's (the one I work on) use https://github.com/gluon-lang/languageserver-types which would serialize optional fields as null if they aren't set and both VS Code and https://github.com/autozimu/LanguageClient-neovim has handled To clarify, I am fine if nulls are supposed to be rejected for
Fair enough. Maybe this rule only applies if the inner object only has optional fields as well? Unless that feels to specific. |
The idea here is that if a type annotation doesn't include |
Yeah, that is fine. Only reason I have been passing nulls is that it is the default when serializing optionals in Rust, so since I weren't familiar with how this was specified in Typescript and nulls happened to work I never thought about it any further. |
Then I opt to close this issue. Any objections ? |
@dbaeumer There is also the case of the original question. Should undefined fields be treated equivalent to |
Due to #355 (comment) is would not do this for |
Ok. I don't want to drag this out much more but if the lack of a field and an empty array or object are not supposed to be treated equivalently we need to instead document how the client or server should handle the difference. Which, as far as I understand, means each of these optional fields will be defined to say that they ought to be treated the same (if my understating is wrong I guess that just means that documenting it is more important). (Some examples) Which seems a bit tedious. If there ever is a 4.0 it may be useful to remove this problem by requiring such fields to exist. |
On the flip side of the topic, is it fair to say that any non-optional fields that get sent as Take the result of a |
I don't think it needs to be specified that they must error on this though it would be nice if implementations did error (or warn perhaps) on things like that to prevent things being accidentally standardized. |
I will close the issue since I think we shouldn't change anything now. I added some clarification to the 3.17 version of the spec. |
There are a fair amount of optional fields on booleans and arrays where I think that the intention of leaving the field as
undefined
ornull
has the same meaning asfalse
or theempty array
. If this is the case we could simplify the deserialized structure in the Rust bindings a bit by removing the wrappingOption
and telling the deserializer to just deserialize tofalse/[]/{}
.https://github.com/gluon-lang/languageserver-types/blob/315294fcec89b87278d7f50348071bcf9e22f452/src/lib.rs#L920
Could we have the protocol define that, unless otherwise stated, that a
undefined
field has the same meaning asfalse
/[]
/{}
? Or if they should be handled differently then that should be stated.Examples
The parameters field on SignatureInformation
Most fields on the capabilities objects https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#workspaceclientcapabilities-define-capabilities-the-editor--tool-provides-on-the-workspace
The text was updated successfully, but these errors were encountered: