From 1225f719fe920587ebbe4170fc5aee1d87eadc22 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Apr 2020 19:27:45 +0200 Subject: Fix pointer syntax --- crates/rust-analyzer/src/config.rs | 56 +++++++++++++++++++---------------- crates/rust-analyzer/src/main_loop.rs | 10 ++++--- 2 files changed, 36 insertions(+), 30 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index d95ed9ec7..3c8f55f1e 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -99,56 +99,60 @@ impl Default for Config { impl Config { #[rustfmt::skip] pub fn update(&mut self, value: &serde_json::Value) { + log::info!("Config::update({:#})", value); + let client_caps = self.client_caps.clone(); *self = Default::default(); self.client_caps = client_caps; - set(value, "publishDecorations", &mut self.publish_decorations); - set(value, "excludeGlobs", &mut self.exclude_globs); - set(value, "useClientWatching", &mut self.use_client_watching); - set(value, "lruCapacity", &mut self.lru_capacity); + set(value, "/publishDecorations", &mut self.publish_decorations); + set(value, "/excludeGlobs", &mut self.exclude_globs); + set(value, "/useClientWatching", &mut self.use_client_watching); + set(value, "/lruCapacity", &mut self.lru_capacity); - set(value, "inlayHintsType", &mut self.inlay_hints.type_hints); - set(value, "inlayHintsParameter", &mut self.inlay_hints.parameter_hints); - set(value, "inlayHintsChaining", &mut self.inlay_hints.chaining_hints); - set(value, "inlayHintsMaxLength", &mut self.inlay_hints.max_length); + set(value, "/inlayHintsType", &mut self.inlay_hints.type_hints); + set(value, "/inlayHintsParameter", &mut self.inlay_hints.parameter_hints); + set(value, "/inlayHintsChaining", &mut self.inlay_hints.chaining_hints); + set(value, "/inlayHintsMaxLength", &mut self.inlay_hints.max_length); if let Some(false) = get(value, "cargo_watch_enable") { self.check = None } else { if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets }) = &mut self.check { - set(value, "cargoWatchArgs", extra_args); - set(value, "cargoWatchCommand", command); - set(value, "cargoWatchAllTargets", all_targets); + set(value, "/cargoWatchArgs", extra_args); + set(value, "/cargoWatchCommand", command); + set(value, "/cargoWatchAllTargets", all_targets); } }; - set(value, "withSysroot", &mut self.with_sysroot); + set(value, "/withSysroot", &mut self.with_sysroot); if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt { - set(value, "rustfmtArgs", extra_args); + set(value, "/rustfmtArgs", extra_args); } - set(value, "cargoFeatures/noDefaultFeatures", &mut self.cargo.no_default_features); - set(value, "cargoFeatures/allFeatures", &mut self.cargo.all_features); - set(value, "cargoFeatures/features", &mut self.cargo.features); - set(value, "cargoFeatures/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); + set(value, "/cargoFeatures/noDefaultFeatures", &mut self.cargo.no_default_features); + set(value, "/cargoFeatures/allFeatures", &mut self.cargo.all_features); + set(value, "/cargoFeatures/features", &mut self.cargo.features); + set(value, "/cargoFeatures/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); + + set(value, "/vscodeLldb", &mut self.vscode_lldb); - set(value, "vscodeLldb", &mut self.vscode_lldb); + set(value, "/featureFlags/lsp.diagnostics", &mut self.publish_diagnostics); + set(value, "/featureFlags/notifications.workspace-loaded", &mut self.notifications.workspace_loaded); + set(value, "/featureFlags/notifications.cargo-toml-not-found", &mut self.notifications.cargo_toml_not_found); + set(value, "/featureFlags/completion.enable-postfix", &mut self.completion.enable_postfix_completions); + set(value, "/featureFlags/completion.insertion.add-call-parenthesis", &mut self.completion.add_call_parenthesis); + set(value, "/featureFlags/completion.insertion.add-argument-snippets", &mut self.completion.add_call_argument_snippets); + set(value, "/featureFlags/call-info.full", &mut self.call_info_full); - set(value, "featureFlags/lsp.diagnostics", &mut self.publish_diagnostics); - set(value, "featureFlags/notifications.workspace-loaded", &mut self.notifications.workspace_loaded); - set(value, "featureFlags/notifications.cargo-toml-not-found", &mut self.notifications.cargo_toml_not_found); - set(value, "featureFlags/completion.enable-postfix", &mut self.completion.enable_postfix_completions); - set(value, "featureFlags/completion.insertion.add-call-parenthesis", &mut self.completion.add_call_parenthesis); - set(value, "featureFlags/completion.insertion.add-argument-snippets", &mut self.completion.add_call_argument_snippets); - set(value, "featureFlags/call-info.full", &mut self.call_info_full); + log::info!("Config::update() = {:#?}", self); fn get<'a, T: Deserialize<'a>>(value: &'a serde_json::Value, pointer: &str) -> Option { value.pointer(pointer).and_then(|it| T::deserialize(it).ok()) } - fn set<'a, T: Deserialize<'a>>(value: &'a serde_json::Value, pointer: &str, slot: &mut T) { + fn set<'a, T: Deserialize<'a> + std::fmt::Debug>(value: &'a serde_json::Value, pointer: &str, slot: &mut T) { if let Some(new_value) = get(value, pointer) { *slot = new_value } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 00f92dbd5..45ae0ad9d 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -364,10 +364,12 @@ fn loop_turn( (Some(err), _) => { log::error!("failed to fetch the server settings: {:?}", err) } - (None, Some(new_config)) => { - let mut config = world_state.config.clone(); - config.update(&new_config); - world_state.update_configuration(config); + (None, Some(configs)) => { + if let Some(new_config) = configs.get(0) { + let mut config = world_state.config.clone(); + config.update(&new_config); + world_state.update_configuration(config); + } } (None, None) => { log::error!("received empty server settings response from the client") -- cgit v1.2.3