Repository navigation
Description
JavaScript is very special with the seperation between null and undefined. In many other languages such as PHP, if a property has not been set, it is null. Consequently, not-set properties will also JSON-encode to null. There is no way to find out if a property is null because it has been set to null or because the property was not set.
My PHP language server responds with this response to the initialize request:
Content-Type: application/vscode-jsonrpc; charset=utf8
Content-Length: 493
{
"id":0,
"result":{
"capabilities":{
"textDocumentSync":1,
"hoverProvider":null,
"completionProvider":null,
"signatureHelpProvider":null,
"definitionProvider":null,
"referencesProvider":null,
"documentHighlightProvider":null,
"documentSymbolProvider":true,
"workspaceSymbolProvider":null,
"codeActionProvider":null,
"codeLensProvider":null,
"documentFormattingProvider":null,
"documentRangeFormattingProvider":null,
"documentOnTypeFormattingProvider":null,
"renameProvider":null
}
},
"error":null,
"jsonrpc":"2.0"
}For a human reading this, it is clear that the request was successful, result is defined and error is not defined. But the language client explicitely checks if error !== undefined here. This makes VS Code treat the request as a failed, and then fail with Cannot read property 'code' of null, because it tries to read the code property of the error.
It makes it impossible to implement the language server protocol with classes in any language that does not have a dedicated undefined type. Please just treat null as undefined.
value != undefined will be true for both null and undefined.
Activity
dbaeumer commentedon Sep 8, 2016
Felix Becker (@felixfbecker) we do treat undefined and null 'equal' in the protocol.I even think that I state somewhere that you should send null not undefined since undefined doesn't exist in other languages. On our server side we even have code that explicitly exchanges undefined with null. And the client code always treats undefined and null as 'equal'
However in the case you pointed out I explicitly tried to followed the JSON RPC spec which states:
Would it be possible for your php json library to have two type of Response. FailedResponse and SuccessResponse.
felixfbecker commentedon Sep 8, 2016
Good to know you keep it in mind :)
I knew about the protocol, but I thought not following it strictly here would be more beneficial. But using subclasses is a better solution.