allow variables in the color-theme definition file for workbench color#199091
allow variables in the color-theme definition file for workbench color#199091d-mahard wants to merge 16 commits intomicrosoft:mainfrom
Conversation
6f4ba1c to
cd5a7c6
Compare
|
I think the direction you are taking is good. |
|
Hi, thank you for the feedback! Sure, I'll try to minimize the changes. |
d-mahard
left a comment
There was a problem hiding this comment.
@aeschli I tried to reduce the changes, but not so much could be removed. Actually about half of the added lines are the unit test (two dummy theme files, and the unit test file itself). So for the logic, it is around 100 lines added and 30 removed.
To help with the review, I added some comments in this PR to explain the logic/design decision.
Please see the comments below.
Let me know if other information is needed.
f4f90b5 to
72daeaf
Compare
|
Thanks @d-mahard for all the work!
|
|
thank you @aeschli for the review! Regarding the following two points:
In my understanding, to satisfy both requirements we still need the dynamic schema (even though the var enum is removed). The reasons are the following: Schemas for setting are controlled here. In line 84 below, we need to use vscode/src/vs/workbench/services/themes/common/themeConfiguration.ts Lines 81 to 90 in 4fce419 For the theme, the schema is (in the current vscode/src/vs/workbench/services/themes/common/colorThemeSchema.ts Lines 222 to 253 in 4fce419 The vscode/src/vs/platform/theme/common/colorRegistry.ts Lines 136 to 153 in 4fce419 We cannot simply just change the schema of the theme, because the So my proposal would still be using the dynamic schema, together with the scheduler, but removing the variable enum. So something like the following: for (const key in workbenchColorSchemaForTheme.properties) {
const property = workbenchColorSchemaForTheme.properties[key];
delete property.format;
property.anyOf = [
{
pattern: '^\\$\\w+', errorMessage: nls.localize('error.invalidFormat.colorEntryWithPalette', "Color must either in hex format (e.g. `#ffffff`) or one of the palette (e.g. `$accentName`)")
}, // here, instead of using `$ref: themePaletteEnumSchemaId` like before, I just add the `$\w+` pattern
{ format: 'color-hex' },
];
}and of course (for completeness): The reason why I think even the scheduler is still needed is like I mentioned in my other comment:
Is my understanding correct or did I miss something here? Do you have any other approach? |
|
@d-mahard So as you say, we can no longer have a single schema to describe colors for I would suggest to collect two different schemas in the ColorRegistry: The trick with these schemas is that they are modified while new colors come in. So you can not just take a copy of it. |
this is achieved without changing schema is colorRegistry, by generating a custom schema.
pallet var enum is removed. Schema for theme is created directly in colorRegistry no longer by copying the default schema.
to separate it from setting
72daeaf to
8508089
Compare
|
@aeschli thank you for the hint! I made the changes based on your suggestions:
In any case I tested the schema validation, see below:
A little caveat: |
|
@d-mahard Thanks for all your work! It's nicely done, I also tested it. |
|
@aeschli |


Description
For feature request described in #105247
Mainly there are two new features proposed here
Add snippets and suggestion for the colors, which include all the defined variables in the paletteThis does NOT include the following
Usage of the palette var for token colors (I am interested to explore this, but would like to hear feedback first)as this needs to change thecolorRegistry, which may affect many other things. (I would also love to explore this option, depending on the feedback)EDIT 2023-12-15 (see comment for screenshots)
Some technical details
$is based on this comment by @aeschliworkbenchColorsSchemaIdbecause modifying it would affect many other things. So instead I create a new JSON Schema based on that (here), so it will be isolated, only in theme file. However, if there is no palette, there will essentially be no modification to the schema, it is just copied as it is.For the snippets/suggestion/validation, the palette needs to be loaded first, meaning that if there is any change in the palette, VSCode needs to be restarted after the change. However, I think it is safe to assume that a palette change, especially the change of the keys, only happens rarely.How to test
I prepared a unit test for the parsing in themeColorParsing.test.ts