From 7dc711e9153165856447c1783bddd4c15242f4ee Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 16 Oct 2025 17:18:06 +0200 Subject: [PATCH] Iterate on CI fixes Co-authored-by: Smit Barmase --- Cargo.lock | 1 + crates/project/src/project.rs | 1 + crates/project/src/project_search.rs | 21 +++++++++++++++------ crates/project_benchmarks/Cargo.toml | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b75b8896ac0611bca05fdddc42aefea2aa2c09c3..34d31b72b771e050a778fd263f48d1d94ebc16cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12891,6 +12891,7 @@ dependencies = [ "project", "settings", "watch", + "workspace-hack", ] [[package]] diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index d5bc41799729760347412787b42b31f955ab7ca9..32844ef164ba142a9bc52979d798909a2f04cdb9 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -4008,6 +4008,7 @@ impl Project { fs: self.fs.clone(), buffer_store: self.buffer_store.clone(), worktrees: self.visible_worktrees(cx).collect::>(), + limit: project_search::Search::MAX_SEARCH_RESULT_FILES + 1, }; searcher.into_results(query, cx) } diff --git a/crates/project/src/project_search.rs b/crates/project/src/project_search.rs index ec863bbec14c68397c775218d954aba700316b0c..2dd8ac66c1b9674fad69159ae3b76f6f900dd2dd 100644 --- a/crates/project/src/project_search.rs +++ b/crates/project/src/project_search.rs @@ -30,11 +30,9 @@ pub(crate) struct Search { pub(crate) fs: Arc, pub(crate) buffer_store: Entity, pub(crate) worktrees: Vec>, + pub(crate) limit: usize, } -const MAX_SEARCH_RESULT_FILES: usize = 5_000; -const MAX_SEARCH_RESULT_RANGES: usize = 10_000; - /// Represents results of project search and allows one to either obtain match positions OR /// just the handles to buffers that may match the search. #[must_use] @@ -56,6 +54,8 @@ impl SearchResultsHandle { } impl Search { + pub(crate) const MAX_SEARCH_RESULT_FILES: usize = 5_000; + pub(crate) const MAX_SEARCH_RESULT_RANGES: usize = 10_000; /// Prepares a project search run. The result has to be used to specify whether you're interested in matching buffers /// or full search results. pub(crate) fn into_results(mut self, query: SearchQuery, cx: &mut App) -> SearchResultsHandle { @@ -70,7 +70,7 @@ impl Search { } else if let Some(entry_id) = buffer.entry_id(cx) { open_buffers.insert(entry_id); } else { - // limit = limit.saturating_sub(1); todo!() + self.limit -= self.limit.saturating_sub(1); unnamed_buffers.push(handle) }; } @@ -120,6 +120,7 @@ impl Search { scope.spawn(Self::maintain_sorted_search_results( sorted_search_results_rx, get_buffer_for_full_scan_tx, + self.limit, )) }); let provide_search_paths = cx.spawn(Self::provide_search_paths( @@ -223,8 +224,10 @@ impl Search { async fn maintain_sorted_search_results( rx: Receiver>, paths_for_full_scan: Sender, + limit: usize, ) { let mut rx = pin!(rx); + let mut matched = 0; while let Some(mut next_path_result) = rx.next().await { let Some(successful_path) = next_path_result.next().await else { // This math did not produce a match, hence skip it. @@ -233,6 +236,10 @@ impl Search { if paths_for_full_scan.send(successful_path).await.is_err() { return; }; + matched += 1; + if matched >= limit { + break; + } } } @@ -395,12 +402,14 @@ impl RequestHandler<'_> { .collect::>(); let matched_ranges = ranges.len(); - if self.matched_buffer_count.fetch_add(1, Ordering::Release) > MAX_SEARCH_RESULT_FILES + if self.matched_buffer_count.fetch_add(1, Ordering::Release) + > Search::MAX_SEARCH_RESULT_FILES || self .matches_count .fetch_add(matched_ranges, Ordering::Release) - > MAX_SEARCH_RESULT_RANGES + > Search::MAX_SEARCH_RESULT_RANGES { + _ = self.publish_matches.send(SearchResult::LimitReached).await; Some(LimitReached) } else { _ = self diff --git a/crates/project_benchmarks/Cargo.toml b/crates/project_benchmarks/Cargo.toml index 1171d468c649bdd9f76a44b3ef0155dc652c6034..ff1fdb5e107e478839c41121b599f4fff89e4892 100644 --- a/crates/project_benchmarks/Cargo.toml +++ b/crates/project_benchmarks/Cargo.toml @@ -16,6 +16,7 @@ node_runtime.workspace = true project.workspace = true settings.workspace = true watch.workspace = true +workspace-hack = { version = "0.1", path = "../../tooling/workspace-hack" } [lints] workspace = true