Repository navigation
fix: keep explicit null settings in didChangeConfiguration - #1710
Merged
angelozerr merged 1 commit intoOct 19, 2026
Merged
Conversation
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.
|
Warning Review limit reachedThis 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. View limit details
Comment |
Contributor
|
@coderabbitai full review |
Contributor
|
LGTM, thanks @lagergren ! |
|
|
This was referenced Oct 28, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why?
workspace/didChangeConfigurationare dropped on the wire.nullto 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?
DidChangeConfigurationParamsthat serializes it with nulls preserved. This covers settings given as aJsonElement, aMapor an object: LSP4J's settings adapter callsGson.toJsonfor maps and objects, so the delegate comes from a copy of the Gson configured withserializeNulls().Implications
Explicit nulls in configuration settings now reach the server as sent. Only
workspace/didChangeConfigurationchanges; other messages, including replies toworkspace/configuration, are serialized as before.Changes
ConfigurationTypeAdapterFactory, registered inJSONUtils.configureCompatibilityAdapters.ConfigurationSerializationTest): a null reset survives a full serialize/parse round trip through LSP4J'sMessageJsonHandler; a null inMapsettings is kept; and after writing a configuration notification, aCompletionItemstill omits its unset optional fields.Manual verification
To reproduce, return settings containing an explicit null from
LanguageClientImpl#createSettingsand watchworkspace/didChangeConfigurationin the LSP console: without this change the null member is missing; with it, the member is sent asnull. I did not run this by hand; the tests cover it.Automated checks completed:
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 withjava.io.tmpdirunder the home directory, since the default macOS temporary directory gives unrelatedVfsRootAccessfailures with and without this change.