redhat-developer / redhat-developer/lsp4ij

`null` gets stripped from user-defined language server configurations

Open
#465 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
344
Forks
113
Avg merge
5h 22m
Merged PRs (30d)
15

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:

image

[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.


  1. According to the language server specification, the types of initializationOptions and return value of configuration requests are both LSPAny, which is a type union including LSPObject and null. LSPObject is defined as:

    type LSPObject = { [key: string]: LSPAny };

    So, LSPObjects are allowed to have string keys and null values.

  2. 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"}
    

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with UserDefinedLanguageServerDefinition.java and trace how its parsed configuration is passed into initializationOptions and workspace configuration responses. Reproduce the case using a configuration containing a null value, then verify that the value remains present in both messages sent to the language server.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.