Skip to content

Commit

Permalink
fix: remove symbols of removed files
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Jun 6, 2024
1 parent 6563e90 commit 414b032
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/lsp/src/tasks/script_indexing_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Backend {
.collect::<Vec<_>>();

if !diff_removed.is_empty() {
self.on_source_tree_files_removed(diff_removed).await;
self.on_source_tree_files_removed(diff_removed, content_path).await;
}
if !diff_added.is_empty() {
self.on_source_tree_files_added(diff_added, content_path).await;
Expand Down Expand Up @@ -107,12 +107,17 @@ impl Backend {
self.reporter.log_info(format!("Parsed discovered scripts in {:.3}s", duration.as_secs_f32())).await;
}

async fn on_source_tree_files_removed(&self, removed_files: Vec<SourceTreeFile>) {
for removed_file in removed_files {
// self.log_info(format!("Deprecated script: {}", removed_path)).await;
async fn on_source_tree_files_removed(&self, removed_files: Vec<SourceTreeFile>, content_path: &AbsPath) {
for removed_file in removed_files.iter() {
self.scripts.remove(removed_file.path.absolute());
self.reporter.purge_diagnostics(removed_file.path.absolute());
}

let paths = removed_files.into_iter()
.map(|f| f.path.clone())
.collect();

self.remove_symbols(content_path, paths).await;
}

async fn on_source_tree_files_modified(&self, modified_files: Vec<SourceTreeFile>) {
Expand Down
21 changes: 21 additions & 0 deletions crates/lsp/src/tasks/symbol_scan_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ impl Backend {
self.reporter.push_diagnostic(&loc_diag.path, loc_diag.diagnostic);
}
}

pub async fn remove_symbols(&self, content_path: &AbsPath, removed_source_paths: Vec<SourceTreePath>) {
let mut symtabs;
if let Ok(res) = self.symtabs.try_write() {
symtabs = res;
} else {
return;
}

let symtab;
if let Some(val) = symtabs.get_mut(content_path) {
symtab = val;
} else {
return;
}

for p in removed_source_paths.iter() {
symtab.remove_symbols_for_source(p.local());
self.reporter.clear_diagnostics(p.absolute(), DiagnosticDomain::SymbolAnalysis);
}
}
}

struct SymbolScanWorker {
Expand Down

0 comments on commit 414b032

Please sign in to comment.