diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-21 10:41:54 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-21 10:41:54 +0100 |
commit | 818aeb8a242bba5d8947ce2960e1af27d998f4fc (patch) | |
tree | f61bb82640fd05d1e62cb614ed51cb52eb471ff8 | |
parent | 2ad5bf8d17389e6711be65200ef918762eba9fdc (diff) | |
parent | a32dd9c478fec0c21fa7416c267bdf1d2416b355 (diff) |
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]>
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 5 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 2 |
2 files changed, 7 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index fec4feee5..8947ccf07 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -178,6 +178,11 @@ impl Config { | |||
178 | 178 | ||
179 | pub fn update(&mut self, json: serde_json::Value) { | 179 | pub fn update(&mut self, json: serde_json::Value) { |
180 | log::info!("Config::update({:#})", json); | 180 | 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 | |||
181 | let data = ConfigData::from_json(json); | 186 | let data = ConfigData::from_json(json); |
182 | 187 | ||
183 | self.with_sysroot = data.withSysroot; | 188 | self.with_sysroot = data.withSysroot; |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index a41f7f564..bb7c4c0c6 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -468,6 +468,8 @@ impl GlobalState { | |||
468 | } | 468 | } |
469 | (None, Some(mut configs)) => { | 469 | (None, Some(mut configs)) => { |
470 | if let Some(json) = configs.get_mut(0) { | 470 | 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. | ||
471 | let mut config = this.config.clone(); | 473 | let mut config = this.config.clone(); |
472 | config.update(json.take()); | 474 | config.update(json.take()); |
473 | this.update_configuration(config); | 475 | this.update_configuration(config); |