本文介绍了VS Code:如何像 Eclipse 一样设置语义语法着色.默认语法着色不这样做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C/C++ 中,在 Eclipse 编辑器中,您可以在更多语言级别设置颜色:例如函数参数,局部变量可以有不同的颜色.可以更改静态和全局变量颜色.可以配置宏和宏引用.

如何在 Visual Studio Code 中执行此操作?我不确定 text mate tmLanguage 是否可以实现这一点.我找不到任何文档.

解决方案

[请参阅下文了解 v1.45 的更改]

您不仅限于主题提供的语义标记突出显示.您可以通过执行以下操作为支持的语言语义标记自己选择颜色和字体样式:

也可以在用户中定义语义主题规则设置:

"editor.tokenColorCustomizationsExperimental": {property.readonly":{前景":#35166d"},*.defaultLibrary":{"fontStyle": "下划线"}}

来自

如果没有列出语义标记类型,则该语言服务尚不支持它们.但毫无疑问,当他们这样做时,您会想要修改他们的一些颜色和字体样式选择.

vscode 1.45editor.tokenColorCustomizationsExperimental 重命名为 editor.semanticTokenColorCustomizations

参见 https://github.com/microsoft/vscode/issues/96267

此语法适用于 Insiders' Build 2020 年 4 月:

"editor.semanticTokenColorCustomizations": {启用":真,规则":{枚举成员":#ff0000"},[默认暗+]":{启用":真,规则":{"variable.readonly": "#ff00ff"},}},

来自 https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_45.md#semantic-token-styling-in-the-user-settings:

语义着色可用于 TypeScript 和 JavaScript,具有对 Java、C++ 的支持正在开发中.默认情况下启用它内置主题并被主题扩展采用.

editor.semanticTokenColorCustomizations 允许用户否决主题设置和自定义主题.

为所有主题添加语义样式的示例:```

"editor.semanticTokenColorCustomizations": {启用":真,规则":{property.readonly":{前景":#35166d"},*.defaultLibrary":{大胆":真实}}}

上面的设置为所有带有 #35166d 的常量和所有常量着色默认库中出现的符号(例如 MathsetTimeout) 粗体.

为 Dark+ 主题添加语义样式的示例:```

"editor.semanticTokenColorCustomizations": {[默认暗+]":{启用":真,规则":{参数":{下划线":真},"*.declaration": { "bold": true }}}}

上面的设置强调了 Dark + 主题中的所有参数和使所有符号声明加粗.语义标记的主题在【语义高亮指南](/api/language-extensions/semantic-highlight-guide#theming).

奇怪的是,在我的测试中,即使上面 "editor.semanticTokenColorCustomizations" 中的 enabled: true 您仍然需要启用此设置:

 "editor.semanticHighlighting.enabled": true

但这是默认设置.

In C/C++, in Eclipse editor you can set colors at a more language level:For eg function argument, local variable can have different colors. Static and global variable colors can be changed. Macros and Macro references can be configured.

How to do this in Visual Studio Code? I am not sure if the text mate tmLanguage can achieve this. I could not find any documentation for this.

解决方案

[see further below for v1.45 changes]


You are not limited to a theme's supplied semantic token highlighting. You can choose the color and fontstyle yourself for supported language-semantic tokens by doing this:

from https://github.com/microsoft/vscode/wiki/Semantic-Highlighting-Overview#as-a-theme-author-do-i-need-to-change-my-theme-to-make-it-work-with-semantic-highlighting

And see especially https://github.com/microsoft/vscode/wiki/Semantic-Highlighting-Overview#how-can-i-find-out-what-semantic-tokens-are-available-and-how-they-are-themed for how to discover the semantic tokens. For example:

If there is no semantic token type listed, that language service does not yet support them. But undoubtedly, when they do you will want to modify some of their color and fontstyle choices.


vscode 1.45 will rename editor.tokenColorCustomizationsExperimental to editor.semanticTokenColorCustomizations

See https://github.com/microsoft/vscode/issues/96267

This syntax works for me in the Insiders' Build April, 2020:

"editor.semanticTokenColorCustomizations": {
    "enabled": true,
    "rules": {
        "enumMember": "#ff0000"
    },
    "[Default Dark+]": {
        "enabled": true,
        "rules": {
            "variable.readonly": "#ff00ff"
        },
    }
},


From https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_45.md#semantic-token-styling-in-the-user-settings:




Oddly, in my testing even with the enabled: true in the above "editor.semanticTokenColorCustomizations" you still need this setting enabled:

    "editor.semanticHighlighting.enabled": true

but that is the default.

这篇关于VS Code:如何像 Eclipse 一样设置语义语法着色.默认语法着色不这样做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 22:24