@@ -221,14 +221,7 @@ pub struct ChatHinter {
221221
222222impl ChatHinter {
223223 /// 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 {
232225 Self {
233226 history : Vec :: new ( ) ,
234227 history_hints_enabled,
@@ -237,7 +230,8 @@ impl ChatHinter {
237230
238231 /// Updates the history with a new command
239232 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' ) {
241235 self . history . push ( command. to_string ( ) ) ;
242236 }
243237 }
@@ -382,11 +376,19 @@ pub fn rl(
382376 . completion_type ( CompletionType :: List )
383377 . edit_mode ( edit_mode)
384378 . 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 ) ;
385386 let h = ChatHelper {
386387 completer : ChatCompleter :: new ( sender, receiver) ,
387- hinter : ChatHinter :: new ( os ) ,
388+ hinter : ChatHinter :: new ( history_hints_enabled ) ,
388389 validator : MultiLineValidator ,
389390 } ;
391+
390392 let mut rl = Editor :: with_config ( config) ?;
391393 rl. set_helper ( Some ( h) ) ;
392394
@@ -417,27 +419,6 @@ mod tests {
417419 use rustyline:: highlight:: Highlighter ;
418420
419421 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- }
441422
442423 #[ test]
443424 fn test_chat_completer_command_completion ( ) {
@@ -484,10 +465,9 @@ mod tests {
484465 fn test_highlight_prompt_basic ( ) {
485466 let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
486467 let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
487- let mock_os = create_mock_os ( ) ;
488468 let helper = ChatHelper {
489469 completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
490- hinter : ChatHinter :: new ( & mock_os ) ,
470+ hinter : ChatHinter :: new ( true ) ,
491471 validator : MultiLineValidator ,
492472 } ;
493473
@@ -501,10 +481,9 @@ mod tests {
501481 fn test_highlight_prompt_with_warning ( ) {
502482 let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
503483 let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
504- let mock_os = create_mock_os ( ) ;
505484 let helper = ChatHelper {
506485 completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
507- hinter : ChatHinter :: new ( & mock_os ) ,
486+ hinter : ChatHinter :: new ( true ) ,
508487 validator : MultiLineValidator ,
509488 } ;
510489
@@ -518,10 +497,9 @@ mod tests {
518497 fn test_highlight_prompt_with_profile ( ) {
519498 let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
520499 let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
521- let mock_os = create_mock_os ( ) ;
522500 let helper = ChatHelper {
523501 completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
524- hinter : ChatHinter :: new ( & mock_os ) ,
502+ hinter : ChatHinter :: new ( true ) ,
525503 validator : MultiLineValidator ,
526504 } ;
527505
@@ -535,10 +513,9 @@ mod tests {
535513 fn test_highlight_prompt_with_profile_and_warning ( ) {
536514 let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
537515 let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
538- let mock_os = create_mock_os ( ) ;
539516 let helper = ChatHelper {
540517 completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
541- hinter : ChatHinter :: new ( & mock_os ) ,
518+ hinter : ChatHinter :: new ( true ) ,
542519 validator : MultiLineValidator ,
543520 } ;
544521
@@ -555,10 +532,9 @@ mod tests {
555532 fn test_highlight_prompt_invalid_format ( ) {
556533 let ( prompt_request_sender, _) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
557534 let ( _, prompt_response_receiver) = std:: sync:: mpsc:: channel :: < Vec < String > > ( ) ;
558- let mock_os = create_mock_os ( ) ;
559535 let helper = ChatHelper {
560536 completer : ChatCompleter :: new ( prompt_request_sender, prompt_response_receiver) ,
561- hinter : ChatHinter :: new ( & mock_os ) ,
537+ hinter : ChatHinter :: new ( true ) ,
562538 validator : MultiLineValidator ,
563539 } ;
564540
@@ -570,8 +546,7 @@ mod tests {
570546
571547 #[ test]
572548 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 ) ;
575550
576551 // Test hint for a command
577552 let line = "/he" ;
@@ -591,51 +566,29 @@ mod tests {
591566 let pos = line. len ( ) ;
592567 let hint = hinter. hint ( line, pos, & ctx) ;
593568 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?" ) ;
604569
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 " ;
607572 let pos = line. len ( ) ;
608- let empty_history = DefaultHistory :: new ( ) ;
609- let ctx = Context :: new ( & empty_history) ;
610-
611573 let hint = hinter. hint ( line, pos, & ctx) ;
612574 assert_eq ! ( hint, None ) ;
613575 }
614576
615577 #[ 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 ) ;
627580
628581 // Add some history
629582 hinter. update_history ( "Hello, world!" ) ;
630583 hinter. update_history ( "How are you?" ) ;
631584
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
633586 let line = "How" ;
634587 let pos = line. len ( ) ;
635588 let empty_history = DefaultHistory :: new ( ) ;
636589 let ctx = Context :: new ( & empty_history) ;
637590
638591 let hint = hinter. hint ( line, pos, & ctx) ;
639- assert_eq ! ( hint, Some ( " are you?" . to_string ( ) ) ) ;
592+ assert_eq ! ( hint, None ) ;
640593 }
641594}
0 commit comments