-
Notifications
You must be signed in to change notification settings - Fork 328
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
metamodel: should all enumerations "support custom values"? #1088
Comments
LSP makes a difference in being I will close the issue since this is intended. |
But then what does My point is just that at the moment if you're generating types to support enumerations, |
The specification doesn't have these custom values so we can't link to them.
If you can guarantee that you are always on the latest version of the specification then technically you don't. Since you should never get values that are not in the specification. |
Well, my concrete problem is apparently a langauge server producing a bunch of completion item kinds that are definitely not in the spec: haskell/lsp#460
Sorry, I mis-typed! I meant to say: link to the capability that defines the custom types. That then provides you with some useful information you could not have otherwise. Anyway: I think the point still stands. Any types generated from the metamodel must allow for enumeration values which are not in the specification version that corresponds to its metamodel, so must accept arbitrary unknown values. And I still believe that |
I would use it to generate a correct model to be for example for the server side. Take a completion item as an example. If kind would support custom values the expected code to generate would be: namespace CompletionItem {
create(kind: CompletionItemKind | number) {
....
}
} Since kind doesn't support custom values I generate: namespace CompletionItem {
create(kind: CompletionItemKind) {
....
}
} which makes it clear that you can't use arbitrary completion item kinds.
|
Doesn't that violate the spec claim that you always have to support additional enumeration values that you may not know about? That applies on the client side too - the client might be on a newer LSP spec and send you a value you don't know about yet. So your "no custom values" version is I think wrong? That's what I mean - in practice you have to treat all the enumerations as open regardless. |
But the sending side doesn't have to support custom values. So when a server creates a completion item it doesn't need to provide API to create a completion item with an unknown completion item kind. So the signature of the create function can be On the receiving side you need to handle unknown values. That is correct. But even there the strategy is as follows:
Hope that clarifies it. |
Okay, I see that you can do what you suggested. But it adds a lot of complexity: you now have
IMO it's far simpler to just use (something equivalent to) Personally, I think it would simplify the spec to just explicitly say that all enumerations are open, and that it's just that a few allow negotiation of specific additional entries. This nuance doesn't seem to add much except confusion to me 🤷 |
There is the perspective of a library provider and a library user. I see your points from a provider perspective but not from a user perspective.
This is up to the client to decide since it depends on the value set available in the client.
Then you basically loose all typing information for enumerations on the API level. |
Well, in Haskell we'd do it like this:
so you can't use the open case accidentally, you have to deliberately do it. No typing lost IMO. |
But this will not work in most other languages I know and making all enumerations to support custom values will at the end force lib maintainers to generate such code. If Haskell supports a type save way I have no problem if you treat all enumerations as if they support custom values. But for the other languages I think explicitly marking them adds value. |
The existence of the
supportsCustomValues
property naturally suggests that enumerations which do not have this property should not support custom values. But the specification says:This suggests that all enumerations must always accept unknown values. That seems to me to be essentially the same as saying that they should all have
supportsCustomValues
(which further suggests that the property should just be removed as it applies to all enumerations). Or is there some other meaning to "supports custom values" beyond this?The text was updated successfully, but these errors were encountered: