From 149e5fde364308f4dc7673664a227ea7b3da8e60 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 11 Nov 2024 12:20:04 -0800 Subject: [PATCH] Don't try to make project search and outline order match project panel (#20513) A straight alphabetical order is arguably clearer, and avoids a large initial delay when searching large repos. Release Notes: - Fixed a long initial delay when performing a project search in a large repository. --- crates/outline_panel/src/outline_panel.rs | 1 - crates/project/src/project_tests.rs | 55 ----------------------- crates/project/src/worktree_store.rs | 10 ++--- 3 files changed, 3 insertions(+), 63 deletions(-) diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index 6ebe783b5cc16b6c9addcd2be38aaadbd2e58314..a6d1903282864873dc9f4e491c336549c81191e3 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -2280,7 +2280,6 @@ impl OutlinePanel { // For a proper git status propagation, we have to keep the entries sorted lexicographically. entries.sort_by(|a, b| a.path.as_ref().cmp(b.path.as_ref())); worktree_snapshot.propagate_git_statuses(&mut entries); - project::sort_worktree_entries(&mut entries); (worktree_id, entries) }) .flat_map(|(worktree_id, entries)| { diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs index 2be927458ccfeabdbeb1448fcfb43d4e5d7e0d5c..490d2e67b5ccc07b57770caa8b1ddf1f7ccfea4b 100644 --- a/crates/project/src/project_tests.rs +++ b/crates/project/src/project_tests.rs @@ -4654,61 +4654,6 @@ async fn test_search_in_gitignored_dirs(cx: &mut gpui::TestAppContext) { ); } -#[gpui::test] -async fn test_search_ordering(cx: &mut gpui::TestAppContext) { - init_test(cx); - - let fs = FakeFs::new(cx.background_executor.clone()); - fs.insert_tree( - "/dir", - json!({ - ".git": {}, - ".gitignore": "**/target\n/node_modules\n", - "aaa.txt": "key:value", - "bbb": { - "index.txt": "index_key:index_value" - }, - "node_modules": { - "10 eleven": "key", - "1 two": "key" - }, - }), - ) - .await; - let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await; - - let mut search = project.update(cx, |project, cx| { - project.search( - SearchQuery::text( - "key", - false, - false, - true, - Default::default(), - Default::default(), - None, - ) - .unwrap(), - cx, - ) - }); - - fn file_name(search_result: Option, cx: &mut gpui::TestAppContext) -> String { - match search_result.unwrap() { - SearchResult::Buffer { buffer, .. } => buffer.read_with(cx, |buffer, _| { - buffer.file().unwrap().path().to_string_lossy().to_string() - }), - _ => panic!("Expected buffer"), - } - } - - assert_eq!(file_name(search.next().await, cx), "bbb/index.txt"); - assert_eq!(file_name(search.next().await, cx), "node_modules/1 two"); - assert_eq!(file_name(search.next().await, cx), "node_modules/10 eleven"); - assert_eq!(file_name(search.next().await, cx), "aaa.txt"); - assert!(search.next().await.is_none()) -} - #[gpui::test] async fn test_create_entry(cx: &mut gpui::TestAppContext) { init_test(cx); diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rs index dc67eedbc11bfacdd13ce2aa3205c90bd04c0363..db5ae67ba73db474f524f5fb27cd65962f36a2c1 100644 --- a/crates/project/src/worktree_store.rs +++ b/crates/project/src/worktree_store.rs @@ -23,7 +23,7 @@ use smol::{ stream::StreamExt, }; use text::ReplicaId; -use util::{paths::compare_paths, ResultExt}; +use util::ResultExt; use worktree::{Entry, ProjectEntryId, Worktree, WorktreeId, WorktreeSettings}; use crate::{search::SearchQuery, ProjectPath}; @@ -725,9 +725,7 @@ impl WorktreeStore { !metadata.is_dir, )) } - results.sort_by(|(a_path, a_is_file), (b_path, b_is_file)| { - compare_paths((a_path, *a_is_file), (b_path, *b_is_file)) - }); + 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() { @@ -782,9 +780,7 @@ impl WorktreeStore { ) -> Result<()> { let include_root = snapshots.len() > 1; for (snapshot, settings) in snapshots { - let mut entries: Vec<_> = snapshot.entries(query.include_ignored(), 0).collect(); - entries.sort_by(|a, b| compare_paths((&a.path, a.is_file()), (&b.path, b.is_file()))); - for entry in entries { + for entry in snapshot.entries(query.include_ignored(), 0) { if entry.is_dir() && entry.is_ignored { if !settings.is_path_excluded(&entry.path) { Self::scan_ignored_dir(