Skip to content

fix: keep explicit null settings in didChangeConfiguration - #1710

Merged
angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/configuration-null-settings
Oct 19, 2026
Merged

angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/configuration-null-settings

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Summary

Why?

  • LSP4J's Gson does not serialize nulls, so null members of the settings in workspace/didChangeConfiguration are dropped on the wire.
  • A server that uses null to mean "reset this setting to its default" never receives the reset. For example, {"compiler": {"sourceRoots": null, "modulePath": [], "enabled": false}} reaches the server as {"compiler": {"modulePath": [], "enabled": false}}.

How?

  • Register a type adapter for DidChangeConfigurationParams that serializes it with nulls preserved. This covers settings given as a JsonElement, a Map or an object: LSP4J's settings adapter calls Gson.toJson for maps and objects, so the delegate comes from a copy of the Gson configured with serializeNulls().
  • Restore the writer's previous null setting after writing, so optional protocol fields in all other messages remain omitted.

Implications

Explicit nulls in configuration settings now reach the server as sent. Only workspace/didChangeConfiguration changes; other messages, including replies to workspace/configuration, are serialized as before.

Changes

  • ConfigurationTypeAdapterFactory, registered in JSONUtils.configureCompatibilityAdapters.
  • 3 tests (ConfigurationSerializationTest): a null reset survives a full serialize/parse round trip through LSP4J's MessageJsonHandler; a null in Map settings is kept; and after writing a configuration notification, a CompletionItem still omits its unset optional fields.

Manual verification

To reproduce, return settings containing an explicit null from LanguageClientImpl#createSettings and watch workspace/didChangeConfiguration in the LSP console: without this change the null member is missing; with it, the member is sent as null. I did not run this by hand; the tests cover it.

Automated checks completed:

  • All 3 new tests fail against unchanged upstream cbe50d3d: the two null-preservation tests lose the null member, and the scoping test fails on its first assertion for the same reason. All pass with this change.
  • ./gradlew check --rerun-tasks --no-build-cache: 493 tests passed, 3 existing skips, no failures or errors. Run with java.io.tmpdir under the home directory, since the default macOS temporary directory gives unrelated VfsRootAccess failures with and without this change.

LSP4J's Gson omits null values, so a workspace/didChangeConfiguration
whose settings set a value to null lost that member on the wire. A
server that treats null as "reset to the default" never received the
reset: {"compiler": {"sourceRoots": null}} arrived as {"compiler": {}}.

Serialize DidChangeConfigurationParams with nulls preserved, for
settings given as a JsonElement, a Map or an object. The writer's null
setting is restored afterwards, so optional protocol fields in every
other message are still omitted.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 281f748e-d35a-4a86-9ca0-7bdefb3ec82d
📥 Commits

Reviewing files that changed from the base of the PR and between cbe50d3 and d15a777.

📒 Files selected for processing: 3
  • src/main/java/com/redhat/devtools/lsp4ij/JSONUtils.java
  • src/main/java/com/redhat/devtools/lsp4ij/internal/adapters/ConfigurationTypeAdapterFactory.java
  • src/test/java/com/redhat/devtools/lsp4ij/ConfigurationSerializationTest.java

Comment @coderabbitai help to get the list of available commands.

@angelozerr angelozerr added the bug Something isn't working label Oct 19, 2026
@angelozerr angelozerr added this to the 0.21.1 milestone Oct 19, 2026
@angelozerr angelozerr moved this to In Progress in Java Tooling Oct 19, 2026
@angelozerr

Copy link
Copy Markdown
Contributor

@coderabbitai full review

@angelozerr

Copy link
Copy Markdown
Contributor

LGTM, thanks @lagergren !

@angelozerr
angelozerr merged commit cc8b5d1 into redhat-developer:main Oct 19, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Java Tooling Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

@angelozerr I’ll review all changes in this PR again.

⚠️ Action not completed

Pull request is closed.

@lagergren
lagergren deleted the fix/configuration-null-settings branch October 26, 2026 21:43
angelozerr pushed a commit that referenced this pull request Nov 3, 2026
…#1847)

* fix: keep explicit nulls in a user-defined language server's settings

LSP4J's Gson omits nulls, so the null members of the JSON settings of a
user-defined language server were dropped on the wire. A server given
{"a": null, "b": "x"} as initialization options received {"b": "x"} in
initialize, and the same settings answered to workspace/configuration
lost "a" too. workspace/didChangeConfiguration has kept them since
#1710.

Register JsonSettingsTypeAdapterFactory with the compatibility
adapters. For InitializeParams it returns a subclass of LSP4J's
InitializeParamsTypeAdapter whose writeInitializationOptions writes
options given as a JsonElement with their nulls. LanguageClientImpl
#configuration now answers with a ConfigurationResult, a list whose
JsonElement settings the factory writes with their nulls, and its other
settings as LSP4J does. Options and settings given as maps or objects,
and the other fields of these messages, are written as before. The LSP
console trace uses the same adapters, so it shows the nulls too.

Tests:
- UserDefinedNullSettingsTest starts a user-defined language server,
  answered by the mock server, with {"a": null, "b": "x"} as its
  configuration and initialization options. Without the change, the
  initialization options and workspace/configuration tests fail with
  expected:<{"a":null,"b":"x"}> but was:<{"b":"x"}> (the reply as a
  one-element list); the didChangeConfiguration test passes on main
  too.
- ConfigurationSerializationTest: the initialize round trip keeps
  nested nulls and still leaves out the unset fields; it fails on main
  with but was:<{"b":"x","c":{},"e":[{}]}>. A workspace/configuration
  reply keeps the nulls of its JSON settings only; with the factory
  unregistered it fails with but was:<[{"b":[{}]},{"label":"name"},null]>.
- MockLanguageServer and MockWorkspaceService record the initialize
  and didChangeConfiguration params.

Full suite: 1110 tests, 3 skipped; only the 7 known macOS failures
("File accessed outside allowed roots"), which fail on main too.

* test: cover initialization options given as a map on the wire

Review of #1847 (CodeRabbit nitpick): the initialize wire test passed only a JsonElement, so no
test reached the branch of JsonSettingsTypeAdapterFactory that hands options of any other type to
LSP4J's own writeInitializationOptions.

The new test serializes an initialize request whose options are a Map through
handler().serialize(...) and checks the initializationOptions member. The map has no null
members: LSP4J's writer drops them, as it did before this pull request, and the test should not
pin that down.

Validation:
- ConfigurationSerializationTest: 6 tests, 0 failures.
- With the fallback replaced by out.nullValue(), only the new test fails
  (expected:<{"b":"x","c":{"d":[1,2]}}> but was:<null>).
- The full ./gradlew check was not run; the change adds one unit test.
angelozerr pushed a commit that referenced this pull request Nov 4, 2026
* docs: describe the 0.30.0 LSP and DAP changes that the docs miss

Several changes merged for 0.30.0 changed behavior that the docs
describe, or added behavior that they don't. LSPSupport.md still said
that pull diagnostics don't support related documents, which #1723
changed.

LSP:
- LSPSupport.md, Pull Diagnostics: previousResultId, and the
  relatedDocuments of either kind of report (#1723, #1735), in place
  of "It doesn't support the related documents."
- LSPSupport.md, Inline Completion: the trigger kind and the selected
  completion item (#1715).
- LSPSupport.md, Signature Help: the retrigger, the active parameter
  of each signature, and signatures without parameters (#1712, #1734).
- LSPSupport.md, Formatting: a file without an open editor (#1707).
- LSPSupport.md, new Did Change Watched Files section: the directories
  outside the project that watchers name, and the watchers of a stopped
  server (#1742). The support list links to it.
- UserGuide.md, Formatting: the Do not format patterns (#1817).
- UserDefinedLanguageServer.md, Configuration tab: null properties
  (#1710, #1847) and invalid JSON (#1828).
- DeveloperGuide.md, Workspace Configuration: null members of
  createSettings() (#1710, #1847).

DAP, dap/UserGuide.md:
- Exception breakpoint: the hint built from exceptionInfo (#1761). The
  screenshot of the stop at the exception moves back after the example
  it shows; the Smart Step Into section had come between them.
- Large variables: a page with fewer children than asked for is the
  last one (#1851).

Validation: each statement was checked against the code at d1a281d:
DocumentContentSynchronizer.refreshPullDiagnostic,
LSPInlineCompletionProvider.createParams, LSPParameterInfoHandler,
ClientCapabilitiesFactory, AbstractLSPFormattingService.canFormat,
LSPFormattingSupport, FileSystemWatchRoots, LanguageServerPanel
.validateJsonFields, JsonSettingsTypeAdapterFactory,
DAPClient.getExceptionHint and DAPVariableChildren. The other changes
merged for 0.30.0 are already documented, by their own PRs, #1784 and
#1810, or change nothing that the docs describe.

Limits: docs only, no new screenshots, no build run.

* docs: say that the JSON fields of a language server are read leniently

CodeRabbit noted that "must be valid JSON" is stricter than what
LSP4IJ accepts. The dialog's check (LanguageServerPanel.jsonError,
JsonParser.parseString) and the readers at run time
(SettingsHelper.parseJson, JsonParser.parseReader for the
initialization options, experimental and installer, Gson.fromJson for
the client configuration and workspace folders) all read leniently.

The paragraph now says which JSON is accepted and which isn't.

Validation: probed Gson 2.15.0's JsonParser.parseString and
Gson.fromJson. Both accept // and /* */ and # comments, unquoted names
and single-quoted strings, and both reject a trailing comma, a missing
brace and an unescaped backslash, such as in C:\Users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants