From c1cfc03a61c2abe4bd435da825be0ef70ca3e73b Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 16 Dec 2024 17:52:37 -0500 Subject: [PATCH] assistant2: Persist model selector changes --- crates/assistant2/src/assistant_panel.rs | 12 ++++++++++-- crates/assistant2/src/message_editor.rs | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/crates/assistant2/src/assistant_panel.rs b/crates/assistant2/src/assistant_panel.rs index 63d52d6d01d48..3a756d9d044f4 100644 --- a/crates/assistant2/src/assistant_panel.rs +++ b/crates/assistant2/src/assistant_panel.rs @@ -90,7 +90,7 @@ impl AssistantPanel { Self { active_view: ActiveView::Thread, workspace: workspace.clone(), - fs, + fs: fs.clone(), language_registry: language_registry.clone(), thread_store: thread_store.clone(), thread: cx.new_view(|cx| { @@ -103,7 +103,13 @@ impl AssistantPanel { ) }), message_editor: cx.new_view(|cx| { - MessageEditor::new(workspace, thread_store.downgrade(), thread.clone(), cx) + MessageEditor::new( + fs.clone(), + workspace, + thread_store.downgrade(), + thread.clone(), + cx, + ) }), tools, local_timezone: UtcOffset::from_whole_seconds( @@ -141,6 +147,7 @@ impl AssistantPanel { }); self.message_editor = cx.new_view(|cx| { MessageEditor::new( + self.fs.clone(), self.workspace.clone(), self.thread_store.downgrade(), thread, @@ -170,6 +177,7 @@ impl AssistantPanel { }); self.message_editor = cx.new_view(|cx| { MessageEditor::new( + self.fs.clone(), self.workspace.clone(), self.thread_store.downgrade(), thread, diff --git a/crates/assistant2/src/message_editor.rs b/crates/assistant2/src/message_editor.rs index 179909d91928f..50715d91a469f 100644 --- a/crates/assistant2/src/message_editor.rs +++ b/crates/assistant2/src/message_editor.rs @@ -1,12 +1,16 @@ +use std::sync::Arc; + use editor::{Editor, EditorElement, EditorStyle}; +use fs::Fs; use gpui::{AppContext, FocusableView, Model, TextStyle, View, WeakModel, WeakView}; use language_model::{LanguageModelRegistry, LanguageModelRequestTool}; use language_model_selector::{LanguageModelSelector, LanguageModelSelectorPopoverMenu}; -use settings::Settings; +use settings::{update_settings_file, Settings}; use theme::ThemeSettings; use ui::{prelude::*, ButtonLike, CheckboxWithLabel, ElevationIndex, KeyBinding, Tooltip}; use workspace::Workspace; +use crate::assistant_settings::AssistantSettings; use crate::context_store::ContextStore; use crate::context_strip::ContextStrip; use crate::thread::{RequestKind, Thread}; @@ -24,6 +28,7 @@ pub struct MessageEditor { impl MessageEditor { pub fn new( + fs: Arc, workspace: WeakView, thread_store: WeakModel, thread: Model, @@ -50,9 +55,14 @@ impl MessageEditor { ) }), language_model_selector: cx.new_view(|cx| { + let fs = fs.clone(); LanguageModelSelector::new( - |model, _cx| { - println!("Selected {:?}", model.name()); + move |model, cx| { + update_settings_file::( + fs.clone(), + cx, + move |settings, _cx| settings.set_model(model.clone()), + ); }, cx, )