-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
[themes] Explore theming support for semantic colors #77133
Comments
related: #32813 |
Do you mean that there will be option to set color variables and use them with themes making? Here is example what i talking about: Or maybe it's possible right now but i don't know how? |
This is a proposal on how to represent the classification that a semantic highlighter computes ( Semantic highlight range providerA 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. interface SemanticHighlightRangeProvider {
provideHighlightRanges(doc,...): [ Range, TokenType, TokenModifier[] ][];
} 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 TokenModifiersA TokenType describes the symbol (class, field, variable...) at the location. The TokenModifiers provide additional information on the symbols (static, declaration, write access...). 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 TokenModifiersVSCode will define a set of predefined (standardized) TokenTypes and TokenTypeModifiers, but extensions can add more if necessary: Predefined TokeTypes:
Predefined TokeTypes Modifiers: TokenTypes and TokenModifiers DefaultsEach 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
interface TokenTypeRegistry {
registerTokenType(id, default: { textMateScopesToProbe: string[], value: TokenStyleValue })
} type TokenStyleValue: = TokenStyle | TokenType | FunctionOf(TokenStyleValue) Theme DefinitionThe active color theme (or user setting) will define colors and styles ( interface TokenStyle {
foreground?: Color | ColorFunction
style?: bold | italic | underline
} {
"tokenStyles": {
"(typenType|*)[.tokenTypeModifier]*": TokenStyle,
//...
}
{
"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'
}
}]
} |
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: <form asp-antiforgery="true">
...
</form> The 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? |
@NTaylorMullen @AmadeusW That needs to be seen when we finalise the SemanticHighlightRangeProvider. Normally with providers we support more than one provider. |
Definitely, but what about registering a "language" with a range semantically? |
@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? |
Done: #81558 |
Just wanted to mention that the token type / token modifier design addresses the concerns about having a flat list of highlightings that I described here. Thanks! One minor comment is that e.g. the A question abut styling: would it make sense to allow including a background color in |
Thanks for the feedback @HighCommander4 . The |
This looks like good progress. However, in order to port semanticolor to VS Code, I need the ability either for the theme to determine color based on the token value (and modifiers), or for a language server to be able to provide actual style information. Would it be possible to add this kind of support? |
@sharedprophet Theming (determine the style based on the token type/modifiers) will be the responsibility of VSCode. I've started working on that. The language server just needs to provide ranges with types and modifiers. |
+1 for having support for Token Value. I'd love semantic coloring that could color the accessibility keywords based on visibility. E.g. bold and loud for public, and quiet and invisible for private. Would help encourage people to consider their visibility more, rather then default it to public. Would also love to be able to color C# Attributes, so that ASP.net HTTP stateful attributes are red, where as stateless green. |
@ryantheleach all the things you mentioned require language specific semantic knowledge and could be done in language servers without giving the token value to the theming layer. |
Whilst true, I think there is always going to be a point where someone is going to want something based on the token value, or it's easier to implement it at a level the user can easily customize, like my asp.net stateful/stateless http method attributes. as far as C# is confirmed they are all identical types and modifiers right? I'd foresee for that level of customizability, that as a user I'd need to define overrides for an attribute with a specific value. |
https://github.com/microsoft/vscode/wiki/Semantic-Highlighting-Overview has a summary of the implemented semantic highlight APIs and user settings. Semantic highlighting for JS in HTML and for TypeScript has been added. Work has started for Java and C++ and a semantic highlight LSP has been proposed. There's still lot of work to be done, but I close this issue as the |
It still lacks a way for token theming to be modified based on the text of the token... |
If I understand correctly this will still not let the identifiers to be consistently coloured—not by their role—but by their value. It would be great for VSCode to implement something akin to what IntelliJ does. Examples:
Having identifiers coloured by their attributes is not quite as useful as having them coloured by their value. I know it sounds silly, but not having this feature pushes me away from using it, because it helps immensely to navigate code faster, and helps me with my mild case of dyslexia. I keep coming back to this issue though. Hoping that this will one day get implemented, and I will finally feel compelled to give VSCode a try as an IDE, as opposed to just another nice text editor for a quick simple change or two. |
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. |
@mattacosta that looks good. How did you do it? |
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. |
@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? |
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? |
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. @alexdima What we still have to work on is to decide what happens when there are multiple providers for a file (which one wins?). |
@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. |
@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. |
The property in the theme is called |
Hm, doesn't seem to work:
|
If a theme has a vscode/src/vs/workbench/services/themes/common/colorThemeData.ts Lines 566 to 580 in fc9543a
|
Ok, sorry, color style customization in themes in not ready yet to be used yet. I'll complete that in the March milestone. |
The text was updated successfully, but these errors were encountered: