Customize syntax highlighting colors of data types and variables for typescript in Visual Studio Code

后端 未结 1 2042
轮回少年
轮回少年 2021-01-05 19:42

I would like customize syntax highlighting colors for typescript.

I use Visual Studio Code 1.16 and custom theme (Actual) Obsidian.

I try use featues editor

1条回答
  •  走了就别回头了
    2021-01-05 20:36

    You're on the right track.

    As you've seen, editor.tokenColorCustomizations can be used to set broad classes of tokens like "keywords", etc. The exact set of things that can be customized this way does not appear to be documented, but you can refer to the source code for ITokenColorCustomizations.

    Then there is the textMateRules section. This can be used to specify things that the "simple" method cannot. The documentation explains the basic idea, but a screenshot may help to illustrate:

    First, use the command palette (Ctrl+Shift+P) to run "Developer: Inspect TM Scopes". This pops up a window that will show the sequence of scope labels for any token.

    Edit 2020-07-24: As of VSCode 1.47 (and possibly a little earlier) the command is called "Developer: Inspect Editor Tokens and Scopes".

    Next, add an entry to textMateRules where the scope specifier matches the stack of scope labels. The matching rules are somewhat complicated but mostly intuitive; you'll probably get it pretty quickly just by experimenting. Changes to the rules take effect as soon as you save settings.json.

    Note: VSCode does not appear to completely or correctly implement the TextMate matching rules. It's close, but that's it. (Examples: VSCode does not implement exclusion with "-", and its resolution of "a c" versus "b c" seems incorrect.)

    For the specific elements in your question:

    • Data types can be matched with support.type.primitive
    • filteredProducts can be matched with variable.other.property
    • OnInit can be matched with entity.other.inherited-class

    Example (that just makes them all red):

            "textMateRules": [
                {
                    "scope": [
                        "support.type.primitive",
                        "variable.other.property",
                        "entity.other.inherited-class",
                    ],
                    "settings": {
                        "foreground": "#F00",
                    },
                },
            ],
    

    0 讨论(0)
提交回复
热议问题