VS Code:如何像 Eclipse 一样设置语义语法着色.默认语法着色不这样做

编程入门 行业动态 更新时间:2024-10-24 04:32:29
本文介绍了VS Code:如何像 Eclipse 一样设置语义语法着色.默认语法着色不这样做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在 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/microsoft/vscode/issues/96267

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

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

<小时>

来自 https://github/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:

It's also possible to define semantic theming rules in the user settings:

"editor.tokenColorCustomizationsExperimental": {
    "property.readonly": {
        "foreground": "#35166d"
    },
    "*.defaultLibrary": {
        "fontStyle": "underline"
    }
}

from https://github/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/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/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/microsoft/vscode-docs/blob/vnext/release-notes/v1_45.md#semantic-token-styling-in-the-user-settings:

Semantic coloring is available for TypeScript and JavaScript, with support for Java, C++ in the works. It is enabled by default for built-in themes and being adopted by theme extensions.

The editor.semanticTokenColorCustomizations allows users to overrule the theme settings and to customize the theming.

Example that adds semantic styling to all themes: ```

"editor.semanticTokenColorCustomizations": {
    "enabled": true,
    "rules": {
        "property.readonly": {
          "foreground": "#35166d"
        },
        "*.defaultLibrary": {
            "bold": true
        }
    }
}



The setting above colors all constants with #35166d and all occurrences of symbols from a default library (e.g. Math, setTimeout) bold.


Example that adds semantic styling to the Dark+ themes: ```

"editor.semanticTokenColorCustomizations": {
    "[Default Dark+]": {
        "enabled": true,
        "rules": {
            "parameter": { "underline": true },
            "*.declaration": { "bold": true }
        }
    }
}


The setting above underlines all parameters in the Dark + theme and
makes all symbol declarations bold.

Theming for semantic tokens is explained in more details in the
[Semantic Highlighting
Guide](/api/language-extensions/semantic-highlight-guide#theming).


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 一样设置语义语法着色.默认语法着色不这样做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 13:38:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法   语义   这样做   Code   Eclipse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!