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

Debt - use CSS variables over registerThemingParticipant #165169

Closed
12 of 26 tasks
jrieken opened this issue Nov 1, 2022 · 26 comments · Fixed by #165186
Closed
12 of 26 tasks

Debt - use CSS variables over registerThemingParticipant #165169

jrieken opened this issue Nov 1, 2022 · 26 comments · Fixed by #165186
Assignees
Labels
debt Code quality issues perf-bloat
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Nov 1, 2022

When running VS Code (or the Monaco editor) all theme colors are exposed as CSS variables. That means components don’t need to use JavaScript to read and set colors but can simply rely on CSS. When a theme changes, the variable values automatically update. Also, with CSS variables you have less code and everything in one place.

The (long) list below is all users of registerThemingParticipant. Those that only set/update colors are candidates for adopting CSS variables The names of the CSS variables can be "derived" with the following logic

  1. prefix --vscode-
  2. take the theme color id and replace dots with slashes

For instance the color id editorSuggestWidget.background is exposed as CSS variables --vscode-editorSuggestWidget-background. Find a sample adoption in this commit: 3a787a8.


  • src/vs/editor/contrib/find/browser/findWidget.ts @rebornix
  • src/vs/workbench/browser/parts/activitybar/activitybarActions.ts
  • src/vs/workbench/browser/parts/editor/tabsTitleControl.ts @bpasero
  • src/vs/workbench/contrib/codeEditor/browser/find/simpleFindWidget.ts @Tyriar
  • src/vs/workbench/contrib/codeEditor/browser/suggestEnabledInput/suggestEnabledInput.ts
  • src/vs/workbench/contrib/codeEditor/browser/untitledTextEditorHint.ts
  • src/vs/workbench/contrib/customEditor/browser/customEditors.ts
  • src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts @roblourens
  • src/vs/workbench/contrib/debug/browser/callStackEditorContribution.ts @roblourens
  • src/vs/workbench/contrib/debug/browser/debugColors.ts @roblourens
  • src/vs/workbench/contrib/extensions/browser/extensionsActions.ts @sandy081
  • src/vs/workbench/contrib/extensions/browser/extensionsList.ts @sandy081
  • src/vs/workbench/contrib/extensions/browser/extensionsViewer.ts @sandy081
  • src/vs/workbench/contrib/extensions/browser/extensionsWidgets.ts @sandy081
  • src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts @rebornix
  • src/vs/workbench/contrib/output/browser/outputView.ts @sandy081
  • src/vs/workbench/contrib/search/browser/searchView.ts @andreamah
  • src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts @andreamah
  • src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @Tyriar
  • src/vs/workbench/contrib/terminal/browser/terminalView.ts @Tyriar
  • src/vs/workbench/contrib/terminal/browser/widgets/terminalHoverWidget.ts @Tyriar
  • src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts @Tyriar
  • src/vs/workbench/contrib/terminal/browser/xterm/markNavigationAddon.ts @Tyriar
  • src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts @Tyriar
  • src/vs/workbench/contrib/welcomeOverlay/browser/welcomeOverlay.ts @bhavyaus
  • src/vs/workbench/contrib/welcomeWalkthrough/browser/walkThroughPart.ts @bhavyaus
@jrieken jrieken added debt Code quality issues perf-bloat labels Nov 1, 2022
@jrieken jrieken added this to the November 2022 milestone Nov 1, 2022
@hediet hediet removed their assignment Nov 1, 2022
mjbvz added a commit to mjbvz/vscode that referenced this issue Nov 1, 2022
mjbvz added a commit that referenced this issue Nov 1, 2022
@VSCodeTriageBot VSCodeTriageBot added the unreleased Patch has not yet been released in VS Code Insiders label Nov 1, 2022
@lramos15 lramos15 reopened this Nov 1, 2022
@VSCodeTriageBot VSCodeTriageBot removed the unreleased Patch has not yet been released in VS Code Insiders label Nov 1, 2022
@lramos15 lramos15 removed their assignment Nov 2, 2022
@rebornix rebornix removed their assignment Nov 3, 2022
@Tyriar
Copy link
Member

Tyriar commented Feb 27, 2023

I looked over mine again and they are all there still intentionally:

registerThemingParticipant((theme, collector) => {
let editorHoverHighlightColor = theme.getColor(editorHoverHighlight);
if (editorHoverHighlightColor) {
if (editorHoverHighlightColor.isOpaque()) {
editorHoverHighlightColor = editorHoverHighlightColor.transparent(0.5);
}
collector.addRule(`.integrated-terminal .hoverHighlight { background-color: ${editorHoverHighlightColor}; }`);
}
});

I don't think we can get the same effect of .transparent(0.5) in CSS using the variable.

https://github.com/microsoft/vscode/blob/bceaaf84a27c3a95a0cdfc79287e3215b56b951c/src/vs/workbench/services/hover/browser/hoverService.ts#L179-L186

Same as above.

let successColor: string | Color | undefined;
let errorColor: string | Color | undefined;
let defaultColor: string | Color | undefined;
registerThemingParticipant((theme: IColorTheme) => {
successColor = theme.getColor(TERMINAL_COMMAND_DECORATION_SUCCESS_BACKGROUND_COLOR);
errorColor = theme.getColor(TERMINAL_COMMAND_DECORATION_ERROR_BACKGROUND_COLOR);
defaultColor = theme.getColor(TERMINAL_COMMAND_DECORATION_DEFAULT_BACKGROUND_COLOR);
});

This is needed as the color is handed off to xterm.js.

@Tyriar Tyriar removed their assignment Feb 27, 2023
@jrieken
Copy link
Member Author

jrieken commented Feb 27, 2023

@Tyriar please check those occurrences anyways so that we can remove them from the todo list

@andreamah
Copy link
Contributor

For searchEditor.ts, I couldn't find references to registerThemingParticipant.

For searchView.ts, we use the RGB values from the foreground var and we use a custom alpha. Since this only applies to the text, I don't think that there's a CSS-only equivalent. We could create a new var for this or just leave this as is; I'm not sure what's best in this case.

registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) => {
if (theme.type === 'dark') {
const foregroundColor = theme.getColor(foreground);
if (foregroundColor) {
const fgWithOpacity = new Color(new RGBA(foregroundColor.rgba.r, foregroundColor.rgba.g, foregroundColor.rgba.b, 0.65));
collector.addRule(`.search-view .message { color: ${fgWithOpacity}; }`);
}
}
});

@Tyriar
Copy link
Member

Tyriar commented Feb 27, 2023

@andreamah you're setting color there so you can probably use a plain opacity: 0.65 style, unless the element also has a background color as that would also apply there.

@andreamah
Copy link
Contributor

@andreamah you're setting color there so you can probably use a plain opacity: 0.65 style, unless the element also has a background color as that would also apply there.

The element also has links, which have a normal alpha, so then the link opacity is affected.

@Tyriar
Copy link
Member

Tyriar commented Feb 27, 2023

@andreamah you could have another rule with higher specificity that re-applies the link color?

@aeschli
Copy link
Contributor

aeschli commented Feb 28, 2023

@Tyriar For

registerThemingParticipant((theme, collector) => {
let editorHoverHighlightColor = theme.getColor(editorHoverHighlight);
if (editorHoverHighlightColor) {
if (editorHoverHighlightColor.isOpaque()) {
editorHoverHighlightColor = editorHoverHighlightColor.transparent(0.5);
}
collector.addRule(`.integrated-terminal .hoverHighlight { background-color: ${editorHoverHighlightColor}; }`);
}
});

you could define a new (terminal hover specific) color. The default value of the color can express that it is a function of editorHoverHighlightColor

let successColor: string | Color | undefined;
let errorColor: string | Color | undefined;
let defaultColor: string | Color | undefined;
registerThemingParticipant((theme: IColorTheme) => {
successColor = theme.getColor(TERMINAL_COMMAND_DECORATION_SUCCESS_BACKGROUND_COLOR);
errorColor = theme.getColor(TERMINAL_COMMAND_DECORATION_ERROR_BACKGROUND_COLOR);
defaultColor = theme.getColor(TERMINAL_COMMAND_DECORATION_DEFAULT_BACKGROUND_COLOR);
});

To access a color value use IThemeService.getColorTheme().getColor(...)

@bpasero bpasero removed their assignment Feb 28, 2023
@bpasero
Copy link
Member

bpasero commented Feb 28, 2023

As discussed in standup, tabs have quite an involved CSS ruling that involves not only colors but also other properties. I would like to keep it this way via registerThemingParticipant and not invent various class names to get a similar effect to make maintenance easier there.

@jrieken
Copy link
Member Author

jrieken commented May 9, 2023

Closing this as I believe we are done here

@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues perf-bloat
Projects
None yet
Development

Successfully merging a pull request may close this issue.