From 6ae2417dea0b60c010b52fa5e490a2612e247d46 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 6 May 2025 11:57:22 -0700 Subject: [PATCH] Fix token count not appearing for the first message (#30035) Release Notes: - N/A Co-authored-by: Ben Brandt --- crates/agent/src/assistant_panel.rs | 3 ++- crates/agent/src/message_editor.rs | 4 ++++ crates/agent/src/thread.rs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/agent/src/assistant_panel.rs b/crates/agent/src/assistant_panel.rs index cedf0465374066698b1d454a29310e14e7e775d8..2cc1466e8a1ff197077603aa03ed041f095ec389 100644 --- a/crates/agent/src/assistant_panel.rs +++ b/crates/agent/src/assistant_panel.rs @@ -1462,6 +1462,7 @@ impl AssistantPanel { let thread = active_thread.thread().read(cx); let thread_id = thread.id().clone(); let is_empty = active_thread.is_empty(); + let editor_empty = self.message_editor.read(cx).is_editor_fully_empty(cx); let last_usage = active_thread.thread().read(cx).last_usage().or_else(|| { maybe!({ let amount = user_store.model_request_usage_amount()?; @@ -1484,7 +1485,7 @@ impl AssistantPanel { let account_url = zed_urls::account_url(cx); let show_token_count = match &self.active_view { - ActiveView::Thread { .. } => !is_empty, + ActiveView::Thread { .. } => !is_empty || !editor_empty, ActiveView::PromptEditor { .. } => true, _ => false, }; diff --git a/crates/agent/src/message_editor.rs b/crates/agent/src/message_editor.rs index 938ebf4cc05b0ab51c1192267c1e3296ddd98c73..958f0f45a572589a78609e765858aa20fc910ab1 100644 --- a/crates/agent/src/message_editor.rs +++ b/crates/agent/src/message_editor.rs @@ -315,6 +315,10 @@ impl MessageEditor { self.editor.read(cx).text(cx).trim().is_empty() } + pub fn is_editor_fully_empty(&self, cx: &App) -> bool { + self.editor.read(cx).is_empty(cx) + } + fn send_to_model(&mut self, window: &mut Window, cx: &mut Context) { let Some(ConfiguredModel { model, provider }) = self .thread diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index 65c4070b45bf7e25a7c3dc6f42c30abbb7865484..68ce69a41d8a61691aaec1aa206b3b5f1f85f317 100644 --- a/crates/agent/src/thread.rs +++ b/crates/agent/src/thread.rs @@ -267,7 +267,7 @@ impl DetailedSummaryState { } } -#[derive(Default)] +#[derive(Default, Debug)] pub struct TotalTokenUsage { pub total: usize, pub max: usize,