@@ -450,11 +450,27 @@ define(function (require, exports, module) {
450
450
return hintList . callMoveUp ( callMoveUpEvent ) ;
451
451
}
452
452
453
- var response = sessionProvider . getHints ( lastChar ) ;
453
+ var response = null ;
454
+
455
+ // Get hints from regular provider if available
456
+ if ( sessionProvider ) {
457
+ response = sessionProvider . getHints ( lastChar ) ;
458
+ }
459
+
454
460
lastChar = null ;
455
461
462
+ // we need this to track if we used hintsAtTopHandler as fallback
463
+ // because otherwise we will end up calling it twice
464
+ var usedTopHintsAsFallback = false ;
465
+
466
+ // If regular provider doesn't have hints, try hints-at-top handler
467
+ if ( ! response && hintsAtTopHandler && hintsAtTopHandler . getHints ) {
468
+ response = hintsAtTopHandler . getHints ( sessionEditor , lastChar ) ;
469
+ usedTopHintsAsFallback = true ;
470
+ }
471
+
456
472
if ( ! response ) {
457
- // the provider wishes to close the session
473
+ // No provider wishes to show hints, close the session
458
474
_endSession ( ) ;
459
475
} else {
460
476
// if the response is true, end the session and begin another
@@ -465,11 +481,14 @@ define(function (require, exports, module) {
465
481
_beginSession ( previousEditor ) ;
466
482
} else if ( response . hasOwnProperty ( "hints" ) ) { // a synchronous response
467
483
// allow extensions to modify the response by adding hints at the top
468
- if ( hintsAtTopHandler ) {
469
- if ( typeof hintsAtTopHandler === 'function' ) {
470
- response = hintsAtTopHandler ( response , sessionEditor ) ;
471
- } else if ( hintsAtTopHandler . prepend ) {
472
- response = hintsAtTopHandler . prepend ( response , sessionEditor ) ;
484
+ // BUT only if we didn't already use the top hints as fallback
485
+ if ( ! usedTopHintsAsFallback && sessionProvider && hintsAtTopHandler && hintsAtTopHandler . getHints ) {
486
+ var topHints = hintsAtTopHandler . getHints ( sessionEditor , lastChar ) ;
487
+
488
+ if ( topHints && topHints . hints && topHints . hints . length > 0 ) {
489
+ // Prepend the top hints to the existing response
490
+ var combinedHints = topHints . hints . concat ( response . hints ) ;
491
+ response = $ . extend ( { } , response , { hints : combinedHints } ) ;
473
492
}
474
493
}
475
494
@@ -490,11 +509,12 @@ define(function (require, exports, module) {
490
509
return ;
491
510
}
492
511
// allow extensions to modify the response by adding hints at the top
493
- if ( hintsAtTopHandler ) {
494
- if ( typeof hintsAtTopHandler === 'function' ) {
495
- hints = hintsAtTopHandler ( hints , sessionEditor ) ;
496
- } else if ( hintsAtTopHandler . prepend ) {
497
- hints = hintsAtTopHandler . prepend ( hints , sessionEditor ) ;
512
+ if ( sessionProvider && hintsAtTopHandler && hintsAtTopHandler . getHints ) {
513
+ var topHints = hintsAtTopHandler . getHints ( sessionEditor , lastChar ) ;
514
+ if ( topHints && topHints . hints && topHints . hints . length > 0 ) {
515
+ // Prepend the top hints to the existing response
516
+ var combinedHints = topHints . hints . concat ( hints . hints ) ;
517
+ hints = $ . extend ( { } , hints , { hints : combinedHints } ) ;
498
518
}
499
519
}
500
520
@@ -507,7 +527,7 @@ define(function (require, exports, module) {
507
527
} ) ;
508
528
}
509
529
}
510
- }
530
+ } ;
511
531
512
532
/**
513
533
* Try to begin a new hinting session.
@@ -529,57 +549,71 @@ define(function (require, exports, module) {
529
549
var language = editor . getLanguageForSelection ( ) ,
530
550
enabledProviders = _getProvidersForLanguageId ( language . getId ( ) ) ;
531
551
532
- enabledProviders . some ( function ( item , index ) {
533
- if ( item . provider . hasHints ( editor , lastChar ) ) {
534
- sessionProvider = item . provider ;
535
- return true ;
536
- }
537
- } ) ;
552
+ // Check if hints-at-top handler has hints first to avoid duplication
553
+ var hasTopHints = false ;
554
+ if ( hintsAtTopHandler && hintsAtTopHandler . hasHints ) {
555
+ hasTopHints = hintsAtTopHandler . hasHints ( editor , lastChar ) ;
556
+ }
538
557
539
- // If a provider is found, initialize the hint list and update it
540
- if ( sessionProvider ) {
541
- var insertHintOnTab ,
558
+ // Find a suitable provider only if hints-at-top handler doesn't have hints
559
+ if ( ! hasTopHints ) {
560
+ enabledProviders . some ( function ( item , index ) {
561
+ if ( item . provider . hasHints ( editor , lastChar ) ) {
562
+ sessionProvider = item . provider ;
563
+ return true ;
564
+ }
565
+ } ) ;
566
+ }
567
+
568
+ // If a provider is found or top hints are available, initialize the hint list and update it
569
+ if ( sessionProvider || hasTopHints ) {
570
+ var insertHintOnTab = PreferencesManager . get ( "insertHintOnTab" ) ,
542
571
maxCodeHints = PreferencesManager . get ( "maxCodeHints" ) ;
543
- if ( sessionProvider . insertHintOnTab !== undefined ) {
572
+
573
+ if ( sessionProvider && sessionProvider . insertHintOnTab !== undefined ) {
544
574
insertHintOnTab = sessionProvider . insertHintOnTab ;
545
- } else {
546
- insertHintOnTab = PreferencesManager . get ( "insertHintOnTab" ) ;
547
575
}
548
576
549
577
sessionEditor = editor ;
550
578
hintList = new CodeHintList ( sessionEditor , insertHintOnTab , maxCodeHints ) ;
551
579
hintList . onHighlight ( function ( $hint , $hintDescContainer , reason ) {
552
580
if ( hintList . enableDescription && $hintDescContainer && $hintDescContainer . length ) {
553
581
// If the current hint provider listening for hint item highlight change
554
- if ( sessionProvider . onHighlight ) {
582
+ if ( sessionProvider && sessionProvider . onHighlight ) {
555
583
sessionProvider . onHighlight ( $hint , $hintDescContainer , reason ) ;
556
584
}
557
585
558
586
// Update the hint description
559
- if ( sessionProvider . updateHintDescription ) {
587
+ if ( sessionProvider && sessionProvider . updateHintDescription ) {
560
588
sessionProvider . updateHintDescription ( $hint , $hintDescContainer ) ;
561
589
}
562
590
} else {
563
- if ( sessionProvider . onHighlight ) {
591
+ if ( sessionProvider && sessionProvider . onHighlight ) {
564
592
sessionProvider . onHighlight ( $hint , undefined , reason ) ;
565
593
}
566
594
}
567
595
} ) ;
568
596
hintList . onSelect ( function ( hint ) {
569
597
// allow extensions to handle special hint selections
570
598
var handled = false ;
571
- if ( hintsAtTopHandler && hintsAtTopHandler . handleHintSelection ) {
572
- handled = hintsAtTopHandler . handleHintSelection ( hint , sessionEditor , _endSession ) ;
599
+ if ( hintsAtTopHandler && hintsAtTopHandler . insertHint ) {
600
+ handled = hintsAtTopHandler . insertHint ( hint ) ;
573
601
}
574
602
575
- if ( ! handled ) {
603
+ if ( handled ) {
604
+ // If hints-at-top handler handled it, end the session
605
+ _endSession ( ) ;
606
+ } else if ( sessionProvider ) {
576
607
// Regular hint provider handling
577
608
var restart = sessionProvider . insertHint ( hint ) ,
578
609
previousEditor = sessionEditor ;
579
610
_endSession ( ) ;
580
611
if ( restart ) {
581
612
_beginSession ( previousEditor ) ;
582
613
}
614
+ } else {
615
+ // if none of the provider handled it, we just end the session
616
+ _endSession ( ) ;
583
617
}
584
618
} ) ;
585
619
hintList . onClose ( ( ) => {
@@ -727,14 +761,13 @@ define(function (require, exports, module) {
727
761
}
728
762
729
763
/**
730
- * Register a handler to modify hints at the top of the hint list.
731
- * This API allows extensions to prepend their own hints to the standard hint list.
764
+ * Register a handler to show hints at the top of the hint list.
765
+ * This API allows extensions to add their own hints at the top of the standard hint list.
732
766
*
733
- * @param {Function|Object } handler - Either a function that takes (response, editor) and returns
734
- * a modified response, or an object with:
735
- * - prepend: function(response, editor) - modify the hint response
736
- * - handleHintSelection: function(hint, editor, endSession) - handle hint selection
737
- * returns true if handled, false otherwise
767
+ * @param {Object } handler - A hint provider object with standard methods:
768
+ * - hasHints: function(editor, implicitChar) - returns true if hints are available
769
+ * - getHints: function(editor, implicitChar) - returns hint response object with hints array
770
+ * - insertHint: function(hint) - handles hint insertion, returns true if handled
738
771
*/
739
772
function showHintsAtTop ( handler ) {
740
773
hintsAtTopHandler = handler ;
0 commit comments