@@ -266,23 +266,8 @@ define(function (require, exports, module) {
266266 codeHintsEnabled = true ,
267267 codeHintOpened = false ;
268268
269- // custom snippets integration
270- // this is to check whether user has set any custom snippets as we need to show it at the first
271- let customSnippetsDriver = null ;
272- let customSnippetsGlobal = null ;
273- let customSnippetsCursorManager = null ;
274-
275- // load custom snippets driver and global
276- try {
277- customSnippetsDriver = require ( "../extensionsIntegrated/CustomSnippets/driver" ) ;
278- customSnippetsGlobal = require ( "../extensionsIntegrated/CustomSnippets/global" ) ;
279- customSnippetsCursorManager = require ( "../extensionsIntegrated/CustomSnippets/snippetCursorManager" ) ;
280- } catch ( e ) {
281- // if unable to load we just set it to null to prevent other parts of the code from breaking
282- customSnippetsDriver = null ;
283- customSnippetsGlobal = null ;
284- customSnippetsCursorManager = null ;
285- }
269+ // API for extensions to show hints at the top
270+ let hintsAtTopHandler = null ;
286271
287272 PreferencesManager . definePreference ( "showCodeHints" , "boolean" , true , {
288273 description : Strings . DESCRIPTION_SHOW_CODE_HINTS
@@ -479,9 +464,13 @@ define(function (require, exports, module) {
479464 _endSession ( ) ;
480465 _beginSession ( previousEditor ) ;
481466 } else if ( response . hasOwnProperty ( "hints" ) ) { // a synchronous response
482- // prepend custom snippets to the response
483- if ( customSnippetsDriver && customSnippetsGlobal && customSnippetsGlobal . SnippetHintsList ) {
484- response = customSnippetsDriver . prependCustomSnippets ( response , sessionEditor ) ;
467+ // 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 ) ;
473+ }
485474 }
486475
487476 if ( hintList . isOpen ( ) ) {
@@ -500,9 +489,13 @@ define(function (require, exports, module) {
500489 if ( ! hintList ) {
501490 return ;
502491 }
503- // prepend custom snippets to the response
504- if ( customSnippetsDriver && customSnippetsGlobal && customSnippetsGlobal . SnippetHintsList ) {
505- response = customSnippetsDriver . prependCustomSnippets ( response , sessionEditor ) ;
492+ // 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 ) ;
498+ }
506499 }
507500
508501 if ( hintList . isOpen ( ) ) {
@@ -573,43 +566,20 @@ define(function (require, exports, module) {
573566 }
574567 } ) ;
575568 hintList . onSelect ( function ( hint ) {
576- // check if the hint is a custom snippet
577- if ( hint && hint . jquery && hint . attr ( "data-isCustomSnippet" ) ) {
578- // handle custom snippet insertion
579- const abbreviation = hint . attr ( "data-val" ) ;
580- if ( customSnippetsDriver && customSnippetsGlobal && customSnippetsGlobal . SnippetHintsList ) {
581- const matchedSnippet = customSnippetsGlobal . SnippetHintsList . find (
582- ( snippet ) => snippet . abbreviation === abbreviation
583- ) ;
584- if ( matchedSnippet ) {
585- // replace the typed abbreviation with the template text using cursor manager
586- const wordInfo = customSnippetsDriver . getWordBeforeCursor ( ) ;
587- const start = { line : wordInfo . line , ch : wordInfo . ch + 1 } ;
588- const end = sessionEditor . getCursorPos ( ) ;
589-
590- if ( customSnippetsCursorManager ) {
591- customSnippetsCursorManager . insertSnippetWithTabStops (
592- sessionEditor ,
593- matchedSnippet . templateText ,
594- start ,
595- end
596- ) ;
597- } else {
598- // insert snippet just by replacing range if cursor manager is not available
599- sessionEditor . document . replaceRange ( matchedSnippet . templateText , start , end ) ;
600- }
601- _endSession ( ) ;
602- return ;
603- }
604- }
569+ // allow extensions to handle special hint selections
570+ var handled = false ;
571+ if ( hintsAtTopHandler && hintsAtTopHandler . handleHintSelection ) {
572+ handled = hintsAtTopHandler . handleHintSelection ( hint , sessionEditor , _endSession ) ;
605573 }
606574
607- // Regular hint provider handling
608- var restart = sessionProvider . insertHint ( hint ) ,
609- previousEditor = sessionEditor ;
610- _endSession ( ) ;
611- if ( restart ) {
612- _beginSession ( previousEditor ) ;
575+ if ( ! handled ) {
576+ // Regular hint provider handling
577+ var restart = sessionProvider . insertHint ( hint ) ,
578+ previousEditor = sessionEditor ;
579+ _endSession ( ) ;
580+ if ( restart ) {
581+ _beginSession ( previousEditor ) ;
582+ }
613583 }
614584 } ) ;
615585 hintList . onClose ( ( ) => {
@@ -756,6 +726,27 @@ define(function (require, exports, module) {
756726 return ( hintList && hintList . isOpen ( ) ) ;
757727 }
758728
729+ /**
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.
732+ *
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
738+ */
739+ function showHintsAtTop ( handler ) {
740+ hintsAtTopHandler = handler ;
741+ }
742+
743+ /**
744+ * Unregister the hints at top handler.
745+ */
746+ function clearHintsAtTop ( ) {
747+ hintsAtTopHandler = null ;
748+ }
749+
759750 /**
760751 * Explicitly start a new session. If we have an existing session,
761752 * then close the current one and restart a new one.
@@ -839,6 +830,8 @@ define(function (require, exports, module) {
839830 exports . isOpen = isOpen ;
840831 exports . registerHintProvider = registerHintProvider ;
841832 exports . hasValidExclusion = hasValidExclusion ;
833+ exports . showHintsAtTop = showHintsAtTop ;
834+ exports . clearHintsAtTop = clearHintsAtTop ;
842835
843836 exports . SELECTION_REASON = CodeHintListModule . _SELECTION_REASON ;
844837} ) ;
0 commit comments