From f66f0980f2c6abc66d04f64c2ac2b65e52a3cc92 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 21 May 2025 11:49:00 -0700 Subject: [PATCH] theme logic fix for setting fallbacks in jetbrains --- .../continue/GetTheme.kt | 2 +- gui/src/styles/ThemePage.tsx | 102 ++++++++---------- gui/src/styles/theme.ts | 81 +++++++------- 3 files changed, 90 insertions(+), 95 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/GetTheme.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/GetTheme.kt index 7fbc21cf4..5fe10d011 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/GetTheme.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/GetTheme.kt @@ -102,8 +102,8 @@ class GetTheme { ?: EditorColorsManager.getInstance().globalScheme.getAttributes(CodeInsightColors.WARNINGS_ATTRIBUTES)?.effectColor ?: namedColor("Component.warningForeground") ?: namedColor("Label.warningForeground") - val errorColor = namedColor("ValidationError.errorColor") ?: namedColor("Component.errorForeground") ?: namedColor("Label.errorForeground") + val accentColor = namedColor("Focus.defaultButtonBorderColor") ?: namedColor("Button.default.focusedBorderColor") ?: namedColor("Button.focusedBorderColor") val editorBackground = editorScheme.defaultBackground diff --git a/gui/src/styles/ThemePage.tsx b/gui/src/styles/ThemePage.tsx index 6a9dd2864..e1075ba02 100644 --- a/gui/src/styles/ThemePage.tsx +++ b/gui/src/styles/ThemePage.tsx @@ -62,36 +62,39 @@ function ThemePage() { return isJetBrains(); }, []); - const refreshJetbrainsColors = () => { - ideMessenger.request("jetbrains/getColors", undefined).then((result) => { - console.log(result); - if (result.status === "success") { - setDocumentStylesFromTheme(result.content); - } - }); + const [missingVars, setMissingVars] = useState([]); + const refreshColors = () => { + if (jetbrains) { + // Jetbrains: get colors and check which ones are missing from theme + void ideMessenger + .request("jetbrains/getColors", undefined) + .then((result) => { + console.log(result); + if (result.status === "success") { + const missingColors = setDocumentStylesFromTheme(result.content); + setMissingVars(missingColors); + } + }); + } else { + // VS Code: find actual missing CSS variables + const notFound: string[] = []; + Object.entries(THEME_COLORS).forEach(([colorName, themeVals], idx) => { + let found = false; + themeVals.vars.forEach((cssVar) => { + const value = getComputedStyle( + document.documentElement, + ).getPropertyValue(cssVar); + if (!value) { + notFound.push(`cssVar (choice #${idx + 1} for color ${colorName}`); + } + }); + }); + setMissingVars(notFound); + } }; - const [missingVars, setMissingVars] = useState([]); - const checkMissingClasses = () => { - const missingVars: string[] = []; - Object.entries(THEME_COLORS).forEach(([colorName, themeVals]) => { - let found = false; - themeVals.vars.forEach((cssVar) => { - const value = getComputedStyle( - document.documentElement, - ).getPropertyValue(cssVar); - if (value) { - found = true; - } - }); - if (!found) { - missingVars.push(colorName); - } - }); - setMissingVars(missingVars); - }; useEffect(() => { - checkMissingClasses(); + refreshColors(); }, []); return ( @@ -185,37 +188,22 @@ function ThemePage() {
-
-

- Missing Theme Variables -

- {missingVars.length > 0 ? ( -
- {missingVars.map((varName) => ( -
- {varName} -
- ))} -
- ) : ( -
No missing variables
- )} - -
+

Manage Theme

+

Missing Theme Colors

+ {missingVars.length > 0 ? ( +
+ {missingVars.map((varName) => ( +
+ {varName} +
+ ))} +
+ ) : ( +
No missing variables
+ )} + {jetbrains ? ( - <> -

- Manage Jetbrains Theme -

-
- - -
- + ) : null}

All Theme Colors

diff --git a/gui/src/styles/theme.ts b/gui/src/styles/theme.ts index dc5475dcb..ad0ee0bd7 100644 --- a/gui/src/styles/theme.ts +++ b/gui/src/styles/theme.ts @@ -117,15 +117,23 @@ export const THEME_COLORS = { default: "#ffffff", // white }, success: { - vars: ["--vscode-notebookStatusSuccessIcon-foreground"], // "var(--vscode-testing-iconPassed, #1bbe84)" // --vscode-charts-green + vars: [ + "--vscode-notebookStatusSuccessIcon-foreground", + "--vscode-testing-iconPassed", + "--vscode-gitDecoration-addedResourceForeground", + "--vscode-charts-green", + ], default: "#4caf50", // green }, warning: { - vars: ["--vscode-editorWarning-foreground"], // --vscode-list-warningForeground + vars: [ + "--vscode-editorWarning-foreground", + "--vscode-list-warningForeground", + ], default: "#ffb74d", // amber/yellow }, error: { - vars: ["--vscode-editorError-foreground"], // --vscode-list-errorForeground + vars: ["--vscode-editorError-foreground", "--vscode-list-errorForeground"], default: "#f44336", // red }, link: { @@ -187,7 +195,7 @@ export const THEME_DEFAULTS = Object.entries(THEME_COLORS).reduce( // Generates recursive CSS variable fallback for a given color name // e.g. var(--vscode-button-background, var(--vscode-button-foreground, #ffffff)) export const getRecursiveVar = (vars: string[], defaultColor: string) => { - return vars.reverse().reduce((curr, varName) => { + return [...vars].reverse().reduce((curr, varName) => { return `var(${varName}, ${curr})`; }, defaultColor); }; @@ -203,44 +211,43 @@ export const varWithFallback = (colorName: keyof typeof THEME_COLORS) => { export const setDocumentStylesFromTheme = ( theme: Record, ) => { - // Check for missing theme items - const themeKeys = Object.keys(THEME_COLORS); - const missingKeys = themeKeys.filter( - (key) => !Object.keys(theme).includes(key), - ); - if (missingKeys.length > 0) { - console.warn( - `Missing theme keys: ${missingKeys.join(", ")}. Please check theme`, - ); - } - // Write each theme color to the document + // Check for extraneous theme items Object.entries(theme).forEach(([colorName, value]) => { - if (value) { - const themeVals = THEME_COLORS[colorName as keyof typeof THEME_COLORS]; - if (!themeVals) { - console.warn( - `Receieved theme color ${colorName} which is not used by the theme`, - ); - return; - } - - // Remove alpha channel from all hex colors (seems to cause bad colors) - let colorVal = value; - if (colorVal.startsWith("#") && value.length > 7) { - colorVal = colorVal.slice(0, 7); - } - - localStorage.setItem(colorName, colorVal); - for (const cssVar of themeVals.vars) { - document.body.style.setProperty(cssVar, colorVal); - document.documentElement.style.setProperty(cssVar, colorVal); - } - } else { + const themeVals = THEME_COLORS[colorName as keyof typeof THEME_COLORS]; + if (!themeVals) { console.warn( - `Theme color ${colorName} is undefined or null. Please check theme. Falling back to defaults.`, + `Receieved theme color ${colorName} which is not used by the theme`, ); + return; } }); + + // Write theme values to document + const missingColors: string[] = []; + Object.entries(THEME_COLORS).forEach(([colorName, settings]) => { + let colorVal = settings.default; + const newColor = theme[colorName]; + if (newColor) { + colorVal = newColor; + // Remove alpha channel from all hex colors (seems to cause bad colors) + if (newColor.startsWith("#") && newColor.length > 7) { + colorVal = colorVal.slice(0, 7); + } + } else { + missingColors.push(colorName); + // console.warn( + // `Missing theme color: ${colorName}. Falling back to default ${colorVal}`, + // ); + } + + localStorage.setItem(colorName, colorVal); + for (const cssVar of settings.vars) { + document.body.style.setProperty(cssVar, colorVal); + document.documentElement.style.setProperty(cssVar, colorVal); + } + }); + + return missingColors; }; export const setDocumentStylesFromLocalStorage = (checkCache: boolean) => {