Skip to content

Commit 818aeb8

Browse files
bors[bot]kjeremy
andauthored
Merge #5467
5467: Allow null or empty values for configuration r=matklad a=kjeremy Allow the client to respond to `workspace/configuration` with `null` values. This is allowed per the spec if the client doesn't know about the configuration we've requested. This also protects against `null` or `{}` during initialize. I'm not sure if we want to interpret `{}` as "don't change anything" but I think that's a reasonable approach to take. This should help with LSP clients working out of the box. Fixes #5464 Co-authored-by: kjeremy <[email protected]>
2 parents 2ad5bf8 + a32dd9c commit 818aeb8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ impl Config {
178178

179179
pub fn update(&mut self, json: serde_json::Value) {
180180
log::info!("Config::update({:#})", json);
181+
182+
if json.is_null() || json.as_object().map_or(false, |it| it.is_empty()) {
183+
return;
184+
}
185+
181186
let data = ConfigData::from_json(json);
182187

183188
self.with_sysroot = data.withSysroot;

crates/rust-analyzer/src/main_loop.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ impl GlobalState {
468468
}
469469
(None, Some(mut configs)) => {
470470
if let Some(json) = configs.get_mut(0) {
471+
// Note that json can be null according to the spec if the client can't
472+
// provide a configuration. This is handled in Config::update below.
471473
let mut config = this.config.clone();
472474
config.update(json.take());
473475
this.update_configuration(config);

0 commit comments

Comments
 (0)