Exclude ignored opened buffers from search

This commit is contained in:
Kirill Bulatov 2023-11-15 16:36:00 +02:00
parent ce2cfc6035
commit cafeba103b
2 changed files with 70 additions and 69 deletions

View file

@ -5570,8 +5570,16 @@ impl Project {
.iter() .iter()
.filter_map(|(_, b)| { .filter_map(|(_, b)| {
let buffer = b.upgrade(cx)?; let buffer = b.upgrade(cx)?;
let snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot()); let (is_ignored, snapshot) = buffer.update(cx, |buffer, cx| {
if let Some(path) = snapshot.file().map(|file| file.path()) { let is_ignored = buffer
.project_path(cx)
.and_then(|path| self.entry_for_path(&path, cx))
.map_or(false, |entry| entry.is_ignored);
(is_ignored, buffer.snapshot())
});
if is_ignored && !query.include_ignored() {
return None;
} else if let Some(path) = snapshot.file().map(|file| file.path()) {
Some((path.clone(), (buffer, snapshot))) Some((path.clone(), (buffer, snapshot)))
} else { } else {
unnamed_files.push(buffer); unnamed_files.push(buffer);

View file

@ -7,7 +7,7 @@ use anyhow::Result;
use client::Client; use client::Client;
use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions}; use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions};
use git::GITIGNORE; use git::GITIGNORE;
use gpui::{executor::Deterministic, ModelContext, ModelHandle, Task, TestAppContext}; use gpui::{executor::Deterministic, ModelContext, Task, TestAppContext};
use parking_lot::Mutex; use parking_lot::Mutex;
use postage::stream::Stream; use postage::stream::Stream;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
@ -880,14 +880,11 @@ async fn test_write_file(cx: &mut TestAppContext) {
} }
#[gpui::test] #[gpui::test]
async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) { async fn test_ignore_exclusions(cx: &mut TestAppContext) {
let dir = temp_tree(json!({ let dir = temp_tree(json!({
".git": {
"index": "blah"
},
".gitignore": "**/target\n/node_modules\n", ".gitignore": "**/target\n/node_modules\n",
"target": { "target": {
"index2": "blah2" "index": "blah2"
}, },
"node_modules": { "node_modules": {
".DS_Store": "", ".DS_Store": "",
@ -932,8 +929,9 @@ async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) {
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete()) cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await; .await;
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
tree.read_with(cx, |tree, _| {
check_worktree_entries( check_worktree_entries(
&tree, tree,
&[ &[
"src/foo/foo.rs", "src/foo/foo.rs",
"src/foo/another.rs", "src/foo/another.rs",
@ -942,14 +940,10 @@ async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) {
// "src/.DS_Store", // "src/.DS_Store",
// ".DS_Store", // ".DS_Store",
], ],
&[ &["target/index", "node_modules/prettier/package.json"],
".git/index",
"target/index2",
"node_modules/prettier/package.json",
],
&["src/lib.rs", "src/bar/bar.rs", ".gitignore"], &["src/lib.rs", "src/bar/bar.rs", ".gitignore"],
cx, )
); });
cx.update(|cx| { cx.update(|cx| {
cx.update_global::<SettingsStore, _, _>(|store, cx| { cx.update_global::<SettingsStore, _, _>(|store, cx| {
@ -960,13 +954,14 @@ async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) {
}); });
tree.flush_fs_events(cx).await; tree.flush_fs_events(cx).await;
cx.foreground().run_until_parked(); cx.foreground().run_until_parked();
tree.read_with(cx, |tree, _| {
check_worktree_entries( check_worktree_entries(
&tree, tree,
&[ &[
"node_modules/prettier/package.json", "node_modules/prettier/package.json",
"node_modules/.DS_Store", "node_modules/.DS_Store",
], ],
&[".git/index", "target/index2"], &["target/index"],
&[ &[
".gitignore", ".gitignore",
"src/lib.rs", "src/lib.rs",
@ -976,8 +971,8 @@ async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) {
"src/.DS_Store", "src/.DS_Store",
".DS_Store", ".DS_Store",
], ],
cx, )
); });
} }
#[gpui::test(iterations = 30)] #[gpui::test(iterations = 30)]
@ -2243,14 +2238,13 @@ fn git_status(repo: &git2::Repository) -> collections::HashMap<String, git2::Sta
.collect() .collect()
} }
#[track_caller]
fn check_worktree_entries( fn check_worktree_entries(
tree: &ModelHandle<Worktree>, tree: &Worktree,
expected_excluded_paths: &[&str], expected_excluded_paths: &[&str],
expected_ignored_paths: &[&str], expected_ignored_paths: &[&str],
expected_tracked_paths: &[&str], expected_tracked_paths: &[&str],
cx: &mut TestAppContext,
) { ) {
tree.read_with(cx, |tree, _| {
for path in expected_excluded_paths { for path in expected_excluded_paths {
let entry = tree.entry_for_path(path); let entry = tree.entry_for_path(path);
assert!( assert!(
@ -2272,5 +2266,4 @@ fn check_worktree_entries(
"expected path '{path}' to be tracked, but got entry: {entry:?}", "expected path '{path}' to be tracked, but got entry: {entry:?}",
); );
} }
});
} }