From 2a19459ee91ce2ee002c6d5fa4a53bc446d11d60 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 24 Mar 2020 21:43:22 +0200 Subject: [PATCH] Avoid failing on incorrect settings response --- crates/rust-analyzer/src/main_loop.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 0ab5b9ef52..79ea90cc94 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -414,18 +414,23 @@ fn loop_turn( log::error!("unexpected response: {:?}", resp) } - if Some(resp.id) == loop_state.configuration_request_id { + if Some(&resp.id) == loop_state.configuration_request_id.as_ref() { loop_state.configuration_request_id = None; + log::debug!("config update response: '{:?}", resp); let Response { error, result, .. } = resp; - match (error, result) { + + match ( + error, + result.map(|result| serde_json::from_value::>(result)), + ) { (Some(err), _) => { log::error!("failed to fetch the server settings: {:?}", err) } - (None, Some(result)) => { - let new_config = serde_json::from_value::>(result)? + (None, Some(Ok(new_config))) => { + let new_config = new_config .first() .expect( - "The client is expected to always send a non-empty config data", + "the client is expected to always send a non-empty config data", ) .to_owned(); world_state.update_configuration( @@ -434,6 +439,9 @@ fn loop_turn( get_feature_flags(&new_config, connection), ); } + (None, Some(Err(e))) => { + log::error!("failed to parse client config response: {}", e) + } (None, None) => { log::error!("received empty server settings response from the client") }