From adc4bb54062bd0bdff8bfaecce238990f4225bac Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 20 Jul 2020 17:25:48 -0400 Subject: [PATCH 1/2] Allow 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. --- crates/rust-analyzer/src/config.rs | 5 +++++ crates/rust-analyzer/src/main_loop.rs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 68b2a2abdd..3a0aa41833 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -177,6 +177,11 @@ impl Config { pub fn update(&mut self, json: serde_json::Value) { log::info!("Config::update({:#})", json); + + if json.is_null() { + return; + } + let data = ConfigData::from_json(json); self.with_sysroot = data.withSysroot; diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index a41f7f5646..bb7c4c0c64 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -468,6 +468,8 @@ impl GlobalState { } (None, Some(mut configs)) => { if let Some(json) = configs.get_mut(0) { + // Note that json can be null according to the spec if the client can't + // provide a configuration. This is handled in Config::update below. let mut config = this.config.clone(); config.update(json.take()); this.update_configuration(config); From a32dd9c478fec0c21fa7416c267bdf1d2416b355 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 20 Jul 2020 18:11:32 -0400 Subject: [PATCH 2/2] Protect against `{}` --- crates/rust-analyzer/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 3a0aa41833..6870d032bd 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -178,7 +178,7 @@ impl Config { pub fn update(&mut self, json: serde_json::Value) { log::info!("Config::update({:#})", json); - if json.is_null() { + if json.is_null() || json.as_object().map_or(false, |it| it.is_empty()) { return; }