assistant: Fix toggling the model selector via keybind (#16319)

This PR restores the ability to toggle the model selector via a keybind
after it was lost in #15693.

Release Notes:

- Restored the ability to toggle the model selector in the Assistant via
a keybinding (Preview only).
This commit is contained in:
Marshall Bowers 2024-08-15 17:45:25 -04:00 committed by GitHub
parent 776442f3ae
commit f65b2b9a2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 46 deletions

View file

@ -17,7 +17,7 @@ use crate::{
PendingSlashCommandStatus, QuoteSelection, RemoteContextMetadata, ResolvedWorkflowStep, PendingSlashCommandStatus, QuoteSelection, RemoteContextMetadata, ResolvedWorkflowStep,
SavedContextMetadata, Split, ToggleFocus, ToggleModelSelector, WorkflowStepView, SavedContextMetadata, Split, ToggleFocus, ToggleModelSelector, WorkflowStepView,
}; };
use crate::{ContextStoreEvent, ShowConfiguration}; use crate::{ContextStoreEvent, ModelPickerDelegate, ShowConfiguration};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use assistant_slash_command::{SlashCommand, SlashCommandOutputSection}; use assistant_slash_command::{SlashCommand, SlashCommandOutputSection};
use client::{proto, Client, Status}; use client::{proto, Client, Status};
@ -145,7 +145,7 @@ pub struct AssistantPanel {
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
subscriptions: Vec<Subscription>, subscriptions: Vec<Subscription>,
model_selector_menu_handle: PopoverMenuHandle<ContextMenu>, model_selector_menu_handle: PopoverMenuHandle<Picker<ModelPickerDelegate>>,
model_summary_editor: View<Editor>, model_summary_editor: View<Editor>,
authenticate_provider_task: Option<(LanguageModelProviderId, Task<()>)>, authenticate_provider_task: Option<(LanguageModelProviderId, Task<()>)>,
configuration_subscription: Option<Subscription>, configuration_subscription: Option<Subscription>,
@ -4044,12 +4044,13 @@ pub struct ContextEditorToolbarItem {
workspace: WeakView<Workspace>, workspace: WeakView<Workspace>,
active_context_editor: Option<WeakView<ContextEditor>>, active_context_editor: Option<WeakView<ContextEditor>>,
model_summary_editor: View<Editor>, model_summary_editor: View<Editor>,
model_selector_menu_handle: PopoverMenuHandle<Picker<ModelPickerDelegate>>,
} }
impl ContextEditorToolbarItem { impl ContextEditorToolbarItem {
pub fn new( pub fn new(
workspace: &Workspace, workspace: &Workspace,
_model_selector_menu_handle: PopoverMenuHandle<ContextMenu>, model_selector_menu_handle: PopoverMenuHandle<Picker<ModelPickerDelegate>>,
model_summary_editor: View<Editor>, model_summary_editor: View<Editor>,
) -> Self { ) -> Self {
Self { Self {
@ -4057,6 +4058,7 @@ impl ContextEditorToolbarItem {
workspace: workspace.weak_handle(), workspace: workspace.weak_handle(),
active_context_editor: None, active_context_editor: None,
model_summary_editor, model_summary_editor,
model_selector_menu_handle,
} }
} }
@ -4190,49 +4192,52 @@ impl Render for ContextEditorToolbarItem {
let right_side = h_flex() let right_side = h_flex()
.gap_2() .gap_2()
.child(ModelSelector::new( .child(
self.fs.clone(), ModelSelector::new(
ButtonLike::new("active-model") self.fs.clone(),
.style(ButtonStyle::Subtle) ButtonLike::new("active-model")
.child( .style(ButtonStyle::Subtle)
h_flex() .child(
.w_full() h_flex()
.gap_0p5() .w_full()
.child( .gap_0p5()
div() .child(
.overflow_x_hidden() div()
.flex_grow() .overflow_x_hidden()
.whitespace_nowrap() .flex_grow()
.child(match (active_provider, active_model) { .whitespace_nowrap()
(Some(provider), Some(model)) => h_flex() .child(match (active_provider, active_model) {
.gap_1() (Some(provider), Some(model)) => h_flex()
.child( .gap_1()
Icon::new(provider.icon()) .child(
.color(Color::Muted) Icon::new(provider.icon())
.size(IconSize::XSmall), .color(Color::Muted)
) .size(IconSize::XSmall),
.child( )
Label::new(model.name().0) .child(
.size(LabelSize::Small) Label::new(model.name().0)
.color(Color::Muted), .size(LabelSize::Small)
) .color(Color::Muted),
.into_any_element(), )
_ => Label::new("No model selected") .into_any_element(),
.size(LabelSize::Small) _ => Label::new("No model selected")
.color(Color::Muted) .size(LabelSize::Small)
.into_any_element(), .color(Color::Muted)
}), .into_any_element(),
) }),
.child( )
Icon::new(IconName::ChevronDown) .child(
.color(Color::Muted) Icon::new(IconName::ChevronDown)
.size(IconSize::XSmall), .color(Color::Muted)
), .size(IconSize::XSmall),
) ),
.tooltip(move |cx| { )
Tooltip::for_action("Change Model", &ToggleModelSelector, cx) .tooltip(move |cx| {
}), Tooltip::for_action("Change Model", &ToggleModelSelector, cx)
)) }),
)
.with_handle(self.model_selector_menu_handle.clone()),
)
.children(self.render_remaining_tokens(cx)) .children(self.render_remaining_tokens(cx))
.child(self.render_inject_context_menu(cx)); .child(self.render_inject_context_menu(cx));

View file

@ -295,5 +295,6 @@ impl<T: PopoverTrigger> RenderOnce for ModelSelector<T> {
.menu(move |_cx| Some(picker_view.clone())) .menu(move |_cx| Some(picker_view.clone()))
.trigger(self.trigger) .trigger(self.trigger)
.attach(gpui::AnchorCorner::BottomLeft) .attach(gpui::AnchorCorner::BottomLeft)
.when_some(self.handle, |menu, handle| menu.with_handle(handle))
} }
} }