Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Gracefully handle models searching for empty glob (#27370)
Richard Feldman6b7167a32d98
diff --git a/crates/assistant_tools/src/edit_files_tool/replace.rs b/crates/assistant_tools/src/edit_files_tool/replace.rsindex f98aa7e4fa3..46f54bb8a56 100644--- a/crates/assistant_tools/src/edit_files_tool/replace.rs+++ b/crates/assistant_tools/src/edit_files_tool/replace.rs@@ -1,5 +1,6 @@use language::{BufferSnapshot, Diff, Point, ToOffset};use project::search::SearchQuery;+use std::iter;use util::{paths::PathMatcher, ResultExt as _};/// Performs an exact string replacement in a buffer, requiring precise character-for-character matching.@@ -11,8 +12,8 @@ pub async fn replace_exact(old: &str, new: &str, snapshot: &BufferSnapshot) -> Ofalse,true,true,- PathMatcher::new(&[]).ok()?,- PathMatcher::new(&[]).ok()?,+ PathMatcher::new(iter::empty::<&str>()).ok()?,+ PathMatcher::new(iter::empty::<&str>()).ok()?,None,).log_err()?;diff --git a/crates/assistant_tools/src/path_search_tool.rs b/crates/assistant_tools/src/path_search_tool.rsindex e2621e3f966..401489ca150 100644--- a/crates/assistant_tools/src/path_search_tool.rs+++ b/crates/assistant_tools/src/path_search_tool.rs@@ -71,7 +71,11 @@ impl Tool for PathSearchTool {Ok(input) => (input.offset.unwrap_or(0), input.glob),Err(err) => return Task::ready(Err(anyhow!(err))),};- let path_matcher = match PathMatcher::new(&[glob.clone()]) {++ let path_matcher = match PathMatcher::new([+ // Sometimes models try to search for "". In this case, return all paths in the project.+ if glob.is_empty() { "*" } else { &glob },+ ]) {Ok(matcher) => matcher,Err(err) => return Task::ready(Err(anyhow!("Invalid glob: {err}"))),};diff --git a/crates/util/src/paths.rs b/crates/util/src/paths.rsindex ecaa0d9bc2f..bdeee4a23e5 100644--- a/crates/util/src/paths.rs+++ b/crates/util/src/paths.rs@@ -377,10 +377,10 @@ impl PartialEq for PathMatcher {impl Eq for PathMatcher {}impl PathMatcher {- pub fn new(globs: &[String]) -> Result<Self, globset::Error> {+ pub fn new(globs: impl IntoIterator<Item = impl AsRef<str>>) -> Result<Self, globset::Error> {let globs = globs- .iter()- .map(|glob| Glob::new(glob))+ .into_iter()+ .map(|as_str| Glob::new(as_str.as_ref())).collect::<Result<Vec<_>, _>>()?;let sources = globs.iter().map(|glob| glob.glob().to_owned()).collect();let mut glob_builder = GlobSetBuilder::new();