@@ -1857,6 +1857,53 @@ impl TextThreadEditor {
1857
1857
. update ( cx, |context, cx| context. summarize ( true , cx) ) ;
1858
1858
}
1859
1859
1860
+ fn render_remaining_tokens ( & self , cx : & App ) -> Option < impl IntoElement + use < > > {
1861
+ let ( token_count_color, token_count, max_token_count, tooltip) =
1862
+ match token_state ( & self . context , cx) ? {
1863
+ TokenState :: NoTokensLeft {
1864
+ max_token_count,
1865
+ token_count,
1866
+ } => (
1867
+ Color :: Error ,
1868
+ token_count,
1869
+ max_token_count,
1870
+ Some ( "Token Limit Reached" ) ,
1871
+ ) ,
1872
+ TokenState :: HasMoreTokens {
1873
+ max_token_count,
1874
+ token_count,
1875
+ over_warn_threshold,
1876
+ } => {
1877
+ let ( color, tooltip) = if over_warn_threshold {
1878
+ ( Color :: Warning , Some ( "Token Limit is Close to Exhaustion" ) )
1879
+ } else {
1880
+ ( Color :: Muted , None )
1881
+ } ;
1882
+ ( color, token_count, max_token_count, tooltip)
1883
+ }
1884
+ } ;
1885
+
1886
+ Some (
1887
+ h_flex ( )
1888
+ . id ( "token-count" )
1889
+ . gap_0p5 ( )
1890
+ . child (
1891
+ Label :: new ( humanize_token_count ( token_count) )
1892
+ . size ( LabelSize :: Small )
1893
+ . color ( token_count_color) ,
1894
+ )
1895
+ . child ( Label :: new ( "/" ) . size ( LabelSize :: Small ) . color ( Color :: Muted ) )
1896
+ . child (
1897
+ Label :: new ( humanize_token_count ( max_token_count) )
1898
+ . size ( LabelSize :: Small )
1899
+ . color ( Color :: Muted ) ,
1900
+ )
1901
+ . when_some ( tooltip, |element, tooltip| {
1902
+ element. tooltip ( Tooltip :: text ( tooltip) )
1903
+ } ) ,
1904
+ )
1905
+ }
1906
+
1860
1907
fn render_send_button ( & self , window : & mut Window , cx : & mut Context < Self > ) -> impl IntoElement {
1861
1908
let focus_handle = self . focus_handle ( cx) ;
1862
1909
@@ -2420,9 +2467,14 @@ impl Render for TextThreadEditor {
2420
2467
)
2421
2468
. child (
2422
2469
h_flex ( )
2423
- . gap_1 ( )
2424
- . child ( self . render_language_model_selector ( window, cx) )
2425
- . child ( self . render_send_button ( window, cx) ) ,
2470
+ . gap_2p5 ( )
2471
+ . children ( self . render_remaining_tokens ( cx) )
2472
+ . child (
2473
+ h_flex ( )
2474
+ . gap_1 ( )
2475
+ . child ( self . render_language_model_selector ( window, cx) )
2476
+ . child ( self . render_send_button ( window, cx) ) ,
2477
+ ) ,
2426
2478
) ,
2427
2479
)
2428
2480
}
@@ -2710,58 +2762,6 @@ impl FollowableItem for TextThreadEditor {
2710
2762
}
2711
2763
}
2712
2764
2713
- pub fn render_remaining_tokens (
2714
- context_editor : & Entity < TextThreadEditor > ,
2715
- cx : & App ,
2716
- ) -> Option < impl IntoElement + use < > > {
2717
- let context = & context_editor. read ( cx) . context ;
2718
-
2719
- let ( token_count_color, token_count, max_token_count, tooltip) = match token_state ( context, cx) ?
2720
- {
2721
- TokenState :: NoTokensLeft {
2722
- max_token_count,
2723
- token_count,
2724
- } => (
2725
- Color :: Error ,
2726
- token_count,
2727
- max_token_count,
2728
- Some ( "Token Limit Reached" ) ,
2729
- ) ,
2730
- TokenState :: HasMoreTokens {
2731
- max_token_count,
2732
- token_count,
2733
- over_warn_threshold,
2734
- } => {
2735
- let ( color, tooltip) = if over_warn_threshold {
2736
- ( Color :: Warning , Some ( "Token Limit is Close to Exhaustion" ) )
2737
- } else {
2738
- ( Color :: Muted , None )
2739
- } ;
2740
- ( color, token_count, max_token_count, tooltip)
2741
- }
2742
- } ;
2743
-
2744
- Some (
2745
- h_flex ( )
2746
- . id ( "token-count" )
2747
- . gap_0p5 ( )
2748
- . child (
2749
- Label :: new ( humanize_token_count ( token_count) )
2750
- . size ( LabelSize :: Small )
2751
- . color ( token_count_color) ,
2752
- )
2753
- . child ( Label :: new ( "/" ) . size ( LabelSize :: Small ) . color ( Color :: Muted ) )
2754
- . child (
2755
- Label :: new ( humanize_token_count ( max_token_count) )
2756
- . size ( LabelSize :: Small )
2757
- . color ( Color :: Muted ) ,
2758
- )
2759
- . when_some ( tooltip, |element, tooltip| {
2760
- element. tooltip ( Tooltip :: text ( tooltip) )
2761
- } ) ,
2762
- )
2763
- }
2764
-
2765
2765
enum PendingSlashCommand { }
2766
2766
2767
2767
fn invoked_slash_command_fold_placeholder (
0 commit comments