From fcdd0d9596cb3bad4e184b36ea3a9059245022cf Mon Sep 17 00:00:00 2001 From: Micah Date: Mon, 29 Jan 2024 16:25:32 -0500 Subject: [PATCH] workspace file removal improvement --- crates/language-server/src/workspace.rs | 45 ++++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/crates/language-server/src/workspace.rs b/crates/language-server/src/workspace.rs index 702f37817..73750654f 100644 --- a/crates/language-server/src/workspace.rs +++ b/crates/language-server/src/workspace.rs @@ -40,6 +40,7 @@ pub trait IngotFileContext { old_path: &str, new_path: &str, ) -> Result<()>; + fn remove_file(&mut self, db: &mut LanguageServerDatabase, path: &str) -> Result<()>; } pub struct LocalIngotContext { @@ -128,6 +129,14 @@ impl IngotFileContext for LocalIngotContext { } Ok(()) } + + fn remove_file(&mut self, db: &mut LanguageServerDatabase, path: &str) -> Result<()> { + let file = self.files.remove(path); + if let Some(file) = file { + file.remove_from_ingot(db)?; + } + Ok(()) + } } pub struct StandaloneIngotContext { @@ -210,6 +219,15 @@ impl IngotFileContext for StandaloneIngotContext { } Ok(()) } + + fn remove_file(&mut self, db: &mut LanguageServerDatabase, path: &str) -> Result<()> { + let file = self.files.remove(path); + if let Some(file) = file { + file.remove_from_ingot(db)?; + } + self.ingots.remove(path); + Ok(()) + } } pub struct Workspace { @@ -300,7 +318,7 @@ impl Workspace { let previous_ingot_context_file_keys = &ingot_context.files.keys().collect::>(); for path in previous_ingot_context_file_keys { if !actual_paths.contains(path) { - ingot_context.files.remove(path); + ingot_context.remove_file(db, path); } } @@ -391,6 +409,16 @@ impl IngotFileContext for Workspace { .rename_file(db, old_path, new_path) } } + + fn remove_file(&mut self, db: &mut LanguageServerDatabase, path: &str) -> Result<()> { + let ctx = get_containing_ingot(&mut self.ingot_contexts, path); + if let Some(ctx) = ctx { + ctx.remove_file(db, path) + } else { + self.standalone_ingot_context.remove_file(db, path)?; + Ok(()) + } + } } pub trait SyncableInputFile { @@ -465,21 +493,6 @@ impl SyncableIngotFileContext for Workspace { for ingot_path in ingot_paths { self.sync_ingot_files(db, &ingot_path); } - - let paths = glob::glob(&format!("{path}/src/**/*.fe")) - .ok() - .unwrap() - .filter_map(|p| { - p.ok() - .unwrap() - .to_str() - .map(std::string::ToString::to_string) - }) - .collect::>(); - - for path in paths { - self.input_from_file_path(db, &path); - } Ok(()) } }