History

Stop automatically running /file command afer file suggestions (#16222)

https://github.com/user-attachments/assets/c5723950-7628-4073-bf03-f0a7473e984e Release Notes: - N/A

Kirill Bulatov committed 2 years ago

Commit 8d9dcf11 parent aa31f9d1 file · +17 −7Browse files

Unified · Split

crates/assistant/src/slash_command/file_command.rs+17−7
@@ -1,5 +1,5 @@
1use super::{diagnostics_command::write_single_file_diagnostics, SlashCommand, SlashCommandOutput};1use super::{diagnostics_command::write_single_file_diagnostics, SlashCommand, SlashCommandOutput};
2use anyhow::{anyhow, Result};2use anyhow::{anyhow, Context as _, Result};
3use assistant_slash_command::{ArgumentCompletion, SlashCommandOutputSection};3use assistant_slash_command::{ArgumentCompletion, SlashCommandOutputSection};
4use fuzzy::PathMatch;4use fuzzy::PathMatch;
5use gpui::{AppContext, Model, Task, View, WeakView};5use gpui::{AppContext, Model, Task, View, WeakView};
@@ -164,7 +164,7 @@ impl SlashCommand for FileSlashCommand { · 158 unmodified lines
164 Some(ArgumentCompletion {164 Some(ArgumentCompletion {
165 label,165 label,
166 new_text: text,166 new_text: text,
167 run_command: true,167 run_command: false,
168 })168 })
169 })169 })
170 .collect())170 .collect())
@@ -182,11 +182,11 @@ impl SlashCommand for FileSlashCommand { · 11 unmodified lines
182 return Task::ready(Err(anyhow!("workspace was dropped")));182 return Task::ready(Err(anyhow!("workspace was dropped")));
183 };183 };
184 184
185 let Some(argument) = arguments.first() else {185 if arguments.is_empty() {
186 return Task::ready(Err(anyhow!("missing path")));186 return Task::ready(Err(anyhow!("missing path")));
187 };187 };
188 188
189 let task = collect_files(workspace.read(cx).project().clone(), argument, cx);189 let task = collect_files(workspace.read(cx).project().clone(), arguments, cx);
190 190
191 cx.foreground_executor().spawn(async move {191 cx.foreground_executor().spawn(async move {
192 let (text, ranges) = task.await?;192 let (text, ranges) = task.await?;
@@ -217,10 +217,17 @@ enum EntryType { · 24 unmodified lines
217 217
218fn collect_files(218fn collect_files(
219 project: Model<Project>,219 project: Model<Project>,
220 glob_input: &str,220 glob_inputs: &[String],
221 cx: &mut AppContext,221 cx: &mut AppContext,
222) -> Task<Result<(String, Vec<(Range<usize>, PathBuf, EntryType)>)>> {222) -> Task<Result<(String, Vec<(Range<usize>, PathBuf, EntryType)>)>> {
223 let Ok(matcher) = PathMatcher::new(&[glob_input.to_owned()]) else {223 let Ok(matchers) = glob_inputs
224 .into_iter()
225 .map(|glob_input| {
226 PathMatcher::new(&[glob_input.to_owned()])
227 .with_context(|| format!("invalid path {glob_input}"))
228 })
229 .collect::<anyhow::Result<Vec<PathMatcher>>>()
230 else {
224 return Task::ready(Err(anyhow!("invalid path")));231 return Task::ready(Err(anyhow!("invalid path")));
225 };232 };
226 233
@@ -242,7 +249,10 @@ fn collect_files( · 15 unmodified lines
242 let mut path_including_worktree_name = PathBuf::new();249 let mut path_including_worktree_name = PathBuf::new();
243 path_including_worktree_name.push(snapshot.root_name());250 path_including_worktree_name.push(snapshot.root_name());
244 path_including_worktree_name.push(&entry.path);251 path_including_worktree_name.push(&entry.path);
245 if !matcher.is_match(&path_including_worktree_name) {252 if !matchers
253 .iter()
254 .any(|matcher| matcher.is_match(&path_including_worktree_name))
255 {
246 continue;256 continue;
247 }257 }
248 258