Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make missing snippet message include languages #2861

Merged
merged 3 commits into from
Feb 25, 2025
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