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

Enhance Highlighting Customization for OpenFgaDsl Language #244

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 18 additions & 13 deletions src/tools/prism/language-definition.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { OpenFgaDslThemeTokenType } from "../../theme/theme.typings";

export const languageDefinition = {
[OpenFgaDslThemeTokenType.MODULE]: {
module: {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks @Siddhant-K-code!

Can you elaborate on the change from using the enums to strings? Not sure how that helps

Copy link
Author

Choose a reason for hiding this comment

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

Why this approach?
In this, each token in the languageDefinition object has been given a more descriptive name that aligns with the default PrismJS tokens. The alias property is used to maintain the mapping to the original OpenFgaDslThemeTokenType enum values.

This approach allows for easier customization of the highlighting colors by utilizing the default PrismJS tokens, while still keeping the internal mapping to the specific OpenFgaDslThemeTokenType enum values.

I've tried to explain this approach in PR description. Let me know, if anything is clear or I could explain in better 🙏🏼

pattern: /(module\s+)[\w_-]+/i,
lookbehind: true,
alias: OpenFgaDslThemeTokenType.MODULE,
},
[OpenFgaDslThemeTokenType.TYPE]: {
type: {
pattern: /(\btype\s+)[\w_-]+/i,
lookbehind: true,
alias: OpenFgaDslThemeTokenType.TYPE,
},
[OpenFgaDslThemeTokenType.EXTEND]: {
"extend-type": {
pattern: /(\bextend type\s+)[\w_-]+/i,
lookbehind: true,
alias: OpenFgaDslThemeTokenType.EXTEND,
},
[OpenFgaDslThemeTokenType.RELATION]: {
relation: {
pattern: /(\bdefine\s+)[\w_-]+/i,
lookbehind: true,
alias: OpenFgaDslThemeTokenType.RELATION,
},
[OpenFgaDslThemeTokenType.DIRECTLY_ASSIGNABLE]: /\[.*]|self/,
[OpenFgaDslThemeTokenType.CONDITION]: {
"directly-assignable": {
pattern: /\[.*]|self/,
alias: OpenFgaDslThemeTokenType.DIRECTLY_ASSIGNABLE,
},
condition: {
pattern: /(\bcondition\s+)[\w_-]+/i,
lookbehind: true,
alias: OpenFgaDslThemeTokenType.CONDITION,
},
"condition-params": {
pattern: /\(.*\)\s*{/,
Expand All @@ -29,10 +32,12 @@ export const languageDefinition = {
"condition-param-type": /\b(string|int|map|uint|list|timestamp|bool|duration|double|ipaddress)\b/,
},
},
[OpenFgaDslThemeTokenType.COMMENT]: {
comment: {
pattern: /(^\s*|\s+)#.*/,
alias: OpenFgaDslThemeTokenType.COMMENT,
},
[OpenFgaDslThemeTokenType.KEYWORD]: {
keyword: {
pattern: /\b(type|relations|define|and|or|but not|from|as|model|schema|condition|module|extend)\b/,
alias: OpenFgaDslThemeTokenType.KEYWORD,
},
};