C#语法突出显示颜色 [英] C# syntax highlight coloring

查看:304
本文介绍了C#语法突出显示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以像Visual Studio一样以某种方式分别更改字段/局部变量的颜色吗?以下是在Visual Studio中的外观(字段变量分配,读写为绿色,而局部变量分配,读写为白色):

但是在VSCode中,局部变量和字段变量的范围都是"variable.other.object.cs".和"variable.other.readwrite.cs"导致:

(播放器和动画均为绿色)

我还想区分静态对象和动态对象,它们都具有"variable.other.object.cs".范围.

在Visual Studio中,它看起来像这样:

但是在VSCode中看起来像这样:

有什么我可以做的吗?谢谢

解决方案

要实现您想要的功能,荧光笔需要了解"图像.代码语义.在

语义标记也会为您提供修饰符(在此示例中为 static )

 "editor.semanticTokenColorCustomizations":{已启用":是的,规则":{"field.static":{前景":#FF0000","fontStyle":斜体",},},}, 

或者,如果您更喜欢使用 textMateRules ,我还没有弄清楚如何指定修饰符.

 "editor.tokenColorCustomizations":{"textMateRules":[{范围":"entity.name.variable.field.cs",设置":{前景":#FF0000","fontStyle":斜体",},},]}, 

Can I somehow change the color of field/local variables separately like in Visual Studio? Heres how it looks like in Visual Studio (field variable assignment, readwrite is green, and local variable assignment, readwrite is white):

but in VSCode, the scope for both local and field variable is "variable.other.object.cs" and "variable.other.readwrite.cs" resulting in:

(both player and anim are green)

I would also like to differentiate between a static and dynamic objects, which both have the "variable.other.object.cs" scope.

In Visual Studio it would look like this:

but it looks like this in VSCode:

Is there anything I can do about this? Thanks

解决方案

To achieve what you want, the highlighter needs to "understand" code semantics. Semantic highlighting in VSCode was introduced early this year, and its support for languages are still limited. OmniSharp, the engine behind the C# highlighter, started supporting Roslyn-based semantics as an experimental feature.

You would first need to opt-in to enable the feature, then restart VSCode for it to take effect.

"csharp.semanticHighlighting.enabled": true,

I assume you know how to invoke the scope inspector, but for the sake of other readers, it's in View > Command Pallette > Developer: Inspect Editor Tokens and Scopes

You now have two options to specify custom highlighting; either using the newly available semantic token, or the old-school textMateRule scopes.

Semantic tokens will give you a modifier as well (static in this example)

"editor.semanticTokenColorCustomizations": {
    "enabled": true,
    "rules": {
        "field.static": {
            "foreground": "#FF0000",
            "fontStyle": "italic",
        },
    },
},

Or, if you prefer using textMateRules, I haven't figured out how to specify modifiers.

"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
            "scope": "entity.name.variable.field.cs",
            "settings": {
                "foreground": "#FF0000",
                "fontStyle": "italic",
            },
        },
    ]
},

这篇关于C#语法突出显示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆