From 14493772787d97475090e42d0c9993bf3b97c005 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 21 Dec 2024 11:11:29 -0500 Subject: [PATCH] assistant2: Fix panics when confirming nonexistent entries in the context picker (#22332) This PR fixes a panic that could occur when confirming when the context picker had no matching entries. Release Notes: - N/A --- .../assistant2/src/context_picker/directory_context_picker.rs | 4 +++- crates/assistant2/src/context_picker/file_context_picker.rs | 4 +++- crates/assistant2/src/context_picker/thread_context_picker.rs | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/assistant2/src/context_picker/directory_context_picker.rs b/crates/assistant2/src/context_picker/directory_context_picker.rs index 691a69908d..9684e70db2 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>) { - 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 79787be789..db497b43a0 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>) { - 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 78e840114a..e2bd1cff22 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>) { - 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;