Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

move semantic search project intialization to a subscribe event for workspace created

KCaverlya1519e4c38bf
diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs
index 357aca2ed86..b0ec7219d13 100644
--- a/crates/search/src/project_search.rs
+++ b/crates/search/src/project_search.rs
@@ -844,16 +844,6 @@ impl ProjectSearchView {
.detach();
let filters_enabled = false;
- // Initialize Semantic Index if Needed
- if SemanticIndex::enabled(cx) {
- let model = model.read(cx);
- project = model.project.clone();
- SemanticIndex::global(cx).map(|semantic| {
- dbg!("Initializing project");
- semantic.update(cx, |this, cx| this.initialize_project(project.clone(), cx));
- });
- }
-
// Check if Worktrees have all been previously indexed
let mut this = ProjectSearchView {
search_id: model.read(cx).search_id,
diff --git a/crates/semantic_index/src/semantic_index.rs b/crates/semantic_index/src/semantic_index.rs
index cca63c00aaf..fed320becdc 100644
--- a/crates/semantic_index/src/semantic_index.rs
+++ b/crates/semantic_index/src/semantic_index.rs
@@ -35,6 +35,7 @@ use util::{
paths::EMBEDDINGS_DIR,
ResultExt,
};
+use workspace::WorkspaceCreated;
const SEMANTIC_INDEX_VERSION: usize = 7;
const EMBEDDINGS_BATCH_SIZE: usize = 80;
@@ -56,6 +57,22 @@ pub fn init(
return;
}
+ cx.subscribe_global::<WorkspaceCreated, _>({
+ move |event, mut cx| {
+ let Some(semantic_index) = SemanticIndex::global(cx) else { return; };
+ let workspace = &event.0;
+ if let Some(workspace) = workspace.upgrade(cx) {
+ let project = workspace.read(cx).project().clone();
+ if project.read(cx).is_local() {
+ semantic_index.update(cx, |index, cx| {
+ index.initialize_project(project, cx);
+ });
+ }
+ }
+ }
+ })
+ .detach();
+
cx.spawn(move |mut cx| async move {
let semantic_index = SemanticIndex::new(
fs,
@@ -133,7 +150,6 @@ impl ProjectState {
async move {
while let Ok(operation) = job_queue_rx.recv().await {
Self::update_queue(&mut worktree_queue, operation);
- dbg!(worktree_queue.len());
}
}
});