【问题标题】:How can I make a VSCode theme recognize C# interfaces?如何让 VSCode 主题识别 C# 接口?
【发布时间】:2017-11-13 20:16:34
【问题描述】:

我正在尝试让 Visual Studio Code 的主题能够满足我的需求。目前,我正在尝试使用 Obsidian 处理 C# 规则,但我不确定使用哪个关键字来覆盖颜色自定义。 VSCode 似乎无法识别接口,因为它们是特定于语言的。

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

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

【问题讨论】:

    标签: c# visual-studio-code vscode-settings


    【解决方案1】:

    editor.tokenColorCustomizations 可以使用多个值:cmets、函数、关键字、数字、字符串、类型和变量。如果这些都不适合您,textMateRules 也可用。所以你可以这样做:

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

    所以你只需要弄清楚“interface”需要什么范围。

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

    Developer: Inspect TM Scopes  
    

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

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

    【讨论】:

    • 所以这种工作。如果我定义一个接口,则标记被标识为entity.name.type.interface.cs,但如果我转到另一个类的属性并查看它的变量类型,它只会显示storage.type.cs 的标记,与所有其他变量类型相同。如果我实现一个接口,同样的事情,它只被称为 storage.type.cs。但是,您让我走上了正确的道路,我正在通过实际的 json 文件对主题进行更多的自定义。
    • @PremierBromanov 你能找到你想要的吗?我正在寻找相同的运气!
    • @FernandoMoreira 不!只是习惯了,可惜
    • 对于那些只想复制粘贴配置的人:"editor.tokenColorCustomizations": { "textMateRules": [{ "scope": "storage.type.cs,entity.name.type. interface.cs", "settings": { "foreground": "#C69650" } }] }
    • 有没有办法检查默认范围的当前默认值?
    【解决方案2】:

    基于Davi's answer:

    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:]] em>"}

    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"
                        }
                    }
                ]
            }
        },
    

    【讨论】:

      【解决方案3】:

      我相信它可以通过编辑“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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-20
        • 2019-03-15
        • 2021-10-30
        • 1970-01-01
        • 2022-11-05
        • 2021-09-08
        • 1970-01-01
        • 2014-01-14
        相关资源
        最近更新 更多