Add support for excluding files based on .gitignore
(#26636)
Closes: #17543 Release Notes: - **New Feature:** Introduced the ability to automatically remove files and directories from the Zed project panel that are specified in `.gitignore`. - **Configuration Option:** This behavior can be controlled via the new `project_panel.hide_gitignore` setting. By setting it to `true`, files listed in `.gitignore` will be excluded from the project panel. - **Toggle:** Ability to toggle this setting using the action `ProjectPanel::ToggleHideGitIgnore` ```json "project_panel": { "hide_gitignore": true }, ``` This results in a cleaner and easier to browse project panel for projects that generate a lot of object files like `xv6-riscv` or `linux` without needing to tweak `file_scan_exclusions` on `settings.json` **Preview:** - With `"project_panel.hide_gitignore": false` (default, this is how zed currently looks)  - With `"project_panel.hide_gitignore": true`  - Action `ProjectPanel::ToggleHideGitIgnore` 
This commit is contained in:
parent
9eacac62a9
commit
82536f5243
4 changed files with 196 additions and 8 deletions
|
@ -3735,6 +3735,172 @@ async fn test_basic_file_deletion_scenarios(cx: &mut gpui::TestAppContext) {
|
|||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_deletion_gitignored(cx: &mut gpui::TestAppContext) {
|
||||
init_test_with_editor(cx);
|
||||
|
||||
let fs = FakeFs::new(cx.executor().clone());
|
||||
fs.insert_tree(
|
||||
path!("/root"),
|
||||
json!({
|
||||
"aa": "// Testing 1",
|
||||
"bb": "// Testing 2",
|
||||
"cc": "// Testing 3",
|
||||
"dd": "// Testing 4",
|
||||
"ee": "// Testing 5",
|
||||
"ff": "// Testing 6",
|
||||
"gg": "// Testing 7",
|
||||
"hh": "// Testing 8",
|
||||
"ii": "// Testing 8",
|
||||
".gitignore": "bb\ndd\nee\nff\nii\n'",
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), [path!("/root").as_ref()], cx).await;
|
||||
let workspace = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
let cx = &mut VisualTestContext::from_window(*workspace, cx);
|
||||
|
||||
// Test 1: Auto selection with one gitignored file next to the deleted file
|
||||
cx.update(|_, cx| {
|
||||
let settings = *ProjectPanelSettings::get_global(cx);
|
||||
ProjectPanelSettings::override_global(
|
||||
ProjectPanelSettings {
|
||||
hide_gitignore: true,
|
||||
..settings
|
||||
},
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
||||
let panel = workspace.update(cx, ProjectPanel::new).unwrap();
|
||||
|
||||
select_path(&panel, "root/aa", cx);
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..10, cx),
|
||||
&[
|
||||
"v root",
|
||||
" .gitignore",
|
||||
" aa <== selected",
|
||||
" cc",
|
||||
" gg",
|
||||
" hh"
|
||||
],
|
||||
"Initial state should hide files on .gitignore"
|
||||
);
|
||||
|
||||
submit_deletion(&panel, cx);
|
||||
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..10, cx),
|
||||
&[
|
||||
"v root",
|
||||
" .gitignore",
|
||||
" cc <== selected",
|
||||
" gg",
|
||||
" hh"
|
||||
],
|
||||
"Should select next entry not on .gitignore"
|
||||
);
|
||||
|
||||
// Test 2: Auto selection with many gitignored files next to the deleted file
|
||||
submit_deletion(&panel, cx);
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..10, cx),
|
||||
&[
|
||||
"v root",
|
||||
" .gitignore",
|
||||
" gg <== selected",
|
||||
" hh"
|
||||
],
|
||||
"Should select next entry not on .gitignore"
|
||||
);
|
||||
|
||||
// Test 3: Auto selection of entry before deleted file
|
||||
select_path(&panel, "root/hh", cx);
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..10, cx),
|
||||
&[
|
||||
"v root",
|
||||
" .gitignore",
|
||||
" gg",
|
||||
" hh <== selected"
|
||||
],
|
||||
"Should select next entry not on .gitignore"
|
||||
);
|
||||
submit_deletion(&panel, cx);
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..10, cx),
|
||||
&["v root", " .gitignore", " gg <== selected"],
|
||||
"Should select next entry not on .gitignore"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_nested_deletion_gitignore(cx: &mut gpui::TestAppContext) {
|
||||
init_test_with_editor(cx);
|
||||
|
||||
let fs = FakeFs::new(cx.executor().clone());
|
||||
fs.insert_tree(
|
||||
path!("/root"),
|
||||
json!({
|
||||
"dir1": {
|
||||
"file1": "// Testing",
|
||||
"file2": "// Testing",
|
||||
"file3": "// Testing"
|
||||
},
|
||||
"aa": "// Testing",
|
||||
".gitignore": "file1\nfile3\n",
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), [path!("/root").as_ref()], cx).await;
|
||||
let workspace = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
let cx = &mut VisualTestContext::from_window(*workspace, cx);
|
||||
|
||||
cx.update(|_, cx| {
|
||||
let settings = *ProjectPanelSettings::get_global(cx);
|
||||
ProjectPanelSettings::override_global(
|
||||
ProjectPanelSettings {
|
||||
hide_gitignore: true,
|
||||
..settings
|
||||
},
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
||||
let panel = workspace.update(cx, ProjectPanel::new).unwrap();
|
||||
|
||||
// Test 1: Visible items should exclude files on gitignore
|
||||
toggle_expand_dir(&panel, "root/dir1", cx);
|
||||
select_path(&panel, "root/dir1/file2", cx);
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..10, cx),
|
||||
&[
|
||||
"v root",
|
||||
" v dir1",
|
||||
" file2 <== selected",
|
||||
" .gitignore",
|
||||
" aa"
|
||||
],
|
||||
"Initial state should hide files on .gitignore"
|
||||
);
|
||||
submit_deletion(&panel, cx);
|
||||
|
||||
// Test 2: Auto selection should go to the parent
|
||||
assert_eq!(
|
||||
visible_entries_as_strings(&panel, 0..10, cx),
|
||||
&[
|
||||
"v root",
|
||||
" v dir1 <== selected",
|
||||
" .gitignore",
|
||||
" aa"
|
||||
],
|
||||
"Initial state should hide files on .gitignore"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_complex_selection_scenarios(cx: &mut gpui::TestAppContext) {
|
||||
init_test_with_editor(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue