From 805fd1dc8184154bb7c5bc24db7b20c06fc47cad Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Sat, 17 Jun 2023 18:16:41 +0200 Subject: [PATCH] feat(plugins): strider improvements (#2551) * fix(plugins): adjust debounce and smart file ignore in strider * style(comment): remove commented code * style(fmt): rustfmt --- Cargo.lock | 53 ++++++++++++++++++- default-plugins/strider/Cargo.toml | 2 +- default-plugins/strider/src/search/mod.rs | 14 +++-- zellij-server/src/plugins/watch_filesystem.rs | 2 +- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 535879b8..cf4b40bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + [[package]] name = "aho-corasick" version = "1.0.1" @@ -324,6 +333,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5988cb1d626264ac94100be357308f29ff7cbdd3b36bda27f450a4ee3f713426" +[[package]] +name = "bstr" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "bumpalo" version = "3.10.0" @@ -1209,6 +1228,19 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "globset" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" +dependencies = [ + "aho-corasick 0.7.20", + "bstr", + "fnv", + "log", + "regex", +] + [[package]] name = "gloo-timers" version = "0.2.4" @@ -1304,6 +1336,23 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "ignore" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +dependencies = [ + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + [[package]] name = "indexmap" version = "1.8.2" @@ -2439,7 +2488,7 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" dependencies = [ - "aho-corasick", + "aho-corasick 1.0.1", "memchr", "regex-syntax", ] @@ -2956,12 +3005,12 @@ dependencies = [ "ansi_term", "colored", "fuzzy-matcher", + "ignore", "pretty-bytes", "serde", "serde_json", "strip-ansi-escapes", "unicode-width", - "walkdir", "zellij-tile", ] diff --git a/default-plugins/strider/Cargo.toml b/default-plugins/strider/Cargo.toml index 65b5d23e..33cf4ca5 100644 --- a/default-plugins/strider/Cargo.toml +++ b/default-plugins/strider/Cargo.toml @@ -10,7 +10,7 @@ license = "MIT" colored = "2.0.0" zellij-tile = { path = "../../zellij-tile" } pretty-bytes = "0.2.2" -walkdir = "2.3.3" +ignore = "0.4.20" fuzzy-matcher = "0.3.7" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/default-plugins/strider/src/search/mod.rs b/default-plugins/strider/src/search/mod.rs index 1a9db2da..33c8a60b 100644 --- a/default-plugins/strider/src/search/mod.rs +++ b/default-plugins/strider/src/search/mod.rs @@ -15,9 +15,9 @@ use zellij_tile::prelude::*; use fuzzy_matcher::skim::SkimMatcherV2; use fuzzy_matcher::FuzzyMatcher; +use ignore::Walk; use search_results::SearchResult; use serde::{Deserialize, Serialize}; -use walkdir::WalkDir; use std::io::{self, BufRead}; @@ -64,8 +64,10 @@ impl Search { } } pub fn scan_hd(&mut self) { - for entry in WalkDir::new(ROOT).into_iter().filter_map(|e| e.ok()) { - self.add_file_entry(entry.path(), entry.metadata().ok()); + for result in Walk::new(ROOT) { + if let Ok(entry) = result { + self.add_file_entry(entry.path(), entry.metadata().ok()); + } } } pub fn search(&mut self, search_term: String) { @@ -160,11 +162,7 @@ impl Search { match line { Ok(line) => { self.file_contents.insert( - ( - // String::from_utf8_lossy(&strip_ansi_escapes::strip(file_path_stripped_prefix.clone()).unwrap()).to_string(), - file_path_stripped_prefix.clone(), - index + 1, - ), + (file_path_stripped_prefix.clone(), index + 1), String::from_utf8_lossy( &strip_ansi_escapes::strip(line).unwrap(), ) diff --git a/zellij-server/src/plugins/watch_filesystem.rs b/zellij-server/src/plugins/watch_filesystem.rs index 9ac0a320..36c0e04d 100644 --- a/zellij-server/src/plugins/watch_filesystem.rs +++ b/zellij-server/src/plugins/watch_filesystem.rs @@ -12,7 +12,7 @@ use zellij_utils::notify_debouncer_full::{ }; use zellij_utils::{data::Event, errors::prelude::Result}; -const DEBOUNCE_DURATION_MS: u64 = 500; +const DEBOUNCE_DURATION_MS: u64 = 400; pub fn watch_filesystem( senders: ThreadSenders,