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.
This commit is contained in:
Mikayla Maki 2025-03-11 22:55:41 -07:00 committed by GitHub
parent 2cd970f137
commit 050f5f6723
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 4 deletions

1
Cargo.lock generated
View file

@ -5441,6 +5441,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"askpass",
"assistant_settings",
"buffer_diff",
"collections",
"component",

View file

@ -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

View file

@ -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<Workspace>,
context_menu: Option<(Entity<ContextMenu>, Point<Pixels>, 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::<SettingsStore>(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<Arc<dyn LanguageModel>> {
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);