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

Use languageId as key in prism generator #1617

Merged
merged 1 commit into from
Aug 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
******************************************************************************/
import { GrammarAST, type Grammar, GrammarUtils, RegExpUtils } from 'langium';
import { expandToNode, joinToNode, toString, type Generated } from 'langium/generate';
import _ from 'lodash';
import type { LangiumLanguageConfig } from '../../package-types.js';
import { collectKeywords } from '../langium-util.js';

Expand Down Expand Up @@ -47,17 +46,17 @@ export function generatePrismHighlighting(grammar: Grammar, config: LangiumLangu
pattern: `/\\b(${filteredKeywords.join('|')})\\b/${modifier}`
};

return generate(highlighter, grammar.name ?? 'unknown');
return generate(highlighter, config.id);
}

function generate(highlighter: PrismHighlighter, grammarName: string): string {
function generate(highlighter: PrismHighlighter, languageId: string): string {
/* eslint-disable @typescript-eslint/indent */
return toString(
expandToNode`
// This file is generated using a best effort guess for your language.
// It is not guaranteed contain all expected prism syntax highlighting rules.
// For more documentation, take a look at https://prismjs.com/extending.html'
Prism.languages.${_.camelCase(grammarName)} = {
Prism.languages["${languageId}"] = {
${joinToNode(
Object.entries(highlighter),
([name, value]) => {
Expand Down
Loading