Skip to content

Commit 37ad994

Browse files
authored
Use default settings if initialization options is empty or not provided (#11566)
## Summary This PR fixes the bug to avoid flattening the global-only settings for the new server. This was added in #11497, possibly to correctly de-serialize an empty value (`{}`). But, this lead to a bug where the configuration under the `settings` key was not being read for global-only variant. By using #[serde(default)], we ensure that the settings field in the `GlobalOnly` variant is optional and that an empty JSON object `{}` is correctly deserialized into `GlobalOnly` with a default `ClientSettings` instance. fixes: #11507 ## Test Plan Update the snapshot and existing test case. Also, verify the following settings in Neovim: 1. Nothing ```lua ruff = { cmd = { '/Users/dhruv/work/astral/ruff/target/debug/ruff', 'server', '--preview', }, } ``` 2. Empty dictionary ```lua ruff = { cmd = { '/Users/dhruv/work/astral/ruff/target/debug/ruff', 'server', '--preview', }, init_options = vim.empty_dict(), } ``` 3. Empty `settings` ```lua ruff = { cmd = { '/Users/dhruv/work/astral/ruff/target/debug/ruff', 'server', '--preview', }, init_options = { settings = vim.empty_dict(), }, } ``` 4. With some configuration: ```lua ruff = { cmd = { '/Users/dhruv/work/astral/ruff/target/debug/ruff', 'server', '--preview', }, init_options = { settings = { configuration = '/tmp/ruff-repro/pyproject.toml', }, }, } ```
1 parent 246a338 commit 37ad994

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2-
"codeAction": {
3-
"disableRuleComment": {
4-
"enable": false
5-
}
6-
},
7-
"lint": {
8-
"ignore": ["RUF001"],
9-
"run": "onSave"
10-
},
11-
"fixAll": false,
12-
"logLevel": "warn",
13-
"lineLength": 80,
14-
"exclude": ["third_party"]
2+
"settings": {
3+
"codeAction": {
4+
"disableRuleComment": {
5+
"enable": false
6+
}
7+
},
8+
"lint": {
9+
"ignore": ["RUF001"],
10+
"run": "onSave"
11+
},
12+
"fixAll": false,
13+
"logLevel": "warn",
14+
"lineLength": 80,
15+
"exclude": ["third_party"]
16+
}
1517
}

crates/ruff_server/src/session/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ enum InitializationOptions {
130130
workspace_settings: Vec<WorkspaceSettings>,
131131
},
132132
GlobalOnly {
133-
#[serde(flatten)]
133+
#[serde(default)]
134134
settings: ClientSettings,
135135
},
136136
}

0 commit comments

Comments
 (0)