如何让 VSCode 主题识别 C# 接口?

How can I make a VSCode theme recognize C# interfaces?

我正在尝试为 Visual Studio 代码设置一个主题,以达到我想要的效果。目前,我正在尝试使用 Obsidian 处理 C# 规则,但我不确定要使用哪个关键字来覆盖颜色自定义。 VSCode 似乎无法识别界面,因为它们是特定于语言的。

"editor.tokenColorCustomizations": {
        "functions" :{
            "foreground": "#F1F2F3"
        },
        "interface": { //not valid
            "foreground": "#B48C8C"
        } 
    }

如何获得 VSCode 颜色自定义以识别特定于 c# 的语法?

editor.tokenColorCustomizations 可以使用多个值:注释、函数、关键字、数字、字符串、类型和变量 .如果 none 对您有用 textMateRules 也可用。所以你可以这样做:

"editor.tokenColorCustomizations": {
    "textMateRules": [{
        "scope": "yourScopeHere",
        "settings": {
            "fontStyle": "italic",
            "foreground": "#C69650"
        }
    }]
   },

因此您只需要弄清楚“接口”所需的范围。

为此,请尝试 CTRL-Shift-P 并键入范围:选择

Developer: Inspect Editor Tokens and Scopes  

并且无论选择哪个关键字,例如 interface,您将获得其 textmate 范围的列表。那应该作为上面的范围值插入。 [根据我的经验,更准确的做法是打开“Inspect TM Scopes”面板,然后单击几个项目,然后单击一个,例如 interface,您想要的 - 范围面板将保持打开状态。] 您可以从范围面板复制。

您可能只需要列出主要范围,但如果需要缩小其范围,您可以将以逗号分隔的列表中列出的其他范围包含在 范围中:..., ..., ...

我相信可以通过编辑 "Program Files\Microsoft VS Code\resources\app\extensions\csharp\syntaxes" 通过添加对 "storage.type.interface.cs" 的支持以及符合约定的正则表达式来部分完成。

类似于[I]([A-Z][a-z][A-Za-z]*)

您还可以排除可能的不匹配,例如 IISManager, IPhoneDevice

https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide https://www.apeth.com/nonblog/stories/textmatebundle.html

祝你好运,如果你完成了请告诉我

基于

  1. 编辑"C:\Program Files\Microsoft VS Code\resources\app\extensions\csharp\syntaxes\csharp.tmLanguage.json":
  2. 查找:

    {"name":"storage.type.cs","match":"@?[[:alpha:]][[:alnum:] ]*"}

  3. 替换为:

    {"name":"storage.type.interface.cs","match":"@?[I][[:upper:]][[:alpha:]][ [:alnum:]]"},{"name":"storage.type.cs","match":"@?[_[:alpha:]][ _[:alnum:]]"}

  4. 添加到settings.json:

    "editor.tokenColorCustomizations": {
        "[Default Dark+]": { // remove scope to apply to all themes
            "textMateRules": [
                {
                    "scope": "entity.name.type.interface.cs",
                    "settings": {
                        "foreground": "#b8d7a3"
                    }
                },
                {
                    "scope": "storage.type.interface.cs",
                    "settings": {
                        "foreground": "#b8d7a3"
                    }
                }
            ]
        }
    },

VSCode 1.63.2:

Ctrl + Shift + P > 打开设置 (JSON)

粘贴这个:

  "editor.tokenColorCustomizations": {
            "[Default Dark+]": { 
                "textMateRules": [
                    {
                        "scope": "entity.name.type.interface",
                        "settings": {
                            "foreground": "#a4ddaf"
                        }
                    }
                ]
            }
        },