Repository navigation
Description
I'm setting configurations through the user-defined language server UI, and find that properties with values explicitly set as null are being stripped before the server receives them:
[Trace - 15:45:59] Sending request 'initialize - (1)'.
Params: {
<...>,
"initializationOptions": {
"field2": "name",
"field3": "nullaaaa"
},
[Trace - 15:50:03] Sending notification 'workspace/didChangeConfiguration'
Params: {
"settings": {
"fieldB": "name"
}
}
When I use the server to request the options/settings from the client, the fields which were set to null are now simply missing.
I expect preservation of fields set to null when sent from the client to the server1. The configuration object that's being retrieved from the UI2 shows that null is actually present in the client configuration object before being sent to the server, so something must be happening after reading the configuration.
-
According to the language server specification, the types of
initializationOptionsand return value of configuration requests are bothLSPAny, which is a type union includingLSPObjectandnull.LSPObjectis defined as:type LSPObject = { [key: string]: LSPAny };So,
LSPObjects are allowed to havestringkeys andnullvalues. -
Using the following modification of
com.redhat.devtools.lsp4ij.server.definition.launching.UserDefinedLanguageServerDefinition:... + import com.google.gson.JsonElement; import com.google.gson.JsonParser; ... public Object getLanguageServerConfiguration() { if (configuration == null && configurationContent != null && !configurationContent.isBlank()) { try { configuration = JsonParser.parseReader(new StringReader(configurationContent)); } catch (Exception e) { LOGGER.error("Error while parsing JSON configuration for the language server '" + getId() + "'", e); } } + LOGGER.error("CONFIGURATION IS: " + ((JsonElement)configuration).toString()); return configuration; }
IDE Logs:
SEVERE - com.redhat.devtools.lsp4ij.server.definition.launching.UserDefinedLanguageServerDefinition - CONFIGURATION IS: {"fieldA":null,"fieldB":"name"}

Activity
angelozerr commentedon Aug 22, 2024
Indeed that's strange. Is there any chance that you investigate more the problem?
bzoracler commentedon Aug 23, 2024
The problem is in
com.redhat.devtools.lsp4ij.console.explorer.TracingMessageConsumer, in the locations where it callsMessageJsonHandler.toString(...).org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler#toStringuses a defaultGsoninstance which doesn't serialisenulls.I made a temporary patch using a
Gsoninstance which turns onnullserialisation, and thenulls started appearing in the traces.angelozerr commentedon Aug 25, 2024
For configuration I undestand that it is better to see null fields, but for other lsp request responses message like completion , showing null fields are not interesting, will grow up the lsp message in the console which will polluate the lsp console.