From 68e3d79847d27486921f52ea3a84da6aa2eece90 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 17 Dec 2024 11:43:27 -0500 Subject: [PATCH] assistant2: Use `ContextKind` to match on `ContextPicker` entries (#22143) This PR updates the `ContextPicker` entries to match on the `ContextKind` instead of using strings. Release Notes: - N/A --- crates/assistant2/src/context_picker.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/assistant2/src/context_picker.rs b/crates/assistant2/src/context_picker.rs index 48bb30a5f5..f6a49d0281 100644 --- a/crates/assistant2/src/context_picker.rs +++ b/crates/assistant2/src/context_picker.rs @@ -13,6 +13,7 @@ use ui::{prelude::*, ListItem, ListItemSpacing}; use util::ResultExt; use workspace::Workspace; +use crate::context::ContextKind; use crate::context_picker::fetch_context_picker::FetchContextPicker; use crate::context_picker::file_context_picker::FileContextPicker; use crate::context_picker::thread_context_picker::ThreadContextPicker; @@ -40,16 +41,14 @@ impl ContextPicker { cx: &mut ViewContext, ) -> Self { let mut entries = vec![ - ContextPickerEntry { - name: "Directory".into(), - icon: IconName::Folder, - }, ContextPickerEntry { name: "File".into(), + kind: ContextKind::File, icon: IconName::File, }, ContextPickerEntry { name: "Fetch".into(), + kind: ContextKind::FetchedUrl, icon: IconName::Globe, }, ]; @@ -57,6 +56,7 @@ impl ContextPicker { if thread_store.is_some() { entries.push(ContextPickerEntry { name: "Thread".into(), + kind: ContextKind::Thread, icon: IconName::MessageCircle, }); } @@ -115,6 +115,7 @@ impl Render for ContextPicker { #[derive(Clone)] struct ContextPickerEntry { name: SharedString, + kind: ContextKind, icon: IconName, } @@ -155,8 +156,8 @@ impl PickerDelegate for ContextPickerDelegate { if let Some(entry) = self.entries.get(self.selected_ix) { self.context_picker .update(cx, |this, cx| { - match entry.name.to_string().as_str() { - "File" => { + match entry.kind { + ContextKind::File => { this.mode = ContextPickerMode::File(cx.new_view(|cx| { FileContextPicker::new( self.context_picker.clone(), @@ -166,7 +167,7 @@ impl PickerDelegate for ContextPickerDelegate { ) })); } - "Fetch" => { + ContextKind::FetchedUrl => { this.mode = ContextPickerMode::Fetch(cx.new_view(|cx| { FetchContextPicker::new( self.context_picker.clone(), @@ -176,7 +177,7 @@ impl PickerDelegate for ContextPickerDelegate { ) })); } - "Thread" => { + ContextKind::Thread => { if let Some(thread_store) = self.thread_store.as_ref() { this.mode = ContextPickerMode::Thread(cx.new_view(|cx| { ThreadContextPicker::new( @@ -188,7 +189,6 @@ impl PickerDelegate for ContextPickerDelegate { })); } } - _ => {} } cx.focus_self();