agent_ui: Fix token count not getting shown in the TextThread (#34485)
Umesh Yadav
created 4 months ago
Closes #34319
In this pr: https://github.com/zed-industries/zed/pull/33462 there was
check added for early return for active_thread and message_editor as
those are not present in the TextThread and only available in the Thread
the token count was not getting triggered for TextThread this pr fixes
that regression by moving the logic specific to Thread inside of thread
view match.
<img width="3024" height="1886" alt="CleanShot 2025-07-15 at 23 50
18@2x"
src="https://github.com/user-attachments/assets/bd74ae8b-6c37-4cdd-ab95-d3c253b8a948"
/>
Release Notes:
- Fix token count not getting shown in the TextThread
Change summary
crates/agent_ui/src/agent_panel.rs | 57 +++++++++++++++----------------
1 file changed, 27 insertions(+), 30 deletions(-)
Detailed changes
@@ -1975,48 +1975,45 @@ impl AgentPanel {
}
fn render_token_count(&self, cx: &App) -> Option<AnyElement> {
- let (active_thread, message_editor) = match &self.active_view {
+ match &self.active_view {
ActiveView::Thread {
thread,
message_editor,
..
- } => (thread.read(cx), message_editor.read(cx)),
- ActiveView::AcpThread { .. } => {
- return None;
- }
- ActiveView::TextThread { .. } | ActiveView::History | ActiveView::Configuration => {
- return None;
- }
- };
+ } => {
+ let active_thread = thread.read(cx);
+ let message_editor = message_editor.read(cx);
- let editor_empty = message_editor.is_editor_fully_empty(cx);
+ let editor_empty = message_editor.is_editor_fully_empty(cx);
- if active_thread.is_empty() && editor_empty {
- return None;
- }
+ if active_thread.is_empty() && editor_empty {
+ return None;
+ }
- let thread = active_thread.thread().read(cx);
- let is_generating = thread.is_generating();
- let conversation_token_usage = thread.total_token_usage()?;
+ let thread = active_thread.thread().read(cx);
+ let is_generating = thread.is_generating();
+ let conversation_token_usage = thread.total_token_usage()?;
- let (total_token_usage, is_estimating) =
- if let Some((editing_message_id, unsent_tokens)) = active_thread.editing_message_id() {
- let combined = thread
- .token_usage_up_to_message(editing_message_id)
- .add(unsent_tokens);
+ let (total_token_usage, is_estimating) =
+ if let Some((editing_message_id, unsent_tokens)) =
+ active_thread.editing_message_id()
+ {
+ let combined = thread
+ .token_usage_up_to_message(editing_message_id)
+ .add(unsent_tokens);
- (combined, unsent_tokens > 0)
- } else {
- let unsent_tokens = message_editor.last_estimated_token_count().unwrap_or(0);
- let combined = conversation_token_usage.add(unsent_tokens);
+ (combined, unsent_tokens > 0)
+ } else {
+ let unsent_tokens =
+ message_editor.last_estimated_token_count().unwrap_or(0);
+ let combined = conversation_token_usage.add(unsent_tokens);
- (combined, unsent_tokens > 0)
- };
+ (combined, unsent_tokens > 0)
+ };
- let is_waiting_to_update_token_count = message_editor.is_waiting_to_update_token_count();
+ let is_waiting_to_update_token_count =
+ message_editor.is_waiting_to_update_token_count();
- match &self.active_view {
- ActiveView::Thread { .. } => {
if total_token_usage.total == 0 {
return None;
}