You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[themes] Explore theming support for semantic colors #77133
define a set of Token Classifications that can be used for semantic highlighting
evaluate actual color/style values based on the current text mate theme
allow themes to define such colors and styles
Reacted by Colen Garoutte-Carson, Aslan French, __, justspring, Bob Brown, Jarek Radosz, Misa Jovanovic, Tristan Partin, Benas Svipas, Michael Chris Lopez and 23 more
Reacted by kanlukasz, Jakob Lindskog, Michal Čaplygin, FakeTruth and Julian Konchunas
This is a proposal on how to represent the classification that a semantic highlighter computes (TokenTypes and TokenModifiers) and how themes and users can associate the style (TokenStyle). I'm still editing this proposal, but feedback and questions are welcome!
Semantic highlight range provider
A semantic highlight range provider takes a document (and potentially other arguments such as the current viewPorts) and returns a list of classified source ranges. The proposal is that each range can be classified with a TokenType and any number of TokenModifiers.
Note: This proposal focuses just on the classification types. The full SemanticHighlightRangeProvider API with a proper return type and optimizations such as compact token representation or ranges grouped by line will be part of a different proposal.
TokenTypes and TokenModifiers
A TokenType describes the symbol (class, field, variable...) at the location. The TokenModifiers provide additional information on the symbols (static, declaration, write access...).
TokenType and TokenModifiers are identified by a string id.
The purpose of splitting the classification into type and modifier is to simplify the theme definition (described later) and to make it easier for extensions to contribute additional classifications.
Predefined TokenTypes and TokenModifiers
VSCode will define a set of predefined (standardized) TokenTypes and TokenTypeModifiers, but extensions can add more if necessary:
Predefined TokeTypes Modifiers: declaration : For all symbol declarations documentation: For all occurrences of symbols in documentation member: for member types, member variables (fields) and member functions (methods) static for static (member types), member variables and member functions modification for references where a variable is modified async for declarations or references for functions that are async deprecated: for annotating deprecated symbols abstract: for annotating abstract functions.
TokenTypes and TokenModifiers Defaults
Each TokenType and TokenModifier come with a default style which is used when the actual theme does not define a style for it.
The default style can be specified as either
a set of textMateScopesToProbe that are ran against the text mate theme rules the current theme defines to find a matching style.
a predefined (static) style
a reference to a different token-type to inherit the style of the other token type
The first segment of a rule is the tokenType or '*', followed by modifiers. The order of the modifiers is not relevant.
A rule matches if the token-type (e.g. const) matches or if the rule starts with * and when all modifiers of the rule are matched.
The rule specificity is defined by the number of segments matching. That means const < *.declaration < *.declaration.exported < const.declaration.exported.
(still to be decided: order when multiple rules have the same number of segments matching)
The final style can be the result of multiple rules. For each style property (foreground, underline, bold, italics) the style of the most specific rule is applied. If a rule does not define a style, the rule is ignored for the evaluation of that style.
The foreground color can be a combination of colors if ColorFunctions ('darker()') are used.
{
"tokenStyles": {
// all consts are blue and underlined"const": { "foreground": "#0000ff", "underline": true },
// all declarations (types, functions, vars,....) are bold"*.declaration": { "bold": true },
// all declaration that are also exported (public) are not bold, but underlined"*.declaration.exported": { "bold": false, "underline": true },
// consts declarations that are exported are bold, underlined (inherited) and blue (inherited)"const.exported.declaration": { "bold": true },
// all async decls and refs are rendered with a slightly darker color"*.asyncReturn": { "foreground": "darker()" }
}
"colors": { .../* same as before */ },
"tokenColors": [
// still there for syntax highlighting and for evaluating // default styles for TokenTypes and Modifier
{
"scope": [ "storage.type.annotation" ],
"settings": { "fontStyle": "bold", "foreground": "#AA3731" }
},
{
"scope": [ "entity.name.type", "entity.name.namespace" ],
"settings": { "fontStyle": "bold", "foreground": "#7A3E9D" }
}
// ...
]
}
TokenTypes and TokenModifiers Contribution
{
"contributes": {
"tokenTypes": [ {
"id": "annotationType",
"default": {
"textMateScopes": ["storage.type.annotation"],
"value": "type"// inherits settings from 'type'
}
}],
"tokenTypeModifier": [ {
"id": "autoBoxed",
"default": {
"value": { "bold": "true" } // default to be used for '*.autoboxed'
}
}]
}
Reacted by Danny McGee, __, VladD2, SPGoding and mxrachel
Are there any thoughts on how this could work for semantically embedded languages? Aka, HTML with JS/CSS or Razor with HTML/JS/CSS.
For instance in Razor if you do:
<formasp-antiforgery="true">
...
</form>
The true can be C#.
It'd be great if there was a way to say "this range is C#" and then adding additional semantic meaning on top of it would be up to Razor or HTML language servers or their extensions
This might be related to embedded laguages; will we support multiple tokens per location? How about multiple token modifiers per location?
For example, static function or keyword in embedded XML (doc comment) are both used in C#.
N. Taylor Mullen (@NTaylorMullen) This needs to be discussed in the issue where we design the SemanticHighlightRangeProvider. Maybe you can file an issue where you describe the idea?
This is from a quick and dirty example I was doing for another issue but, have a look at the parameters. Is there something I'm missing? It seems to be possible.
Basically I had my extension provide a set of default colors for certain modifiers and then had my server add one of those modifiers to each parameter.
Matt Acosta (@mattacosta) but can it work with other language servers? Can your language server act as an intermediary to other language servers so it is lanuguage agnostic?
I'd like to be able to implement a solution that works for any language without changing the language servers for those languages.
There's no need to be part of the language server. Any extension can contribute a semantic token provider, for any language. Alexandru Dima (@alexdima) What we still have to work on is to decide what happens when there are multiple providers for a file (which one wins?).
I also want to emphasize that just because you can doesn't mean you should... that first run would be hella expensive (if it works at all), and I have no idea what kind of optimizations would be possible/required.
to my theme and it doesn't work. Adding this to user settings does work though.
I know I can style things by mapping semantic topics to textmate scopes and then styling the latter as usual, but that's a very roundabout way to do this.
returnPromise.reject(newError(nls.localize({key: 'error.invalidformat.tokenColors',comment: ['{0} will be replaced by a path. Values in quotes should not be translated.']},"Problem parsing color theme file: {0}. Property 'tokenColors' should be either an array specifying colors or a path to a TextMate theme file",themeLocation.toString())));
Activity
aeschli commentedon Jul 10, 2019
related: #32813
kanlukasz commentedon Aug 1, 2019
Do you mean that there will be option to set color variables and use them with themes making?
I mean something like in Sublime Text
Here is example what i talking about:
https://stackoverflow.com/questions/56473901/is-it-possible-to-use-color-variables-in-the-visual-studio-code-when-creating-th
Or maybe it's possible right now but i don't know how?
aeschli commentedon Sep 23, 2019
This is a proposal on how to represent the classification that a semantic highlighter computes (
TokenTypesandTokenModifiers) and how themes and users can associate the style (TokenStyle). I'm still editing this proposal, but feedback and questions are welcome!Semantic highlight range provider
A semantic highlight range provider takes a document (and potentially other arguments such as the current viewPorts) and returns a list of classified source ranges. The proposal is that each range can be classified with a TokenType and any number of TokenModifiers.
Note: This proposal focuses just on the classification types. The full SemanticHighlightRangeProvider API with a proper return type and optimizations such as compact token representation or ranges grouped by line will be part of a different proposal.
TokenTypes and TokenModifiers
A TokenType describes the symbol (class, field, variable...) at the location. The TokenModifiers provide additional information on the symbols (static, declaration, write access...).
TokenType and TokenModifiers are identified by a string id.
The purpose of splitting the classification into type and modifier is to simplify the theme definition (described later) and to make it easier for extensions to contribute additional classifications.
Predefined TokenTypes and TokenModifiers
VSCode will define a set of predefined (standardized) TokenTypes and TokenTypeModifiers, but extensions can add more if necessary:
Predefined TokeTypes:
comments,strings,numbers,keywords,regexp,operatorsnamespacestypes,structs(Type),classes(Type),interfaces(Type),enums(Type),parameterTypes(Type)functions,macros(Function)variables,constants(Variable),parameters(Variable),properties(Variable),labelsPredefined TokeTypes Modifiers:
declaration: For all symbol declarationsdocumentation: For all occurrences of symbols in documentationmember: for member types, member variables (fields) and member functions (methods)staticfor static (member types), member variables and member functionsmodificationfor references where a variable is modifiedasyncfor declarations or references for functions that are asyncdeprecated: for annotating deprecated symbolsabstract: for annotating abstract functions.TokenTypes and TokenModifiers Defaults
Each TokenType and TokenModifier come with a default style which is used when the actual theme does not define a style for it.
The default style can be specified as either
textMateScopesToProbethat are ran against the text mate theme rules the current theme defines to find a matching style.Theme Definition
The active color theme (or user setting) will define colors and styles (
TokenStyle) for TokenTypes and TokenModifiers or combination thereof.{ "tokenStyles": { "(typenType|*)[.tokenTypeModifier]*": TokenStyle, //... }const) matches or if the rule starts with*and when all modifiers of the rule are matched.const<*.declaration<*.declaration.exported<const.declaration.exported.(still to be decided: order when multiple rules have the same number of segments matching)
{ "tokenStyles": { // all consts are blue and underlined "const": { "foreground": "#0000ff", "underline": true }, // all declarations (types, functions, vars,....) are bold "*.declaration": { "bold": true }, // all declaration that are also exported (public) are not bold, but underlined "*.declaration.exported": { "bold": false, "underline": true }, // consts declarations that are exported are bold, underlined (inherited) and blue (inherited) "const.exported.declaration": { "bold": true }, // all async decls and refs are rendered with a slightly darker color "*.asyncReturn": { "foreground": "darker()" } } "colors": { ... /* same as before */ }, "tokenColors": [ // still there for syntax highlighting and for evaluating // default styles for TokenTypes and Modifier { "scope": [ "storage.type.annotation" ], "settings": { "fontStyle": "bold", "foreground": "#AA3731" } }, { "scope": [ "entity.name.type", "entity.name.namespace" ], "settings": { "fontStyle": "bold", "foreground": "#7A3E9D" } } // ... ] }TokenTypes and TokenModifiers Contribution
{ "contributes": { "tokenTypes": [ { "id": "annotationType", "default": { "textMateScopes": ["storage.type.annotation"], "value": "type" // inherits settings from 'type' } }], "tokenTypeModifier": [ { "id": "autoBoxed", "default": { "value": { "bold": "true" } // default to be used for '*.autoboxed' } }] }NTaylorMullen commentedon Sep 25, 2019
Are there any thoughts on how this could work for semantically embedded languages? Aka, HTML with JS/CSS or Razor with HTML/JS/CSS.
For instance in Razor if you do:
The
truecan be C#.It'd be great if there was a way to say "this range is C#" and then adding additional semantic meaning on top of it would be up to Razor or HTML language servers or their extensions
AmadeusW commentedon Sep 25, 2019
This might be related to embedded laguages; will we support multiple tokens per location? How about multiple token modifiers per location?
For example, static function or keyword in embedded XML (doc comment) are both used in C#.
aeschli commentedon Sep 26, 2019
N. Taylor Mullen (@NTaylorMullen) Amadeusz Wieczorek (@AmadeusW) That needs to be seen when we finalise the SemanticHighlightRangeProvider. Normally with providers we support more than one provider.
NTaylorMullen commentedon Sep 26, 2019
Definitely, but what about registering a "language" with a range semantically?
aeschli commentedon Sep 27, 2019
N. Taylor Mullen (@NTaylorMullen) This needs to be discussed in the issue where we design the SemanticHighlightRangeProvider. Maybe you can file an issue where you describe the idea?
22 remaining items
mattacosta commentedon Feb 7, 2020
sharedprophet Oleg Utkin (@NonLogicalDev)
This is from a quick and dirty example I was doing for another issue but, have a look at the parameters. Is there something I'm missing? It seems to be possible.
sharedprophet commentedon Feb 7, 2020
Matt Acosta (@mattacosta) that looks good. How did you do it?
mattacosta commentedon Feb 17, 2020
Basically I had my extension provide a set of default colors for certain modifiers and then had my server add one of those modifiers to each parameter.
sharedprophet commentedon Feb 18, 2020
Matt Acosta (@mattacosta) but can it work with other language servers? Can your language server act as an intermediary to other language servers so it is lanuguage agnostic?
mattacosta commentedon Feb 18, 2020
Not sure if I follow exactly, but if you were able to ask those servers for a list of unique symbols in a file, then yes?
sharedprophet commentedon Feb 18, 2020
I'd like to be able to implement a solution that works for any language without changing the language servers for those languages.
aeschli commentedon Feb 18, 2020
There's no need to be part of the language server. Any extension can contribute a semantic token provider, for any language. Alexandru Dima (@alexdima) What we still have to work on is to decide what happens when there are multiple providers for a file (which one wins?).
mattacosta commentedon Feb 18, 2020
sharedprophet Previous answer still applies. A highly theoretical yes.
I also want to emphasize that just because you can doesn't mean you should... that first run would be hella expensive (if it works at all), and I have no idea what kind of optimizations would be possible/required.
matklad commentedon Feb 28, 2020
Martin Aeschlimann (@aeschli) the wiki says
Is this actually implemented for themes yet?
I've tried adding
{ "name": "Pale Fire", "type": "dark", "editor.tokenColorCustomizationsExperimental": { "enumMember": "#ff0000" }, "tokenColorCustomizationsExperimental": { "enumMember": "#ff0000" }, }to my theme and it doesn't work. Adding this to user settings does work though.
I know I can style things by mapping semantic topics to textmate scopes and then styling the latter as usual, but that's a very roundabout way to do this.
aeschli commentedon Feb 28, 2020
The property in the theme is called
tokenStylingRules. It's not yet documented and might be changed.matklad commentedon Feb 28, 2020
Hm, doesn't seem to work:
matklad/pale-fire@01bca94
mattacosta commentedon Feb 29, 2020
If a theme has a
tokenColorskey, it looks like the_loadColorThemefunction returns before ever readingtokenStylingRules.vscode/src/vs/workbench/services/themes/common/colorThemeData.ts
Lines 566 to 580 in fc9543a
aeschli commentedon Mar 2, 2020
Ok, sorry, color style customization in themes in not ready yet to be used yet. I'll complete that in the March milestone.