Skip to content

Commit

Permalink
remove unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty committed Nov 3, 2023
1 parent 2faf4d5 commit ac1e23b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions sway-lsp/src/core/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion sway-lsp/src/server_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ac1e23b

Please sign in to comment.