From 050f5f6723c9c1640272b17a2a7fe17f3de43487 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 11 Mar 2025 22:55:41 -0700 Subject: [PATCH] Hide generate commit message button when assistant is disabled (#26519) Release Notes: - Git Beta: Fixed the generate commit message button still showing when the assistant is disabled. --- Cargo.lock | 1 + crates/git_ui/Cargo.toml | 1 + crates/git_ui/src/git_panel.rs | 25 +++++++++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 959ea95ee7..2388f9d211 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5441,6 +5441,7 @@ version = "0.1.0" dependencies = [ "anyhow", "askpass", + "assistant_settings", "buffer_diff", "collections", "component", diff --git a/crates/git_ui/Cargo.toml b/crates/git_ui/Cargo.toml index ddff1f440e..4d7d300d19 100644 --- a/crates/git_ui/Cargo.toml +++ b/crates/git_ui/Cargo.toml @@ -19,6 +19,7 @@ test-support = ["multi_buffer/test-support"] [dependencies] anyhow.workspace = true askpass.workspace = true +assistant_settings.workspace = true buffer_diff.workspace = true collections.workspace = true component.workspace = true diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index d46957c59f..7efb74ef01 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -11,6 +11,7 @@ use crate::{ use crate::{picker_prompt, project_diff, ProjectDiff}; use anyhow::Result; use askpass::AskPassDelegate; +use assistant_settings::AssistantSettings; use db::kvp::KEY_VALUE_STORE; use editor::commit_tooltip::CommitTooltip; @@ -49,7 +50,7 @@ use project::{ Fs, Project, ProjectPath, }; use serde::{Deserialize, Serialize}; -use settings::Settings as _; +use settings::{Settings as _, SettingsStore}; use std::cell::RefCell; use std::future::Future; use std::path::{Path, PathBuf}; @@ -327,6 +328,7 @@ pub struct GitPanel { workspace: WeakEntity, context_menu: Option<(Entity, Point, Subscription)>, modal_open: bool, + _settings_subscription: Subscription, } struct RemoteOperationGuard { @@ -443,6 +445,14 @@ impl GitPanel { hide_task: None, }; + let mut assistant_enabled = AssistantSettings::get_global(cx).enabled; + let _settings_subscription = cx.observe_global::(move |_, cx| { + if assistant_enabled != AssistantSettings::get_global(cx).enabled { + assistant_enabled = AssistantSettings::get_global(cx).enabled; + cx.notify(); + } + }); + let mut git_panel = Self { pending_remote_operations: Default::default(), remote_operation_id: 0, @@ -478,6 +488,7 @@ impl GitPanel { entry_count: 0, horizontal_scrollbar, vertical_scrollbar, + _settings_subscription, }; git_panel.schedule_update(false, window, cx); git_panel @@ -3590,9 +3601,14 @@ impl GitPanel { } fn current_language_model(cx: &Context<'_, GitPanel>) -> Option> { - let provider = LanguageModelRegistry::read_global(cx).active_provider()?; - let model = LanguageModelRegistry::read_global(cx).active_model()?; - provider.is_authenticated(cx).then(|| model) + assistant_settings::AssistantSettings::get_global(cx) + .enabled + .then(|| { + let provider = LanguageModelRegistry::read_global(cx).active_provider()?; + let model = LanguageModelRegistry::read_global(cx).active_model()?; + provider.is_authenticated(cx).then(|| model) + }) + .flatten() } impl Render for GitPanel { @@ -4326,6 +4342,7 @@ mod tests { cx.update(|cx| { let settings_store = SettingsStore::test(cx); cx.set_global(settings_store); + AssistantSettings::register(cx); WorktreeSettings::register(cx); workspace::init_settings(cx); theme::init(LoadThemes::JustBase, cx);