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

Request adding new 'decorator' semantic token scopes for Javascript/Typescript #114082

Closed
gaplo917 opened this issue Jan 9, 2021 · 2 comments
Closed
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders semantic-tokens Semantic tokens issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@gaplo917
Copy link

gaplo917 commented Jan 9, 2021

Current Limitation

In the current Typescript development, after enabling Semantic Highlighting, the typescript decorators are identified as a function. I have no way to specify the decorator syntax color.

Consider the color scheme extension contains the following configuration

    "semanticTokenColors": {
        "function": {
            "foreground": "#A6E22E"
        },
     },
     "tokenColors" :  {
          "name": "Typescript / Javascript Decorator",
          "scope": [
              "meta.decorator.ts variable.other.readwrite.ts"
          ],
          "settings": {
              "foreground": "#BBB529"
          }
      },

Let's check the following rendered images.

Disabled Semantic Highlighting (Expected Color I want)
Screenshot 2021-01-09 at 23 46 56

Enabled Semantic Highlighting (No way configure as function semantic token type overwrite)
Screenshot 2021-01-09 at 23 47 16

Motivation

This limitation is an obstacle for syntax highlighting color scheme developers to use rich color to represent different syntax.

Real World Codebase example and IDE Competitor

Consider in a typescript graphql development with

  • type-graphql : Use lots of decorator with typescript reflect meta data to generate GraphQL schema
  • typedi : Use decorator to register/indicate the dependencies injection

those two libraries heavily use decorators to abstract and simplify the code bases.

However, current VSCode Typescript development lacking decorator semantic token causing a limitation that decorator syntax highlighted color must be the same color with function.
Screenshot 2021-01-10 at 00 09 36

Others IDE Competitor(Intellij Ultimate / WebStorm), has no limitation with its "Semantic highlighting" implementation
Screenshot 2021-01-10 at 00 09 16

It would be great if VSCode can solve this limitation and gives more flexibility for syntax highlighting color scheme developer to use more color to represent different syntax. In my opinion, the more consistent syntax color representation, the more productivity on reading source code just like the design philosophy of Dark and Dark+.

Suggestion

Adding a new semantic token type can solve this problem. To keep the backward compatibility of the wide range of typescript color schemes, entity.name.function should be used as a fallback for those color themes that might not yet be adding the new color, i.e. semanticTokenColors.decorator.

Semantic token type Fallback Textmate scopes
decorator meta.decorator, entity.name.function
@dannymcgee
Copy link

Just wanted to throw in my two-cents as a theme creator and someone who fusses about syntax highlighting more than any sane human should:

While I do think it would be great to have a dedicated semantic token for decorators/annotations/attributes (which has also been brought up on another issue), I also think it would be great if themes (or user color customizations) could set something like an !important flag on a color definition targeting a TM grammar scope.

One huge pet peeve of mine is that my theme slightly fades the delimiters on strings by targeting the punctuation.definition.string scope, but most of the time the LSP client for any given language will just stomp on that with a "String" semantic token that includes the quote marks. I don't want to turn off semantic tokens, because there's a lot of situations where they'll be more accurate than the TM grammar and I value that accuracy. But having the ability to explicitly override a semantic token in certain contexts could solve both my string-delimiter issue and the TS/JS decorator issue.

@aeschli aeschli added this to the October 2021 milestone Oct 21, 2021
@aeschli aeschli added semantic-tokens Semantic tokens issues feature-request Request for new features or functionality labels Oct 21, 2021
@aeschli aeschli added the verification-needed Verification of issue is requested label Oct 25, 2021
@aeschli
Copy link
Contributor

aeschli commented Oct 25, 2021

To verify:

  • open and run the semantic-tokens-sample
  • In the [Extension Development Host] window, open sample/sample.semanticLanguage in the editor
  • check that [decorator] gets the decorator semantic token (use the Inspect Editor Tokens and Scopes command

@rzhao271 rzhao271 added the verified Verification succeeded label Oct 26, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders semantic-tokens Semantic tokens issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants
@gaplo917 @aeschli @rzhao271 @dannymcgee and others