Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Restore token count for text threads (#36989)
Antonio Scandurrab4d4294bee68
diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rsindex 624cb5c0c68..586a782bc35 100644--- a/crates/agent_ui/src/agent_panel.rs+++ b/crates/agent_ui/src/agent_panel.rs@@ -29,7 +29,6 @@ use crate::{slash_command::SlashCommandCompletionProvider,text_thread_editor::{AgentPanelDelegate, TextThreadEditor, humanize_token_count, make_lsp_adapter_delegate,- render_remaining_tokens,},thread_history::{HistoryEntryElement, ThreadHistory},ui::{AgentOnboardingModal, EndTrialUpsell},@@ -2875,12 +2874,8 @@ impl AgentPanel {Some(token_count)}- ActiveView::TextThread { context_editor, .. } => {- let element = render_remaining_tokens(context_editor, cx)?;-- Some(element.into_any_element())- }ActiveView::ExternalAgentThread { .. }+ | ActiveView::TextThread { .. }| ActiveView::History| ActiveView::Configuration => None,}diff --git a/crates/agent_ui/src/text_thread_editor.rs b/crates/agent_ui/src/text_thread_editor.rsindex e9e7eba4b66..70ec94beead 100644--- a/crates/agent_ui/src/text_thread_editor.rs+++ b/crates/agent_ui/src/text_thread_editor.rs@@ -1857,6 +1857,53 @@ impl TextThreadEditor {.update(cx, |context, cx| context.summarize(true, cx));}+ fn render_remaining_tokens(&self, cx: &App) -> Option<impl IntoElement + use<>> {+ let (token_count_color, token_count, max_token_count, tooltip) =+ match token_state(&self.context, cx)? {+ TokenState::NoTokensLeft {+ max_token_count,+ token_count,+ } => (+ Color::Error,+ token_count,+ max_token_count,+ Some("Token Limit Reached"),+ ),+ TokenState::HasMoreTokens {+ max_token_count,+ token_count,+ over_warn_threshold,+ } => {+ let (color, tooltip) = if over_warn_threshold {+ (Color::Warning, Some("Token Limit is Close to Exhaustion"))+ } else {+ (Color::Muted, None)+ };+ (color, token_count, max_token_count, tooltip)+ }+ };++ Some(+ h_flex()+ .id("token-count")+ .gap_0p5()+ .child(+ Label::new(humanize_token_count(token_count))+ .size(LabelSize::Small)+ .color(token_count_color),+ )+ .child(Label::new("/").size(LabelSize::Small).color(Color::Muted))+ .child(+ Label::new(humanize_token_count(max_token_count))+ .size(LabelSize::Small)+ .color(Color::Muted),+ )+ .when_some(tooltip, |element, tooltip| {+ element.tooltip(Tooltip::text(tooltip))+ }),+ )+ }+fn render_send_button(&self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {let focus_handle = self.focus_handle(cx);@@ -2420,9 +2467,14 @@ impl Render for TextThreadEditor {).child(h_flex()- .gap_1()- .child(self.render_language_model_selector(window, cx))- .child(self.render_send_button(window, cx)),+ .gap_2p5()+ .children(self.render_remaining_tokens(cx))+ .child(+ h_flex()+ .gap_1()+ .child(self.render_language_model_selector(window, cx))+ .child(self.render_send_button(window, cx)),+ ),),)}@@ -2710,58 +2762,6 @@ impl FollowableItem for TextThreadEditor {}}-pub fn render_remaining_tokens(- context_editor: &Entity<TextThreadEditor>,- cx: &App,-) -> Option<impl IntoElement + use<>> {- let context = &context_editor.read(cx).context;-- let (token_count_color, token_count, max_token_count, tooltip) = match token_state(context, cx)?- {- TokenState::NoTokensLeft {- max_token_count,- token_count,- } => (- Color::Error,- token_count,- max_token_count,- Some("Token Limit Reached"),- ),- TokenState::HasMoreTokens {- max_token_count,- token_count,- over_warn_threshold,- } => {- let (color, tooltip) = if over_warn_threshold {- (Color::Warning, Some("Token Limit is Close to Exhaustion"))- } else {- (Color::Muted, None)- };- (color, token_count, max_token_count, tooltip)- }- };-- Some(- h_flex()- .id("token-count")- .gap_0p5()- .child(- Label::new(humanize_token_count(token_count))- .size(LabelSize::Small)- .color(token_count_color),- )- .child(Label::new("/").size(LabelSize::Small).color(Color::Muted))- .child(- Label::new(humanize_token_count(max_token_count))- .size(LabelSize::Small)- .color(Color::Muted),- )- .when_some(tooltip, |element, tooltip| {- element.tooltip(Tooltip::text(tooltip))- }),- )-}-enum PendingSlashCommand {}fn invoked_slash_command_fold_placeholder(