-
Notifications
You must be signed in to change notification settings - Fork 764
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
Simplify protocol with regards to optional fields vs nullable fields. #87
Comments
Marked `InitializeParams.processId` and `InitializeParams.rootPath` as optional.
@bruno-medeiros agree with you, the protocol should not make use of undefined values but stick to I won't use LSP4J but VS Code to answer questions about the protocol since it is kind of a reference implementation. Concerning Unfortunately currently the specification does not reflect effects of input parameters as well as legality and effects of previous calls on a current call's result. The best one can do is to test the server against VS Code and the client against let say the TS server, since the protocol was initially defined for them. |
Yeah, I just made I could test it out with VS Code, but as far as I know there is no simple way to test out a custom LSP language server, at least for someone who is not familiar with Typescript and VS Code extension development (and I'm not familiar at all with any of those). And even if I test with VS Code - the official LSP implementation - there is the risk of some other LSP implementation interpreting things in a different way. |
@bruno-medeiros I think we just have to improve the spec for such properties. Regarding to testing with VS Code. You can have a look at this simple extension. It is probably a bit outdated but it should be straightforward to upgrade it. It starts a java process with Xtext LS: https://github.com/akosyakov/ride-vsclient/blob/master/src/extension.ts#L18. You can change this line to start a process with your LS. |
I will keep it open since there is indeed a mismatch between properties being null and undefined ones. We should make this better. In general I tend now to not make any properties optional (undefined) since undefined is very JS specific and the protocol is for more than one implementation language |
Yeah, another example where it's not clear a property is optional or not is TextDocumentItem's At the moment, I'm erroring on the cautional side, and try only to require a property if is strictly necessary for the underlying operation. |
Think about this again I am not sure if making all optional properties null is the right thing to do. We use JSON RPC and having a missing property in there is OK. The corresponding clients and server implemented in a different programming can then decide how they best map a missing attribute to their programing language. There is on exception to this: error and result values send in the JSON-RPC responses can not be missing by JSON RPC definition. I made a pass a while ago to clearly specify where I will close the issue since I think what we have in terms of the specification is clear enough right now (Please note that some properties instead of being optional are declared using |
From my understanding, in the protocol, a field marked as "?" is optional. If it's not marked as optional, the key must be present, however, the value can still be null. This duality is confusing and makes it harder to undertand the protocol. Let's take
InitializeParams
as an example:We can clearly see that the the
initializationOptions
key is optional, butrootPath
andprocessId
are not. However,rootPath
can be null, as the documentation specifies. But what aboutprocessId
? Can it be null? It's not clear from the spec. I'd imagine it shouldn't be null, if it's not explicitly mentioned in the documentation. Yet I've tried out LSP4J and it sendsprocessId
as null... Who is right?I propose that any field that can be null should be marked as optional (with "?"). Such that effectively, LSP states there is no semantic difference between a field that is missing (no key at all), and a field with key present, but with null value. This would eliminate ambiguities such as the example above.
This semantic distinction is even more important for languages such as Rust which don't have nullable types. (I'm writing an LSP SDK for Rust, and just realized this ambiguity will be a major pain)
The text was updated successfully, but these errors were encountered: