@@ -450,11 +450,27 @@ define(function (require, exports, module) {
450450 return hintList . callMoveUp ( callMoveUpEvent ) ;
451451 }
452452
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+
454460 lastChar = null ;
455461
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+
456472 if ( ! response ) {
457- // the provider wishes to close the session
473+ // No provider wishes to show hints, close the session
458474 _endSession ( ) ;
459475 } else {
460476 // if the response is true, end the session and begin another
@@ -465,11 +481,14 @@ define(function (require, exports, module) {
465481 _beginSession ( previousEditor ) ;
466482 } else if ( response . hasOwnProperty ( "hints" ) ) { // a synchronous response
467483 // 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 } ) ;
473492 }
474493 }
475494
@@ -490,11 +509,12 @@ define(function (require, exports, module) {
490509 return ;
491510 }
492511 // 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 } ) ;
498518 }
499519 }
500520
@@ -507,7 +527,7 @@ define(function (require, exports, module) {
507527 } ) ;
508528 }
509529 }
510- }
530+ } ;
511531
512532 /**
513533 * Try to begin a new hinting session.
@@ -529,57 +549,71 @@ define(function (require, exports, module) {
529549 var language = editor . getLanguageForSelection ( ) ,
530550 enabledProviders = _getProvidersForLanguageId ( language . getId ( ) ) ;
531551
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+ }
538557
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" ) ,
542571 maxCodeHints = PreferencesManager . get ( "maxCodeHints" ) ;
543- if ( sessionProvider . insertHintOnTab !== undefined ) {
572+
573+ if ( sessionProvider && sessionProvider . insertHintOnTab !== undefined ) {
544574 insertHintOnTab = sessionProvider . insertHintOnTab ;
545- } else {
546- insertHintOnTab = PreferencesManager . get ( "insertHintOnTab" ) ;
547575 }
548576
549577 sessionEditor = editor ;
550578 hintList = new CodeHintList ( sessionEditor , insertHintOnTab , maxCodeHints ) ;
551579 hintList . onHighlight ( function ( $hint , $hintDescContainer , reason ) {
552580 if ( hintList . enableDescription && $hintDescContainer && $hintDescContainer . length ) {
553581 // If the current hint provider listening for hint item highlight change
554- if ( sessionProvider . onHighlight ) {
582+ if ( sessionProvider && sessionProvider . onHighlight ) {
555583 sessionProvider . onHighlight ( $hint , $hintDescContainer , reason ) ;
556584 }
557585
558586 // Update the hint description
559- if ( sessionProvider . updateHintDescription ) {
587+ if ( sessionProvider && sessionProvider . updateHintDescription ) {
560588 sessionProvider . updateHintDescription ( $hint , $hintDescContainer ) ;
561589 }
562590 } else {
563- if ( sessionProvider . onHighlight ) {
591+ if ( sessionProvider && sessionProvider . onHighlight ) {
564592 sessionProvider . onHighlight ( $hint , undefined , reason ) ;
565593 }
566594 }
567595 } ) ;
568596 hintList . onSelect ( function ( hint ) {
569597 // allow extensions to handle special hint selections
570598 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 ) ;
573601 }
574602
575- if ( ! handled ) {
603+ if ( handled ) {
604+ // If hints-at-top handler handled it, end the session
605+ _endSession ( ) ;
606+ } else if ( sessionProvider ) {
576607 // Regular hint provider handling
577608 var restart = sessionProvider . insertHint ( hint ) ,
578609 previousEditor = sessionEditor ;
579610 _endSession ( ) ;
580611 if ( restart ) {
581612 _beginSession ( previousEditor ) ;
582613 }
614+ } else {
615+ // if none of the provider handled it, we just end the session
616+ _endSession ( ) ;
583617 }
584618 } ) ;
585619 hintList . onClose ( ( ) => {
@@ -727,14 +761,13 @@ define(function (require, exports, module) {
727761 }
728762
729763 /**
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.
732766 *
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
738771 */
739772 function showHintsAtTop ( handler ) {
740773 hintsAtTopHandler = handler ;
0 commit comments