From ac1e23b2ae8c2052e8ce793e86a4de31734f8a4f Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Fri, 3 Nov 2023 15:57:49 +1100 Subject: [PATCH] remove unwrap --- sway-lsp/src/core/session.rs | 5 +++-- sway-lsp/src/server_state.rs | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sway-lsp/src/core/session.rs b/sway-lsp/src/core/session.rs index 106aa071534..45377054a47 100644 --- a/sway-lsp/src/core/session.rs +++ b/sway-lsp/src/core/session.rs @@ -148,11 +148,12 @@ impl Session { } /// Clean up memory in the [TypeEngine] and [DeclEngine] for the user's workspace. - pub fn garbage_collect(&self) { - let path = self.sync.temp_dir().unwrap(); + pub fn garbage_collect(&self) -> Result<(), LanguageServerError> { + let path = self.sync.temp_dir()?; if let Some(module_id) = self.engines.read().se().get_module_id(&path) { self.engines.write().clear_module(&module_id); } + Ok(()) } /// Write the result of parsing to the session. diff --git a/sway-lsp/src/server_state.rs b/sway-lsp/src/server_state.rs index 15761802d6d..99af28f79a6 100644 --- a/sway-lsp/src/server_state.rs +++ b/sway-lsp/src/server_state.rs @@ -122,7 +122,9 @@ async fn run_blocking_parse_project( // as the project hasn't been parsed yet. if !session.token_map().is_empty() { // This operation is fairly expensive. Perhaps we should call it less often than every keystroke? - session.garbage_collect(); + if let Err(err) = session.garbage_collect() { + tracing::error!("Unable to perform garbage collection: {}", err.to_string()); + } } let parse_result = session::parse_project(&uri, &session.engines.read())?; let (errors, warnings) = parse_result.diagnostics.clone();