diff --git a/package.json b/package.json index 0bfe00f2..42017453 100644 --- a/package.json +++ b/package.json @@ -136,6 +136,11 @@ "type": "boolean", "default": false, "description": "Controls whether borders should be enabled on some additional UI elements." + }, + "catppuccin.underlinedSemanticTokens": { + "type": "boolean", + "default": false, + "description": "Controls whether semantic tokens should appear as underlined." } } } diff --git a/src/theme/index.ts b/src/theme/index.ts index 0d035fb4..36c1faad 100644 --- a/src/theme/index.ts +++ b/src/theme/index.ts @@ -21,6 +21,7 @@ export const defaultOptions: ThemeOptions = { bracketMode: "rainbow", extraBordersEnabled: false, customUIColors: {}, + underlinedSemanticTokens: false, }; export const compileTheme = ( diff --git a/src/theme/semanticTokens.ts b/src/theme/semanticTokens.ts index 6ebbf59d..9faa4cd9 100644 --- a/src/theme/semanticTokens.ts +++ b/src/theme/semanticTokens.ts @@ -1,9 +1,9 @@ import type { SemanticTokens, ThemeContext } from "@/types"; export const getSemanticTokens = (context: ThemeContext): SemanticTokens => { - const { palette } = context; + const { palette, options } = context; - return { + let mappings: SemanticTokens = { enumMember: { foreground: palette.teal }, selfKeyword: { foreground: palette.red }, "variable.defaultLibrary": { foreground: palette.maroon }, @@ -47,4 +47,19 @@ export const getSemanticTokens = (context: ThemeContext): SemanticTokens => { "text.math": { foreground: palette.flamingo }, pol: { foreground: palette.flamingo }, }; + + if (options.underlinedSemanticTokens) { + mappings = Object.entries(mappings).reduce((acc, [k, v]) => { + if (typeof v === "string") return acc; + return { + ...acc, + [k]: { + ...v, + underline: true, + }, + }; + }, {}); + } + + return mappings; }; diff --git a/src/types/index.d.ts b/src/types/index.d.ts index a38af656..b578e785 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -66,6 +66,7 @@ export type ThemeOptions = { bracketMode: CatppuccinBracketMode; extraBordersEnabled: boolean; customUIColors: CustomUIColors; + underlinedSemanticTokens: boolean; }; export type ThemePaths = { diff --git a/src/utils.ts b/src/utils.ts index 7ee2d90c..c6efa35f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -112,7 +112,8 @@ export const getConfiguration = (): ThemeOptions => { bracketMode: conf.get("bracketMode"), extraBordersEnabled: conf.get("extraBordersEnabled"), customUIColors: conf.get("customUIColors"), - }; + underlinedSemanticTokens: conf.get("underlinedSemanticTokens"), + } satisfies Partial; return { ...defaultOptions, ...filterObject(options, ([, value]) => value !== undefined),