diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index a879e81fa74ed4ece8921f61cd3c0993092d59b1..053c922ba7ceac5bb79aad8eb66e8d0018c4b982 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -126,7 +126,7 @@ use text::{Anchor, BufferId, OffsetRangeExt, Point, Rope}; use toolchain_store::EmptyToolchainStore; use util::{ ResultExt as _, maybe, - paths::{PathStyle, SanitizedPath, compare_paths, is_absolute}, + paths::{PathStyle, SanitizedPath, is_absolute}, rel_path::RelPath, }; use worktree::{CreatedEntry, Snapshot, Traversal}; @@ -153,8 +153,6 @@ pub use lsp_store::{ }; pub use toolchain_store::{ToolchainStore, Toolchains}; const MAX_PROJECT_SEARCH_HISTORY_SIZE: usize = 500; -const MAX_SEARCH_RESULT_FILES: usize = 5_000; -const MAX_SEARCH_RESULT_RANGES: usize = 10_000; pub trait ProjectItem: 'static { fn try_open( @@ -4038,51 +4036,6 @@ impl Project { } } - fn sort_search_candidates( - &mut self, - search_query: &SearchQuery, - cx: &mut Context, - ) -> Receiver> { - let worktree_store = self.worktree_store.read(cx); - let mut buffers = search_query - .buffers() - .into_iter() - .flatten() - .filter(|buffer| { - let b = buffer.read(cx); - if let Some(file) = b.file() { - if !search_query.match_path(file.path().as_std_path()) { - return false; - } - if let Some(entry) = b - .entry_id(cx) - .and_then(|entry_id| worktree_store.entry_for_id(entry_id, cx)) - && entry.is_ignored - && !search_query.include_ignored() - { - return false; - } - } - true - }) - .collect::>(); - let (tx, rx) = smol::channel::unbounded(); - buffers.sort_by(|a, b| match (a.read(cx).file(), b.read(cx).file()) { - (None, None) => a.read(cx).remote_id().cmp(&b.read(cx).remote_id()), - (None, Some(_)) => std::cmp::Ordering::Less, - (Some(_), None) => std::cmp::Ordering::Greater, - (Some(a), Some(b)) => compare_paths( - (a.path().as_std_path(), true), - (b.path().as_std_path(), true), - ), - }); - for buffer in buffers { - tx.send_blocking(buffer.clone()).unwrap() - } - - rx - } - fn find_search_candidates_remote( &mut self, query: &SearchQuery, diff --git a/crates/project/src/project_search.rs b/crates/project/src/project_search.rs index ae20cad98b17057183fb132c18a859d77634aa0a..3de727349d2eb7cb7872f9f763048d39d2bed0c1 100644 --- a/crates/project/src/project_search.rs +++ b/crates/project/src/project_search.rs @@ -110,7 +110,9 @@ impl ProjectSearcher { else { return; }; - results.send(should_scan_rx).await; + if results.send(should_scan_rx).await.is_err() { + return; + }; } } } @@ -126,7 +128,9 @@ impl ProjectSearcher { // This math did not produce a match, hence skip it. continue; }; - paths_for_full_scan.send(successful_path).await; + if paths_for_full_scan.send(successful_path).await.is_err() { + return; + }; } } @@ -263,7 +267,8 @@ impl RequestHandler<'_> { { Some(LimitReached) } else { - self.publish_matches + _ = self + .publish_matches .send(SearchResult::Buffer { buffer, ranges }) .await; None diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rs index bfc7c300bb77e26700a80f5981c850026f4144aa..4ef6ed30f22efc6186d7642a3bcd303c5b34c842 100644 --- a/crates/project/src/worktree_store.rs +++ b/crates/project/src/worktree_store.rs @@ -999,93 +999,14 @@ impl WorktreeStore { matching_paths_rx } - fn scan_ignored_dir<'a>( - fs: &'a Arc, - snapshot: &'a worktree::Snapshot, - path: &'a RelPath, - query: &'a SearchQuery, - filter_tx: &'a Sender, - output_tx: &'a Sender>, - ) -> BoxFuture<'a, Result<()>> { - async move { - let abs_path = snapshot.absolutize(path); - let Some(mut files) = fs - .read_dir(&abs_path) - .await - .with_context(|| format!("listing ignored path {abs_path:?}")) - .log_err() - else { - return Ok(()); - }; - - let mut results = Vec::new(); - - while let Some(Ok(file)) = files.next().await { - let Some(metadata) = fs - .metadata(&file) - .await - .with_context(|| format!("fetching fs metadata for {abs_path:?}")) - .log_err() - .flatten() - else { - continue; - }; - if metadata.is_symlink || metadata.is_fifo { - continue; - } - let relative_path = file.strip_prefix(snapshot.abs_path())?; - let relative_path = RelPath::new(&relative_path, snapshot.path_style()) - .context("getting relative path")?; - results.push((relative_path.into_arc(), !metadata.is_dir)) - } - results.sort_by(|(a_path, _), (b_path, _)| a_path.cmp(b_path)); - for (path, is_file) in results { - if is_file { - if query.filters_path() { - let matched_path = if query.match_full_paths() { - let mut full_path = snapshot.root_name().as_std_path().to_owned(); - full_path.push(path.as_std_path()); - query.match_path(&full_path) - } else { - query.match_path(&path.as_std_path()) - }; - if !matched_path { - continue; - } - } - let (tx, rx) = oneshot::channel(); - output_tx.send(rx).await?; - filter_tx - .send(MatchingEntry { - respond: tx, - worktree_root: snapshot.abs_path().clone(), - path: ProjectPath { - worktree_id: snapshot.id(), - path: path.into_arc(), - }, - }) - .await?; - } else { - Self::scan_ignored_dir(fs, snapshot, &path, query, filter_tx, output_tx) - .await?; - } - } - Ok(()) - } - .boxed() - } - async fn find_candidate_paths( - fs: Arc, - snapshots: Vec<(worktree::Snapshot, WorktreeSettings)>, - open_entries: HashSet, - query: SearchQuery, - filter_tx: Sender, - output_tx: Sender>, + _: Arc, + _: Vec<(worktree::Snapshot, WorktreeSettings)>, + _: HashSet, + _: SearchQuery, + _: Sender, + _: Sender>, ) -> Result<()> { - for (snapshot, settings) in snapshots { - for entry in snapshot.entries(query.include_ignored(), 0) {} - } Ok(()) }