Skip to content

Commit 45fca7d

Browse files
mrleemurrayCopilot
andauthored
Fix Debug Console colors with transparent editor overrides (#350385)
Fix invisible Debug Console messages Co-authored-by: mrleemurray <mrleemurray@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5fd5910 commit 45fca7d

6 files changed

Lines changed: 157 additions & 18 deletions

File tree

‎src/vs/platform/theme/common/colorUtils.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const enum ColorTransformType {
5454
IfDefinedThenElse,
5555
Mix,
5656
Opacity,
57+
ThemeColor,
5758
}
5859

5960
export type ColorTransform =
@@ -65,7 +66,8 @@ export type ColorTransform =
6566
| { op: ColorTransformType.OneOf; values: readonly ColorValue[] }
6667
| { op: ColorTransformType.LessProminent; value: ColorValue; background: ColorValue; factor: number; transparency: number }
6768
| { op: ColorTransformType.IfDefinedThenElse; if: ColorIdentifier; then: ColorValue; else: ColorValue }
68-
| { op: ColorTransformType.Mix; color: ColorValue; with: ColorValue; ratio?: number };
69+
| { op: ColorTransformType.Mix; color: ColorValue; with: ColorValue; ratio?: number }
70+
| { op: ColorTransformType.ThemeColor; color: ColorIdentifier };
6971

7072
export interface ColorDefaults {
7173
light: ColorValue | null;
@@ -305,6 +307,9 @@ export function executeTransform(transform: ColorTransform, theme: IColorTheme):
305307
case ColorTransformType.IfDefinedThenElse:
306308
return resolveColorValue(theme.defines(transform.if) ? transform.then : transform.else, theme);
307309

310+
case ColorTransformType.ThemeColor:
311+
return theme.getColor(transform.color, true, true);
312+
308313
case ColorTransformType.LessProminent: {
309314
const from = resolveColorValue(transform.value, theme);
310315
if (!from) {
@@ -350,6 +355,11 @@ export function oneOf(...colorValues: ColorValue[]): ColorTransform {
350355
return { op: ColorTransformType.OneOf, values: colorValues };
351356
}
352357

358+
/** Resolves a theme color without user or transient overrides of that color. */
359+
export function themeColor(color: ColorIdentifier): ColorTransform {
360+
return { op: ColorTransformType.ThemeColor, color };
361+
}
362+
353363
export function ifDefinedThenElse(ifArg: ColorIdentifier, thenArg: ColorValue, elseArg: ColorValue): ColorTransform {
354364
return { op: ColorTransformType.IfDefinedThenElse, if: ifArg, then: thenArg, else: elseArg };
355365
}

‎src/vs/platform/theme/common/themeService.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ export interface IColorTheme {
5151
* specify the color, the default color is returned unless <code>useDefault</code> is set to false.
5252
* @param color the id of the color
5353
* @param useDefault specifies if the default color should be used. If not set, the default is used.
54+
* @param ignoreOverrides ignores user and transient overrides for this color.
5455
*/
55-
getColor(color: ColorIdentifier, useDefault?: boolean): Color | undefined;
56+
getColor(color: ColorIdentifier, useDefault?: boolean, ignoreOverrides?: boolean): Color | undefined;
5657

5758
/**
5859
* Returns whether the theme defines a value for the color. If not, that means the

‎src/vs/workbench/contrib/debug/browser/debugColors.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { registerColor, foreground, editorInfoForeground, editorWarningForeground, errorForeground, badgeBackground, badgeForeground, listDeemphasizedForeground, contrastBorder, inputBorder, toolbarHoverBackground } from '../../../../platform/theme/common/colorRegistry.js';
6+
import { registerColor, themeColor, foreground, editorInfoForeground, editorWarningForeground, errorForeground, badgeBackground, badgeForeground, listDeemphasizedForeground, contrastBorder, inputBorder, toolbarHoverBackground } from '../../../../platform/theme/common/colorRegistry.js';
77
import { registerThemingParticipant } from '../../../../platform/theme/common/themeService.js';
88
import { ThemeIcon } from '../../../../base/common/themables.js';
99
import { Color } from '../../../../base/common/color.js';
@@ -43,8 +43,8 @@ export function registerColors() {
4343
const debugViewStateLabelBackground = registerColor('debugView.stateLabelBackground', '#88888844', 'Background color for a label in the CALL STACK view showing the current session\'s or thread\'s state.');
4444
const debugViewValueChangedHighlight = registerColor('debugView.valueChangedHighlight', '#569CD6', 'Color used to highlight value changes in the debug views (ie. in the Variables view).');
4545

46-
const debugConsoleInfoForeground = registerColor('debugConsole.infoForeground', { dark: editorInfoForeground, light: editorInfoForeground, hcDark: foreground, hcLight: foreground }, 'Foreground color for info messages in debug REPL console.');
47-
const debugConsoleWarningForeground = registerColor('debugConsole.warningForeground', { dark: editorWarningForeground, light: editorWarningForeground, hcDark: '#008000', hcLight: editorWarningForeground }, 'Foreground color for warning messages in debug REPL console.');
46+
const debugConsoleInfoForeground = registerColor('debugConsole.infoForeground', { dark: themeColor(editorInfoForeground), light: themeColor(editorInfoForeground), hcDark: foreground, hcLight: foreground }, 'Foreground color for info messages in debug REPL console.');
47+
const debugConsoleWarningForeground = registerColor('debugConsole.warningForeground', { dark: themeColor(editorWarningForeground), light: themeColor(editorWarningForeground), hcDark: '#008000', hcLight: themeColor(editorWarningForeground) }, 'Foreground color for warning messages in debug REPL console.');
4848
const debugConsoleErrorForeground = registerColor('debugConsole.errorForeground', errorForeground, 'Foreground color for error messages in debug REPL console.');
4949
const debugConsoleSourceForeground = registerColor('debugConsole.sourceForeground', foreground, 'Foreground color for source filenames in debug REPL console.');
5050
const debugConsoleInputIconForeground = registerColor('debugConsoleInputIcon.foreground', foreground, 'Foreground color for debug console input marker icon.');
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import assert from 'assert';
7+
import { mock } from '../../../../../base/test/common/mock.js';
8+
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
9+
import { IEnvironmentService } from '../../../../../platform/environment/common/environment.js';
10+
import { Registry } from '../../../../../platform/registry/common/platform.js';
11+
import { editorInfoForeground, editorWarningForeground } from '../../../../../platform/theme/common/colorRegistry.js';
12+
import { ColorScheme } from '../../../../../platform/theme/common/theme.js';
13+
import { Extensions, IThemingRegistry } from '../../../../../platform/theme/common/themeService.js';
14+
import { ColorThemeData } from '../../../../services/themes/common/colorThemeData.js';
15+
import { registerColors } from '../../browser/debugColors.js';
16+
17+
const themingRegistry = Registry.as<IThemingRegistry>(Extensions.ThemingContribution);
18+
const participantIndex = themingRegistry.getThemingParticipants().length;
19+
registerColors();
20+
const debugThemingParticipant = themingRegistry.getThemingParticipants()[participantIndex];
21+
22+
suite('Debug Colors', () => {
23+
ensureNoDisposablesAreLeakedInTestSuite();
24+
25+
test('debug console info and warning colors do not inherit transparent editor diagnostic customizations', () => {
26+
const themes = [
27+
{ type: ColorScheme.DARK, info: '#59a4f9', warning: '#cca700' },
28+
{ type: ColorScheme.LIGHT, info: '#0063d3', warning: '#bf8803' },
29+
{ type: ColorScheme.HIGH_CONTRAST_DARK, info: '#ffffff', warning: '#008000' },
30+
{ type: ColorScheme.HIGH_CONTRAST_LIGHT, info: '#292929', warning: '#895503' },
31+
];
32+
33+
assert.deepStrictEqual(themes.map(({ type }) => {
34+
const theme = ColorThemeData.createUnloadedThemeForThemeType(type);
35+
theme.setCustomColors({ [editorInfoForeground]: '#00000000', [editorWarningForeground]: '#00000000' });
36+
return [
37+
theme.getColor('debugConsole.infoForeground')?.toString(),
38+
theme.getColor('debugConsole.warningForeground')?.toString()
39+
];
40+
}), themes.map(({ info, warning }) => [info, warning]));
41+
});
42+
43+
test('preserves theme-defined diagnostic colors despite editor customizations', () => {
44+
const themes = [
45+
{ type: ColorScheme.DARK, info: '#17ff12', warning: '#ff1212' },
46+
{ type: ColorScheme.LIGHT, info: '#17ff12', warning: '#ff1212' },
47+
{ type: ColorScheme.HIGH_CONTRAST_DARK, info: '#ffffff', warning: '#008000' },
48+
{ type: ColorScheme.HIGH_CONTRAST_LIGHT, info: '#292929', warning: '#ff1212' },
49+
];
50+
51+
assert.deepStrictEqual(themes.map(({ type }) => {
52+
const theme = ColorThemeData.createUnloadedThemeForThemeType(type, {
53+
[editorInfoForeground]: '#17ff12',
54+
[editorWarningForeground]: '#ff1212',
55+
});
56+
theme.setCustomColors({ [editorInfoForeground]: '#00000000', [editorWarningForeground]: '#00000000' });
57+
return [
58+
theme.getColor('debugConsole.infoForeground')?.toString(),
59+
theme.getColor('debugConsole.warningForeground')?.toString()
60+
];
61+
}), themes.map(({ info, warning }) => [info, warning]));
62+
});
63+
64+
test('explicit console colors override theme colors and appear in the generated styles', () => {
65+
const theme = ColorThemeData.createUnloadedThemeForThemeType(ColorScheme.DARK, {
66+
[editorInfoForeground]: '#17ff12',
67+
[editorWarningForeground]: '#ff1212',
68+
'debugConsole.infoForeground': '#112233',
69+
'debugConsole.warningForeground': '#445566',
70+
});
71+
const themeColors = [
72+
theme.getColor('debugConsole.infoForeground')?.toString(),
73+
theme.getColor('debugConsole.warningForeground')?.toString()
74+
];
75+
theme.setCustomColors({
76+
[editorInfoForeground]: '#00000000',
77+
[editorWarningForeground]: '#00000000',
78+
'debugConsole.infoForeground': '#123456',
79+
'debugConsole.warningForeground': '#abcdef',
80+
});
81+
const rules: string[] = [];
82+
const environment = new class extends mock<IEnvironmentService>() { };
83+
debugThemingParticipant(theme, { addRule: rule => rules.push(rule) }, environment);
84+
const css = rules.join('\n');
85+
86+
assert.deepStrictEqual([
87+
...themeColors,
88+
theme.getColor('debugConsole.infoForeground')?.toString(),
89+
theme.getColor('debugConsole.warningForeground')?.toString(),
90+
...['info', 'warn'].map(severity => css.match(new RegExp(`\\.value\\.${severity} \\{\\s*color: (?<color>[^;]+);`))?.groups?.color)
91+
], ['#112233', '#445566', '#123456', '#abcdef', '#123456', '#abcdef']);
92+
});
93+
});

‎src/vs/workbench/services/themes/common/colorThemeData.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,23 @@ export class ColorThemeData implements IWorkbenchColorTheme {
149149
return this.textMateThemingRules;
150150
}
151151

152-
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color | undefined {
153-
const transientColor = this.transientColorMap?.[colorId];
154-
if (transientColor) {
155-
return transientColor;
156-
}
157-
const customColor = this.customColorMap[colorId];
158-
if (customColor instanceof Color) {
159-
return customColor;
160-
}
161-
if (customColor === undefined) { /* !== DEFAULT_COLOR_CONFIG_VALUE */
162-
const color = this.colorMap[colorId];
163-
if (color !== undefined) {
164-
return color;
152+
public getColor(colorId: ColorIdentifier, useDefault?: boolean, ignoreOverrides?: boolean): Color | undefined {
153+
if (!ignoreOverrides) {
154+
const transientColor = this.transientColorMap?.[colorId];
155+
if (transientColor) {
156+
return transientColor;
165157
}
158+
const customColor = this.customColorMap[colorId];
159+
if (customColor instanceof Color) {
160+
return customColor;
161+
}
162+
if (customColor !== undefined) { /* === DEFAULT_COLOR_CONFIG_VALUE */
163+
return useDefault !== false ? this.getDefault(colorId) : undefined;
164+
}
165+
}
166+
const color = this.colorMap[colorId];
167+
if (color !== undefined) {
168+
return color;
166169
}
167170
if (useDefault !== false) {
168171
return this.getDefault(colorId);

‎src/vs/workbench/services/themes/test/common/colorThemeData.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,38 @@ suite('ColorThemeData - transient colors', () => {
5858
});
5959
});
6060

61+
test('resolves theme colors independently of user and transient overrides', () => {
62+
const theme = ColorThemeData.createUnloadedTheme('vs-dark', { [editorBackground]: '#202020' });
63+
theme.setCustomColors({ [editorBackground]: '#123456', [foreground]: '#abcdef' });
64+
theme.setTransientColors({ [editorBackground]: Color.fromHex('#654321') });
65+
66+
assert.deepStrictEqual({
67+
active: theme.getColor(editorBackground)?.toString(),
68+
theme: theme.getColor(editorBackground, false, true)?.toString(),
69+
fallback: theme.getColor(foreground, true, true)?.toString(),
70+
missing: theme.getColor(foreground, false, true),
71+
}, {
72+
active: '#654321',
73+
theme: '#202020',
74+
fallback: '#cccccc',
75+
missing: undefined,
76+
});
77+
});
78+
79+
test('preserves default-color customization semantics', () => {
80+
const theme = ColorThemeData.createUnloadedTheme('vs-dark', { [editorBackground]: '#202020' });
81+
theme.setCustomColors({ [editorBackground]: 'default' });
82+
assert.deepStrictEqual({
83+
active: theme.getColor(editorBackground)?.toString(),
84+
explicit: theme.getColor(editorBackground, false),
85+
theme: theme.getColor(editorBackground, false, true)?.toString(),
86+
}, {
87+
active: '#1e1e1e',
88+
explicit: undefined,
89+
theme: '#202020',
90+
});
91+
});
92+
6193
test('clearing runtime colors restores theme and user-customized colors', () => {
6294
const theme = ColorThemeData.createUnloadedTheme('vs-dark', { [editorBackground]: '#202020' });
6395
theme.setCustomColors({ [inputBackground]: '#123456' });

0 commit comments

Comments
 (0)