Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

assistant2: Fix panics when confirming nonexistent entries in the context picker (#22332)

Marshall Bowers14493772787d
diff --git a/crates/assistant2/src/context_picker/directory_context_picker.rs b/crates/assistant2/src/context_picker/directory_context_picker.rs
index 691a69908da..9684e70db2d 100644
--- a/crates/assistant2/src/context_picker/directory_context_picker.rs
+++ b/crates/assistant2/src/context_picker/directory_context_picker.rs
@@ -178,7 +178,9 @@ impl PickerDelegate for DirectoryContextPickerDelegate {
}
fn confirm(&mut self, _secondary: bool, cx: &mut ViewContext<Picker<Self>>) {
- let mat = &self.matches[self.selected_index];
+ let Some(mat) = self.matches.get(self.selected_index) else {
+ return;
+ };
let workspace = self.workspace.clone();
let Some(project) = workspace
diff --git a/crates/assistant2/src/context_picker/file_context_picker.rs b/crates/assistant2/src/context_picker/file_context_picker.rs
index 79787be7899..db497b43a04 100644
--- a/crates/assistant2/src/context_picker/file_context_picker.rs
+++ b/crates/assistant2/src/context_picker/file_context_picker.rs
@@ -192,7 +192,9 @@ impl PickerDelegate for FileContextPickerDelegate {
}
fn confirm(&mut self, _secondary: bool, cx: &mut ViewContext<Picker<Self>>) {
- let mat = &self.matches[self.selected_index];
+ let Some(mat) = self.matches.get(self.selected_index) else {
+ return;
+ };
let workspace = self.workspace.clone();
let Some(project) = workspace
diff --git a/crates/assistant2/src/context_picker/thread_context_picker.rs b/crates/assistant2/src/context_picker/thread_context_picker.rs
index 78e840114a4..e2bd1cff229 100644
--- a/crates/assistant2/src/context_picker/thread_context_picker.rs
+++ b/crates/assistant2/src/context_picker/thread_context_picker.rs
@@ -154,7 +154,9 @@ impl PickerDelegate for ThreadContextPickerDelegate {
}
fn confirm(&mut self, _secondary: bool, cx: &mut ViewContext<Picker<Self>>) {
- let entry = &self.matches[self.selected_index];
+ let Some(entry) = self.matches.get(self.selected_index) else {
+ return;
+ };
let Some(thread_store) = self.thread_store.upgrade() else {
return;