Skip to content

Commit 2f7d83b

Browse files
Copilotkv9898
andcommitted
Address additional code review feedback
- Add validation for theme kind parameter in notification handler - Document HighContrast theme handling (treated as dark) - Prevent fallback detection from overriding explicit theme notifications - Add flag to track whether theme was explicitly set Co-authored-by: kv9898 <[email protected]>
1 parent cba7695 commit 2f7d83b

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

apps/lsp/src/config.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export class ConfigurationManager extends Disposable {
137137
private _settings: Settings;
138138
private _logger: ILogger;
139139
private _activeColorThemeKind: "light" | "dark" = "dark";
140+
private _themeExplicitlySet = false;
140141

141142
constructor(
142143
private readonly connection_: Connection,
@@ -181,11 +182,13 @@ export class ConfigurationManager extends Disposable {
181182

182183
// Fallback: try to detect theme from name if we haven't received an explicit notification yet
183184
// This is a best-effort approach for compatibility, but won't work with autoDetectColorScheme
184-
// Default to dark theme if neither Light nor Dark is in the theme name
185-
if (settings.workbench.colorTheme.includes("Light")) {
186-
this._activeColorThemeKind = "light";
187-
} else if (settings.workbench.colorTheme.includes("Dark")) {
188-
this._activeColorThemeKind = "dark";
185+
// Only apply fallback if theme hasn't been explicitly set via notification
186+
if (!this._themeExplicitlySet) {
187+
if (settings.workbench.colorTheme.includes("Light")) {
188+
this._activeColorThemeKind = "light";
189+
} else if (settings.workbench.colorTheme.includes("Dark")) {
190+
this._activeColorThemeKind = "dark";
191+
}
189192
}
190193

191194
this._onDidChangeConfiguration.fire(this._settings);
@@ -217,6 +220,7 @@ export class ConfigurationManager extends Disposable {
217220
public setActiveColorThemeKind(kind: "light" | "dark") {
218221
if (this._activeColorThemeKind !== kind) {
219222
this._activeColorThemeKind = kind;
223+
this._themeExplicitlySet = true;
220224
this._onDidChangeConfiguration.fire(this._settings);
221225
}
222226
}

apps/lsp/src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,14 @@ connection.onInitialized(async () => {
225225
}
226226

227227
// listen for color theme changes from the client
228-
connection.onNotification("quarto/didChangeActiveColorTheme", (params: { kind: "light" | "dark" }) => {
228+
connection.onNotification("quarto/didChangeActiveColorTheme", (params: { kind: string }) => {
229229
logger.logNotification('didChangeActiveColorTheme');
230-
configManager.setActiveColorThemeKind(params.kind);
230+
// Validate the theme kind before using it
231+
if (params.kind === "light" || params.kind === "dark") {
232+
configManager.setActiveColorThemeKind(params.kind);
233+
} else {
234+
logger.logError(`Invalid theme kind received: ${params.kind}`);
235+
}
231236
});
232237

233238
// initialize connection to quarto

apps/vscode/src/lsp/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ export async function activateLsp(
156156
// Helper to send current theme to LSP server
157157
const sendThemeNotification = () => {
158158
if (client) {
159+
// Map VS Code theme kinds to light/dark. HighContrast themes are treated as dark
160+
// since they typically have light text on dark backgrounds
159161
const kind = window.activeColorTheme.kind === ColorThemeKind.Light ? "light" : "dark";
160162
client.sendNotification("quarto/didChangeActiveColorTheme", { kind });
161163
}

0 commit comments

Comments
 (0)