diff --git a/crates/project/src/project_tree.rs b/crates/project/src/project_tree.rs index bc1978b8f0..9bbe34c4af 100644 --- a/crates/project/src/project_tree.rs +++ b/crates/project/src/project_tree.rs @@ -8,9 +8,8 @@ mod toolchain_tree; use std::{ borrow::Borrow, - collections::{btree_map::Entry as TreeEntry, hash_map::Entry, BTreeMap}, + collections::{hash_map::Entry, BTreeMap}, ops::ControlFlow, - path::Path, sync::Arc, }; @@ -28,13 +27,11 @@ use crate::{ }; pub(crate) use server_tree::LanguageServerTree; -type IsRoot = bool; struct WorktreeRoots { - _roots: RootPathTrie, - roots: BTreeMap, BTreeMap>, + roots: RootPathTrie, worktree_store: Model, - worktree_subscription: Subscription, + _worktree_subscription: Subscription, } impl WorktreeRoots { @@ -44,16 +41,16 @@ impl WorktreeRoots { cx: &mut AppContext, ) -> Model { cx.new_model(|cx| Self { - _roots: RootPathTrie::new(), - roots: Default::default(), + roots: RootPathTrie::new(), worktree_store, - worktree_subscription: cx.subscribe(&worktree, |this: &mut Self, _, event, cx| { + _worktree_subscription: cx.subscribe(&worktree, |this: &mut Self, _, event, cx| { match event { WorktreeEvent::UpdatedEntries(changes) => { for (path, _, kind) in changes.iter() { match kind { worktree::PathChange::Removed => { - this.roots.remove(path); + let path = TriePath::from(path.as_ref()); + this.roots.remove(&path); } _ => {} } @@ -65,7 +62,8 @@ impl WorktreeRoots { else { return; }; - this.roots.remove(&entry.path); + let path = TriePath::from(entry.path.as_ref()); + this.roots.remove(&path); } } }), @@ -150,11 +148,11 @@ impl ProjectTree { let key = TriePath::from(&*path); - let mut roots = worktree_roots.update(cx, |this, _| { - this._roots.walk(&key, &mut |path, labels| { - for label in labels { + worktree_roots.update(cx, |this, _| { + this.roots.walk(&key, &mut |path, labels| { + for (label, presence) in labels { if let Some(slot) = roots.get_mut(label) { - debug_assert_eq!(slot, &mut None, "For a given path to a root of a worktree there should be at most project root"); + debug_assert_eq!(slot, &mut None, "For a given path to a root of a worktree there should be at most project root of {label:?} kind"); let _ = slot.insert(ProjectPath { worktree_id, path: path.clone(), @@ -168,7 +166,6 @@ impl ProjectTree { ControlFlow::Continue(()) } }); - roots }); // for ancestor in path.ancestors().skip(1) { diff --git a/crates/project/src/project_tree/path_trie.rs b/crates/project/src/project_tree/path_trie.rs index 998f8a91ab..4c91ee2e47 100644 --- a/crates/project/src/project_tree/path_trie.rs +++ b/crates/project/src/project_tree/path_trie.rs @@ -13,12 +13,17 @@ use std::{ /// a known root at `python/project` and the unexplored part is `subdir/another_subdir` - we need to run a scan on these 2 directories pub(super) struct RootPathTrie