Skip to content

Commit 97cd348

Browse files
devvaannshabose
authored andcommitted
fix: improve readability of isSnippetSupportedInLanguageContext function
1 parent a3a8d6f commit 97cd348

File tree

1 file changed

+9
-29
lines changed
  • src/extensionsIntegrated/CustomSnippets

1 file changed

+9
-29
lines changed

src/extensionsIntegrated/CustomSnippets/helper.js

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -314,51 +314,31 @@ define(function (require, exports, module) {
314314
* @returns {boolean} - True if the snippet is supported
315315
*/
316316
function isSnippetSupportedInLanguageContext(snippet, languageContext, editor) {
317-
// first we need to try the optimizedSnippet
318-
if (snippet.supportsAllLanguages !== undefined) {
319-
if (snippet.supportsAllLanguages) {
320-
return true;
321-
}
322-
323-
if (languageContext) {
324-
const effectiveExtension = mapLanguageToExtension(languageContext);
325-
// if we have a proper mapping (starts with .), use language context matching
326-
if (effectiveExtension.startsWith(".")) {
327-
return snippet.supportedLangSet.has(effectiveExtension);
328-
}
329-
}
330-
331-
// this is just a fallback if language context matching failed
332-
// file extension matching
333-
if (editor) {
334-
const fileExtension = getCurrentFileExtension(editor);
335-
return isSnippetSupportedInFile(snippet, fileExtension);
336-
}
337-
338-
return false;
339-
}
340-
341-
// for non-optimized snippets
342-
if (snippet.fileExtension.toLowerCase() === "all") {
317+
// Check for "all" languages support (both optimized and non-optimized)
318+
if (snippet.supportsAllLanguages === true || snippet.fileExtension?.toLowerCase() === "all") {
343319
return true;
344320
}
345321

322+
// Try language context matching if available
346323
if (languageContext) {
347324
const effectiveExtension = mapLanguageToExtension(languageContext);
348325

349326
// if we have a proper mapping (starts with .), use language context matching
350327
if (effectiveExtension.startsWith(".")) {
328+
// Use optimized path if available
329+
if (snippet.supportedLangSet) {
330+
return snippet.supportedLangSet.has(effectiveExtension);
331+
}
332+
// Fallback for non-optimized snippets
351333
const supportedExtensions = snippet.fileExtension
352334
.toLowerCase()
353335
.split(",")
354336
.map((ext) => ext.trim());
355-
356337
return supportedExtensions.some((ext) => ext === effectiveExtension);
357338
}
358339
}
359340

360-
// this is just a fallback if language context matching failed
361-
// file extension matching
341+
// final fallback for file extension matching if language context matching failed
362342
if (editor) {
363343
const fileExtension = getCurrentFileExtension(editor);
364344
return isSnippetSupportedInFile(snippet, fileExtension);

0 commit comments

Comments
 (0)