Skip to content

Commit fc74841

Browse files
committed
workspace file removal improvement
1 parent 2b43c77 commit fc74841

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

crates/language-server/src/workspace.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub trait IngotFileContext {
4040
old_path: &str,
4141
new_path: &str,
4242
) -> Result<()>;
43+
fn remove_file(&mut self, db: &mut LanguageServerDatabase, path: &str) -> Result<()>;
4344
}
4445

4546
pub struct LocalIngotContext {
@@ -128,6 +129,14 @@ impl IngotFileContext for LocalIngotContext {
128129
}
129130
Ok(())
130131
}
132+
133+
fn remove_file(&mut self, db: &mut LanguageServerDatabase, path: &str) -> Result<()> {
134+
let file = self.files.remove(path);
135+
if let Some(file) = file {
136+
file.remove_from_ingot(db)?;
137+
}
138+
Ok(())
139+
}
131140
}
132141

133142
pub struct StandaloneIngotContext {
@@ -210,6 +219,15 @@ impl IngotFileContext for StandaloneIngotContext {
210219
}
211220
Ok(())
212221
}
222+
223+
fn remove_file(&mut self, db: &mut LanguageServerDatabase, path: &str) -> Result<()> {
224+
let file = self.files.remove(path);
225+
if let Some(file) = file {
226+
file.remove_from_ingot(db)?;
227+
}
228+
self.ingots.remove(path);
229+
Ok(())
230+
}
213231
}
214232

215233
pub struct Workspace {
@@ -300,7 +318,7 @@ impl Workspace {
300318
let previous_ingot_context_file_keys = &ingot_context.files.keys().collect::<Vec<String>>();
301319
for path in previous_ingot_context_file_keys {
302320
if !actual_paths.contains(path) {
303-
ingot_context.files.remove(path);
321+
ingot_context.remove_file(db, path);
304322
}
305323
}
306324

@@ -391,6 +409,16 @@ impl IngotFileContext for Workspace {
391409
.rename_file(db, old_path, new_path)
392410
}
393411
}
412+
413+
fn remove_file(&mut self, db: &mut LanguageServerDatabase, path: &str) -> Result<()> {
414+
let ctx = get_containing_ingot(&mut self.ingot_contexts, path);
415+
if let Some(ctx) = ctx {
416+
ctx.remove_file(db, path)
417+
} else {
418+
self.standalone_ingot_context.remove_file(db, path)?;
419+
Ok(())
420+
}
421+
}
394422
}
395423

396424
pub trait SyncableInputFile {
@@ -465,21 +493,6 @@ impl SyncableIngotFileContext for Workspace {
465493
for ingot_path in ingot_paths {
466494
self.sync_ingot_files(db, &ingot_path);
467495
}
468-
469-
let paths = glob::glob(&format!("{path}/src/**/*.fe"))
470-
.ok()
471-
.unwrap()
472-
.filter_map(|p| {
473-
p.ok()
474-
.unwrap()
475-
.to_str()
476-
.map(std::string::ToString::to_string)
477-
})
478-
.collect::<Vec<String>>();
479-
480-
for path in paths {
481-
self.input_from_file_path(db, &path);
482-
}
483496
Ok(())
484497
}
485498
}

0 commit comments

Comments
 (0)