Skip to content
Merged
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion packages/cursorless-engine/src/core/getPreferredSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@ export function getPreferredSnippet(
const preferredSnippet = filteredSnippets[0];

if (preferredSnippet == null) {
throw new Error("No snippet available for the current language");
const languages = getUniqueLanguagesString(snippetDescription.snippets);
throw new Error(
`No snippet available for language '${languageId}'. Available languages: ${languages}`,
);
}

return preferredSnippet;
}

function getUniqueLanguagesString(snippets: CustomInsertSnippetArg[]): string {
const languages = new Set(
snippets.flatMap((snippet) => snippet.languages ?? []),
);
return Array.from(languages).sort().join(", ");
Comment on lines +50 to +53
Copy link
Member

@phillco phillco Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is just building the list for this one use case to construct the error message, I would just inline it. It's only two lines. Not strongly opinionated though

}

/**
* Filter snippet definitions by language.
* @param snippetDescriptions The snippets to filter
Expand Down
Loading