From 05e52fc8d08c80dddf60abe144222de5ae604928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Thu, 18 Aug 2022 04:09:50 +0100 Subject: [PATCH] Fix crashes when run with eglot as a client This just handles ConfigurationDidChange events in which the "mcglsl" key wasn't set without crashing, by ignoring them; if the configuration changed, but none of our configuration changed, there's nothing we need to update. Obviously there is still a lot that can go wrong here, but this allows running the language server with https://github.com/joaotavora/eglot, as that language server sends a ConfigurationDidChange on startup if any configuration is set (including for other language servers). --- server/main/src/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/main/src/main.rs b/server/main/src/main.rs index 7798e53..91b1292 100644 --- a/server/main/src/main.rs +++ b/server/main/src/main.rs @@ -651,14 +651,16 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer { log_level: String, } - let config: Configuration = from_value(params.settings.as_object().unwrap().get("mcglsl").unwrap().to_owned()).unwrap(); + if let Some(settings) = params.settings.as_object().unwrap().get("mcglsl") { + let config: Configuration = from_value(settings.to_owned()).unwrap(); - info!("got updated configuration"; "config" => params.settings.as_object().unwrap().get("mcglsl").unwrap().to_string()); + info!("got updated configuration"; "config" => params.settings.as_object().unwrap().get("mcglsl").unwrap().to_string()); - configuration::handle_log_level_change(config.log_level, |level| { - self.log_guard = None; // set to None so Drop is invoked - self.log_guard = Some(logging::set_logger_with_level(level)); - }) + configuration::handle_log_level_change(config.log_level, |level| { + self.log_guard = None; // set to None so Drop is invoked + self.log_guard = Some(logging::set_logger_with_level(level)); + }) + } }); }