Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
3c0be62
feat: custom snippets working prototype
devvaannsh May 19, 2025
207b2c6
feat: integrated custom snippets with code hint manager
devvaannsh May 24, 2025
d983f29
fix: avoid duplicate snippet hints
devvaannsh May 24, 2025
bda71a5
fix: show snippet icon at the side of the hint properly
devvaannsh May 24, 2025
3685255
feat: save snippets to prefs so that it stays even on reloads
devvaannsh May 24, 2025
9621318
fix: remove popup auto-complete suggestions from appearing when input…
devvaannsh May 24, 2025
9a5c592
fix: highlight matching characters for custom snippets
devvaannsh May 24, 2025
a42e2e7
fix: all snippets are not properly shown when there are no default hints
devvaannsh May 24, 2025
64b63c2
feat: display snippet description in the code hints
devvaannsh May 25, 2025
2773542
fix: description showing at the side of the snippet instead of bottom
devvaannsh May 25, 2025
f53f84e
feat: make all the input fields mandatory
devvaannsh May 26, 2025
9c16e51
fix: tooltip not appearing when snippet hints are hovered
devvaannsh May 26, 2025
813f891
refactor: update template box from input box to textarea
devvaannsh May 26, 2025
8612bd0
refactor: update the styling of the custom snippet list
devvaannsh May 27, 2025
b831189
fix: styling issues
devvaannsh May 27, 2025
673605a
feat: add filter snippets input to the toolbar
devvaannsh May 27, 2025
7e813c4
fix: filter input not getting hidden in add snippet panel
devvaannsh May 27, 2025
3d6826b
feat: search snippets using filter input
devvaannsh May 27, 2025
c1a84e2
refactor: improve code readability
devvaannsh May 27, 2025
636d5df
feat: add snippet list header
devvaannsh May 27, 2025
08e436b
refactor: add small padding bottom in snippets list so that all conte…
devvaannsh May 27, 2025
ed56920
fix: validate file extension input values to make sure users always t…
devvaannsh May 28, 2025
2998081
fix: hide snippet header when no snippets are present
devvaannsh May 28, 2025
7e26610
fix: scrollbar invisible when not enough content to scroll
devvaannsh May 28, 2025
0be2267
refactor: reduce bottom padding for snippet list wrapper
devvaannsh May 28, 2025
2507604
refactor: increase padding for improved readability
devvaannsh May 28, 2025
bb2c3c8
refactor: add snippet UI
devvaannsh May 28, 2025
6c012e3
refactor: made placeholder text a bit lighter
devvaannsh May 28, 2025
c73d590
feat: show tooltip when add-snippet labels are hovered
devvaannsh May 28, 2025
24344ce
refactor: update '<' to '< back' button
devvaannsh May 28, 2025
0a28523
feat: made description and file extension input as optional
devvaannsh May 28, 2025
bb79634
refactor: increase input field width as content was not properly visible
devvaannsh May 28, 2025
1872cfa
feat: show edit snippet view when user clicks on a snippet
devvaannsh May 28, 2025
e53edb5
fix: remove resizer from textarea box in edit snippet menu
devvaannsh May 28, 2025
9691b1c
fix: prevent focus change when tab key is pressed inside the template…
devvaannsh May 28, 2025
8369415
fix: make the buttons UI consistent to other parts
devvaannsh May 28, 2025
6f2ebab
fix: empty snippets were getting added when save button was clicked w…
devvaannsh May 28, 2025
e429f00
feat: update toolbar title based on the current active view
devvaannsh May 28, 2025
f318761
feat: add support for tab stops
devvaannsh May 29, 2025
377c588
fix: update snippets count when a snippet is deleted
devvaannsh May 29, 2025
9a77e9f
refactor: give the delete button more padding
devvaannsh May 29, 2025
2c9632c
fix: hide snippets count when no snippets are present
devvaannsh May 29, 2025
d8ba3ab
fix: get word before cursor doesn't break at tab spacing
devvaannsh May 29, 2025
28b6bba
fix: use language mode to show snippet hints instead of file extension
devvaannsh May 31, 2025
81707b2
fix: don't allow abbreviations to be more than 30 chars
devvaannsh May 31, 2025
f606ce5
fix: pasted content is exceeding the max char limit
devvaannsh May 31, 2025
77d1438
fix: allow keyboard shortcuts to work normally on the input fields
devvaannsh May 31, 2025
cfbec00
refactor: code beautification
devvaannsh May 31, 2025
145e318
fix: add char limit to description too
devvaannsh May 31, 2025
ced13b6
refactor: use same color like keyboard shortcut panel header
devvaannsh May 31, 2025
9e42781
refactor: responsive styling
devvaannsh Jun 1, 2025
ad0b79c
refactor: add snippet and edit snippet panel UI
devvaannsh Jun 1, 2025
c72d0e0
refactor: error message styling
devvaannsh Jun 1, 2025
84498c8
refactor: move all files outside of src directory inside custom snippets
devvaannsh Jun 6, 2025
b49174e
feat: add license to all files
devvaannsh Jun 6, 2025
0b52b3b
fix: show exact matches before partial matches
devvaannsh Jun 6, 2025
31ed342
fix: description not properly visible issue
devvaannsh Jun 6, 2025
ff6d140
fix: add proper indentation when a multi line snippet is expanded
devvaannsh Jun 6, 2025
2722862
fix: remove optional chaining as its not supported
devvaannsh Jun 6, 2025
7d3cb09
feat: add showHintsAtTop api inside codehintmanager
devvaannsh Jun 7, 2025
a74eb87
fix: match api signatures to keep it consistent and removed unused code
devvaannsh Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 108 additions & 23 deletions src/editor/CodeHintManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ define(function (require, exports, module) {
codeHintsEnabled = true,
codeHintOpened = false;

// API for extensions to show hints at the top
let hintsAtTopHandler = null;

PreferencesManager.definePreference("showCodeHints", "boolean", true, {
description: Strings.DESCRIPTION_SHOW_CODE_HINTS
});
Expand Down Expand Up @@ -447,11 +450,27 @@ define(function (require, exports, module) {
return hintList.callMoveUp(callMoveUpEvent);
}

var response = sessionProvider.getHints(lastChar);
var response = null;

// Get hints from regular provider if available
if (sessionProvider) {
response = sessionProvider.getHints(lastChar);
}

lastChar = null;

// we need this to track if we used hintsAtTopHandler as fallback
// because otherwise we will end up calling it twice
var usedTopHintsAsFallback = false;

// If regular provider doesn't have hints, try hints-at-top handler
if (!response && hintsAtTopHandler && hintsAtTopHandler.getHints) {
response = hintsAtTopHandler.getHints(sessionEditor, lastChar);
usedTopHintsAsFallback = true;
}

if (!response) {
// the provider wishes to close the session
// No provider wishes to show hints, close the session
_endSession();
} else {
// if the response is true, end the session and begin another
Expand All @@ -461,6 +480,18 @@ define(function (require, exports, module) {
_endSession();
_beginSession(previousEditor);
} else if (response.hasOwnProperty("hints")) { // a synchronous response
// allow extensions to modify the response by adding hints at the top
// BUT only if we didn't already use the top hints as fallback
if (!usedTopHintsAsFallback && sessionProvider && hintsAtTopHandler && hintsAtTopHandler.getHints) {
var topHints = hintsAtTopHandler.getHints(sessionEditor, lastChar);

if (topHints && topHints.hints && topHints.hints.length > 0) {
// Prepend the top hints to the existing response
var combinedHints = topHints.hints.concat(response.hints);
response = $.extend({}, response, { hints: combinedHints });
}
}

if (hintList.isOpen()) {
// the session is open
hintList.update(response);
Expand All @@ -477,6 +508,15 @@ define(function (require, exports, module) {
if (!hintList) {
return;
}
// allow extensions to modify the response by adding hints at the top
if (sessionProvider && hintsAtTopHandler && hintsAtTopHandler.getHints) {
var topHints = hintsAtTopHandler.getHints(sessionEditor, lastChar);
if (topHints && topHints.hints && topHints.hints.length > 0) {
// Prepend the top hints to the existing response
var combinedHints = topHints.hints.concat(hints.hints);
hints = $.extend({}, hints, { hints: combinedHints });
}
}

if (hintList.isOpen()) {
// the session is open
Expand All @@ -487,7 +527,7 @@ define(function (require, exports, module) {
});
}
}
}
};

/**
* Try to begin a new hinting session.
Expand All @@ -509,48 +549,71 @@ define(function (require, exports, module) {
var language = editor.getLanguageForSelection(),
enabledProviders = _getProvidersForLanguageId(language.getId());

enabledProviders.some(function (item, index) {
if (item.provider.hasHints(editor, lastChar)) {
sessionProvider = item.provider;
return true;
}
});
// Check if hints-at-top handler has hints first to avoid duplication
var hasTopHints = false;
if (hintsAtTopHandler && hintsAtTopHandler.hasHints) {
hasTopHints = hintsAtTopHandler.hasHints(editor, lastChar);
}

// If a provider is found, initialize the hint list and update it
if (sessionProvider) {
var insertHintOnTab,
// Find a suitable provider only if hints-at-top handler doesn't have hints
if (!hasTopHints) {
enabledProviders.some(function (item, index) {
if (item.provider.hasHints(editor, lastChar)) {
sessionProvider = item.provider;
return true;
}
});
}

// If a provider is found or top hints are available, initialize the hint list and update it
if (sessionProvider || hasTopHints) {
var insertHintOnTab = PreferencesManager.get("insertHintOnTab"),
maxCodeHints = PreferencesManager.get("maxCodeHints");
if (sessionProvider.insertHintOnTab !== undefined) {

if (sessionProvider && sessionProvider.insertHintOnTab !== undefined) {
insertHintOnTab = sessionProvider.insertHintOnTab;
} else {
insertHintOnTab = PreferencesManager.get("insertHintOnTab");
}

sessionEditor = editor;
hintList = new CodeHintList(sessionEditor, insertHintOnTab, maxCodeHints);
hintList.onHighlight(function ($hint, $hintDescContainer, reason) {
if (hintList.enableDescription && $hintDescContainer && $hintDescContainer.length) {
// If the current hint provider listening for hint item highlight change
if (sessionProvider.onHighlight) {
if (sessionProvider && sessionProvider.onHighlight) {
sessionProvider.onHighlight($hint, $hintDescContainer, reason);
}

// Update the hint description
if (sessionProvider.updateHintDescription) {
if (sessionProvider && sessionProvider.updateHintDescription) {
sessionProvider.updateHintDescription($hint, $hintDescContainer);
}
} else {
if (sessionProvider.onHighlight) {
if (sessionProvider && sessionProvider.onHighlight) {
sessionProvider.onHighlight($hint, undefined, reason);
}
}
});
hintList.onSelect(function (hint) {
var restart = sessionProvider.insertHint(hint),
previousEditor = sessionEditor;
_endSession();
if (restart) {
_beginSession(previousEditor);
// allow extensions to handle special hint selections
var handled = false;
if (hintsAtTopHandler && hintsAtTopHandler.insertHint) {
handled = hintsAtTopHandler.insertHint(hint);
}

if (handled) {
// If hints-at-top handler handled it, end the session
_endSession();
} else if (sessionProvider) {
// Regular hint provider handling
var restart = sessionProvider.insertHint(hint),
previousEditor = sessionEditor;
_endSession();
if (restart) {
_beginSession(previousEditor);
}
} else {
// if none of the provider handled it, we just end the session
_endSession();
}
});
hintList.onClose(()=>{
Expand Down Expand Up @@ -697,6 +760,26 @@ define(function (require, exports, module) {
return (hintList && hintList.isOpen());
}

/**
* Register a handler to show hints at the top of the hint list.
* This API allows extensions to add their own hints at the top of the standard hint list.
*
* @param {Object} handler - A hint provider object with standard methods:
* - hasHints: function(editor, implicitChar) - returns true if hints are available
* - getHints: function(editor, implicitChar) - returns hint response object with hints array
* - insertHint: function(hint) - handles hint insertion, returns true if handled
*/
function showHintsAtTop(handler) {
hintsAtTopHandler = handler;
}

/**
* Unregister the hints at top handler.
*/
function clearHintsAtTop() {
hintsAtTopHandler = null;
}

/**
* Explicitly start a new session. If we have an existing session,
* then close the current one and restart a new one.
Expand Down Expand Up @@ -780,6 +863,8 @@ define(function (require, exports, module) {
exports.isOpen = isOpen;
exports.registerHintProvider = registerHintProvider;
exports.hasValidExclusion = hasValidExclusion;
exports.showHintsAtTop = showHintsAtTop;
exports.clearHintsAtTop = clearHintsAtTop;

exports.SELECTION_REASON = CodeHintListModule._SELECTION_REASON;
});
Loading
Loading