From 901dbedf8d022ecb1d355d6aadd3aaeed198dc7d Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 13 Dec 2024 17:26:10 -0500 Subject: [PATCH] assistant2: Refine context pickers (#21996) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds some visual refinements to the context pickers in Assistant2. Screenshot 2024-12-13 at 5 11 24 PM Screenshot 2024-12-13 at 5 11 31 PM Release Notes: - N/A --- .../context_picker/fetch_context_picker.rs | 15 +++++++--- .../src/context_picker/file_context_picker.rs | 29 ++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/crates/assistant2/src/context_picker/fetch_context_picker.rs b/crates/assistant2/src/context_picker/fetch_context_picker.rs index 9545d546eb..352d3cd057 100644 --- a/crates/assistant2/src/context_picker/fetch_context_picker.rs +++ b/crates/assistant2/src/context_picker/fetch_context_picker.rs @@ -8,7 +8,7 @@ use gpui::{AppContext, DismissEvent, FocusHandle, FocusableView, Task, View, Wea use html_to_markdown::{convert_html_to_markdown, markdown, TagHandler}; use http_client::{AsyncBody, HttpClientWithUrl}; use picker::{Picker, PickerDelegate}; -use ui::{prelude::*, ListItem, ListItemSpacing, ViewContext}; +use ui::{prelude::*, ListItem, ViewContext}; use workspace::Workspace; use crate::context::ContextKind; @@ -150,7 +150,15 @@ impl PickerDelegate for FetchContextPickerDelegate { type ListItem = ListItem; fn match_count(&self) -> usize { - 1 + if self.url.is_empty() { + 0 + } else { + 1 + } + } + + fn no_matches_text(&self, _cx: &mut WindowContext) -> SharedString { + "Enter the URL that you would like to fetch".into() } fn selected_index(&self) -> usize { @@ -210,9 +218,8 @@ impl PickerDelegate for FetchContextPickerDelegate { Some( ListItem::new(ix) .inset(true) - .spacing(ListItemSpacing::Sparse) .toggle_state(selected) - .child(self.url.clone()), + .child(Label::new(self.url.clone())), ) } } diff --git a/crates/assistant2/src/context_picker/file_context_picker.rs b/crates/assistant2/src/context_picker/file_context_picker.rs index 08e7e13d54..c5441bb92a 100644 --- a/crates/assistant2/src/context_picker/file_context_picker.rs +++ b/crates/assistant2/src/context_picker/file_context_picker.rs @@ -8,7 +8,7 @@ use fuzzy::PathMatch; use gpui::{AppContext, DismissEvent, FocusHandle, FocusableView, Task, View, WeakView}; use picker::{Picker, PickerDelegate}; use project::{PathMatchCandidateSet, WorktreeId}; -use ui::{prelude::*, ListItem, ListItemSpacing}; +use ui::{prelude::*, ListItem}; use util::ResultExt as _; use workspace::Workspace; @@ -254,14 +254,29 @@ impl PickerDelegate for FileContextPickerDelegate { selected: bool, _cx: &mut ViewContext>, ) -> Option { - let mat = &self.matches[ix]; + let path_match = &self.matches[ix]; + let file_name = path_match + .path + .file_name() + .unwrap_or_default() + .to_string_lossy() + .to_string(); + let directory = path_match + .path + .parent() + .map(|directory| format!("{}/", directory.to_string_lossy())); Some( - ListItem::new(ix) - .inset(true) - .spacing(ListItemSpacing::Sparse) - .toggle_state(selected) - .child(mat.path.to_string_lossy().to_string()), + ListItem::new(ix).inset(true).toggle_state(selected).child( + h_flex() + .gap_2() + .child(Label::new(file_name)) + .children(directory.map(|directory| { + Label::new(directory) + .size(LabelSize::Small) + .color(Color::Muted) + })), + ), ) } }