@@ -221,14 +221,7 @@ pub struct ChatHinter {
221
221
222
222
impl ChatHinter {
223
223
/// Creates a new ChatHinter instance
224
- pub fn new ( os : & Os ) -> Self {
225
- // Default to disabled if setting doesn't exist
226
- let history_hints_enabled = os
227
- . database
228
- . settings
229
- . get_bool ( Setting :: ChatEnableHistoryHints )
230
- . unwrap_or ( false ) ;
231
-
224
+ pub fn new ( history_hints_enabled : bool ) -> Self {
232
225
Self {
233
226
history : Vec :: new ( ) ,
234
227
history_hints_enabled,
@@ -237,7 +230,8 @@ impl ChatHinter {
237
230
238
231
/// Updates the history with a new command
239
232
pub fn update_history ( & mut self , command : & str ) {
240
- if !command. trim ( ) . is_empty ( ) {
233
+ let command = command. trim ( ) ;
234
+ if !command. is_empty ( ) && !command. contains ( '\n' ) && !command. contains ( '\r' ) {
241
235
self . history . push ( command. to_string ( ) ) ;
242
236
}
243
237
}
@@ -382,11 +376,19 @@ pub fn rl(
382
376
. completion_type ( CompletionType :: List )
383
377
. edit_mode ( edit_mode)
384
378
. build ( ) ;
379
+
380
+ // Default to disabled if setting doesn't exist
381
+ let history_hints_enabled = os
382
+ . database
383
+ . settings
384
+ . get_bool ( Setting :: ChatEnableHistoryHints )
385
+ . unwrap_or ( false ) ;
385
386
let h = ChatHelper {
386
387
completer : ChatCompleter :: new ( sender, receiver) ,
387
- hinter : ChatHinter :: new ( os ) ,
388
+ hinter : ChatHinter :: new ( history_hints_enabled ) ,
388
389
validator : MultiLineValidator ,
389
390
} ;
391
+
390
392
let mut rl = Editor :: with_config ( config) ?;
391
393
rl. set_helper ( Some ( h) ) ;
392
394
@@ -417,27 +419,6 @@ mod tests {
417
419
use rustyline:: highlight:: Highlighter ;
418
420
419
421
use super :: * ;
420
- use crate :: database:: Settings ;
421
- use crate :: os:: {
422
- Fs ,
423
- Os ,
424
- } ;
425
-
426
- // Helper function to create a mock Os for testing
427
- fn create_mock_os ( ) -> Os {
428
- let mut os = Os {
429
- database : crate :: database:: Database {
430
- pool : r2d2:: Pool :: builder ( )
431
- . build ( r2d2_sqlite:: SqliteConnectionManager :: memory ( ) )
432
- . unwrap ( ) ,
433
- settings : Settings :: default ( ) ,
434
- } ,
435
- fs : Fs :: new ( ) ,
436
- env : crate :: os:: Env :: new ( ) ,
437
- telemetry : crate :: telemetry:: Telemetry :: new ( ) ,
438
- } ;
439
- os
440
- }
441
422
442
423
#[ test]
443
424
fn test_chat_completer_command_completion ( ) {
@@ -484,10 +465,9 @@ mod tests {
484
465
fn test_highlight_prompt_basic ( ) {
485
466
let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
486
467
let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
487
- let mock_os = create_mock_os ( ) ;
488
468
let helper = ChatHelper {
489
469
completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
490
- hinter : ChatHinter :: new ( & mock_os ) ,
470
+ hinter : ChatHinter :: new ( true ) ,
491
471
validator : MultiLineValidator ,
492
472
} ;
493
473
@@ -501,10 +481,9 @@ mod tests {
501
481
fn test_highlight_prompt_with_warning ( ) {
502
482
let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
503
483
let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
504
- let mock_os = create_mock_os ( ) ;
505
484
let helper = ChatHelper {
506
485
completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
507
- hinter : ChatHinter :: new ( & mock_os ) ,
486
+ hinter : ChatHinter :: new ( true ) ,
508
487
validator : MultiLineValidator ,
509
488
} ;
510
489
@@ -518,10 +497,9 @@ mod tests {
518
497
fn test_highlight_prompt_with_profile ( ) {
519
498
let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
520
499
let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
521
- let mock_os = create_mock_os ( ) ;
522
500
let helper = ChatHelper {
523
501
completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
524
- hinter : ChatHinter :: new ( & mock_os ) ,
502
+ hinter : ChatHinter :: new ( true ) ,
525
503
validator : MultiLineValidator ,
526
504
} ;
527
505
@@ -535,10 +513,9 @@ mod tests {
535
513
fn test_highlight_prompt_with_profile_and_warning ( ) {
536
514
let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
537
515
let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
538
- let mock_os = create_mock_os ( ) ;
539
516
let helper = ChatHelper {
540
517
completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
541
- hinter : ChatHinter :: new ( & mock_os ) ,
518
+ hinter : ChatHinter :: new ( true ) ,
542
519
validator : MultiLineValidator ,
543
520
} ;
544
521
@@ -555,10 +532,9 @@ mod tests {
555
532
fn test_highlight_prompt_invalid_format ( ) {
556
533
let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
557
534
let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
558
- let mock_os = create_mock_os ( ) ;
559
535
let helper = ChatHelper {
560
536
completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
561
- hinter : ChatHinter :: new ( & mock_os ) ,
537
+ hinter : ChatHinter :: new ( true ) ,
562
538
validator : MultiLineValidator ,
563
539
} ;
564
540
@@ -570,8 +546,7 @@ mod tests {
570
546
571
547
#[ test]
572
548
fn test_chat_hinter_command_hint ( ) {
573
- let mock_os = create_mock_os ( ) ;
574
- let hinter = ChatHinter :: new ( & mock_os) ;
549
+ let hinter = ChatHinter :: new ( true ) ;
575
550
576
551
// Test hint for a command
577
552
let line = "/he" ;
@@ -591,51 +566,29 @@ mod tests {
591
566
let pos = line. len ( ) ;
592
567
let hint = hinter. hint ( line, pos, & ctx) ;
593
568
assert_eq ! ( hint, None ) ;
594
- }
595
-
596
- #[ test]
597
- fn test_chat_hinter_history_hint_disabled ( ) {
598
- let mock_os = create_mock_os ( ) ;
599
- let mut hinter = ChatHinter :: new ( & mock_os) ; // Default is disabled
600
-
601
- // Add some history
602
- hinter. update_history ( "Hello, world!" ) ;
603
- hinter. update_history ( "How are you?" ) ;
604
569
605
- // Test hint from history - should be None since history hints are disabled
606
- let line = "How " ;
570
+ // Test hint for a multi-line command
571
+ let line = "/abcd \n efg " ;
607
572
let pos = line. len ( ) ;
608
- let empty_history = DefaultHistory :: new ( ) ;
609
- let ctx = Context :: new ( & empty_history) ;
610
-
611
573
let hint = hinter. hint ( line, pos, & ctx) ;
612
574
assert_eq ! ( hint, None ) ;
613
575
}
614
576
615
577
#[ test]
616
- fn test_chat_hinter_history_hint_enabled ( ) {
617
- let mut mock_os = create_mock_os ( ) ;
618
-
619
- // Enable history hints
620
- mock_os
621
- . database
622
- . settings
623
- . 0
624
- . insert ( "chat.enableHistoryHints" . to_string ( ) , serde_json:: Value :: Bool ( true ) ) ;
625
-
626
- let mut hinter = ChatHinter :: new ( & mock_os) ;
578
+ fn test_chat_hinter_history_hint_disabled ( ) {
579
+ let mut hinter = ChatHinter :: new ( false ) ;
627
580
628
581
// Add some history
629
582
hinter. update_history ( "Hello, world!" ) ;
630
583
hinter. update_history ( "How are you?" ) ;
631
584
632
- // Test hint from history - should work since history hints are enabled
585
+ // Test hint from history - should be None since history hints are disabled
633
586
let line = "How" ;
634
587
let pos = line. len ( ) ;
635
588
let empty_history = DefaultHistory :: new ( ) ;
636
589
let ctx = Context :: new ( & empty_history) ;
637
590
638
591
let hint = hinter. hint ( line, pos, & ctx) ;
639
- assert_eq ! ( hint, Some ( " are you?" . to_string ( ) ) ) ;
592
+ assert_eq ! ( hint, None ) ;
640
593
}
641
594
}
0 commit comments