Deduplicate building a walk builder from config

pull/9723/head
mo8it 9 months ago
parent 6db666fce1
commit 2f08d8d8b3

1
Cargo.lock generated

@ -1443,6 +1443,7 @@ dependencies = [
"helix-stdx", "helix-stdx",
"helix-tui", "helix-tui",
"helix-vcs", "helix-vcs",
"ignore",
"libc", "libc",
"log", "log",
"once_cell", "once_cell",

@ -39,6 +39,7 @@ package.helix-term.opt-level = 2
[workspace.dependencies] [workspace.dependencies]
tree-sitter = { version = "0.20", git = "https://github.com/helix-editor/tree-sitter", rev = "660481dbf71413eba5a928b0b0ab8da50c1109e0" } tree-sitter = { version = "0.20", git = "https://github.com/helix-editor/tree-sitter", rev = "660481dbf71413eba5a928b0b0ab8da50c1109e0" }
nucleo = "0.2.0" nucleo = "0.2.0"
ignore = "0.4"
[workspace.package] [workspace.package]
version = "23.10.0" version = "23.10.0"

@ -51,7 +51,7 @@ log = "0.4"
# File picker # File picker
nucleo.workspace = true nucleo.workspace = true
ignore = "0.4" ignore.workspace = true
# markdown doc rendering # markdown doc rendering
pulldown-cmark = { version = "0.10", default-features = false } pulldown-cmark = { version = "0.10", default-features = false }
# file type detection # file type detection

@ -74,7 +74,7 @@ use url::Url;
use grep_regex::RegexMatcherBuilder; use grep_regex::RegexMatcherBuilder;
use grep_searcher::{sinks, BinaryDetection, SearcherBuilder}; use grep_searcher::{sinks, BinaryDetection, SearcherBuilder};
use ignore::{DirEntry, WalkBuilder, WalkState}; use ignore::{DirEntry, WalkState};
pub type OnKeyCallback = Box<dyn FnOnce(&mut Context, KeyEvent)>; pub type OnKeyCallback = Box<dyn FnOnce(&mut Context, KeyEvent)>;
@ -2281,24 +2281,14 @@ fn global_search(cx: &mut Context) {
.canonicalize() .canonicalize()
.unwrap_or_else(|_| search_root.clone()); .unwrap_or_else(|_| search_root.clone());
let injector_ = injector.clone(); let injector_ = injector.clone();
let mut walk_builder = file_picker_config.walk_builder(search_root);
std::thread::spawn(move || { std::thread::spawn(move || {
let searcher = SearcherBuilder::new() let searcher = SearcherBuilder::new()
.binary_detection(BinaryDetection::quit(b'\x00')) .binary_detection(BinaryDetection::quit(b'\x00'))
.build(); .build();
let mut walk_builder = WalkBuilder::new(search_root); walk_builder.filter_entry(move |entry| {
walk_builder
.hidden(file_picker_config.hidden)
.parents(file_picker_config.parents)
.ignore(file_picker_config.ignore)
.follow_links(file_picker_config.follow_symlinks)
.git_ignore(file_picker_config.git_ignore)
.git_global(file_picker_config.git_global)
.git_exclude(file_picker_config.git_exclude)
.max_depth(file_picker_config.max_depth)
.filter_entry(move |entry| {
filter_picker_entry(entry, &absolute_root, dedup_symlinks) filter_picker_entry(entry, &absolute_root, dedup_symlinks)
}); });

@ -156,7 +156,7 @@ pub fn regex_prompt(
} }
pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker<PathBuf> { pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker<PathBuf> {
use ignore::{types::TypesBuilder, WalkBuilder}; use ignore::types::TypesBuilder;
use std::time::Instant; use std::time::Instant;
let now = Instant::now(); let now = Instant::now();
@ -164,17 +164,9 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker
let dedup_symlinks = config.file_picker.deduplicate_links; let dedup_symlinks = config.file_picker.deduplicate_links;
let absolute_root = root.canonicalize().unwrap_or_else(|_| root.clone()); let absolute_root = root.canonicalize().unwrap_or_else(|_| root.clone());
let mut walk_builder = WalkBuilder::new(&root); let mut walk_builder = config.file_picker.walk_builder(&root);
walk_builder walk_builder
.hidden(config.file_picker.hidden)
.parents(config.file_picker.parents)
.ignore(config.file_picker.ignore)
.follow_links(config.file_picker.follow_symlinks)
.git_ignore(config.file_picker.git_ignore)
.git_global(config.file_picker.git_global)
.git_exclude(config.file_picker.git_exclude)
.sort_by_file_name(|name1, name2| name1.cmp(name2)) .sort_by_file_name(|name1, name2| name1.cmp(name2))
.max_depth(config.file_picker.max_depth)
.filter_entry(move |entry| filter_picker_entry(entry, &absolute_root, dedup_symlinks)); .filter_entry(move |entry| filter_picker_entry(entry, &absolute_root, dedup_symlinks));
walk_builder.add_custom_ignore_filename(helix_loader::config_dir().join("ignore")); walk_builder.add_custom_ignore_filename(helix_loader::config_dir().join("ignore"));

@ -48,6 +48,7 @@ log = "~0.4"
parking_lot = "0.12.1" parking_lot = "0.12.1"
ignore.workspace = true
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
clipboard-win = { version = "5.1", features = ["std"] } clipboard-win = { version = "5.1", features = ["std"] }

@ -17,6 +17,7 @@ use helix_vcs::DiffProviderRegistry;
use futures_util::stream::select_all::SelectAll; use futures_util::stream::select_all::SelectAll;
use futures_util::{future, StreamExt}; use futures_util::{future, StreamExt};
use helix_lsp::Call; use helix_lsp::Call;
use ignore::WalkBuilder;
use tokio_stream::wrappers::UnboundedReceiverStream; use tokio_stream::wrappers::UnboundedReceiverStream;
use std::{ use std::{
@ -212,6 +213,25 @@ impl Default for FilePickerConfig {
} }
} }
impl FilePickerConfig {
pub fn walk_builder<P>(&self, path: P) -> WalkBuilder
where
P: AsRef<Path>,
{
let mut builder = WalkBuilder::new(path);
builder
.hidden(self.hidden)
.follow_links(self.follow_symlinks)
.parents(self.parents)
.ignore(self.ignore)
.git_ignore(self.git_ignore)
.git_global(self.git_global)
.git_exclude(self.git_exclude)
.max_depth(self.max_depth);
builder
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct Config { pub struct Config {

Loading…
Cancel
Save