【问题标题】:What is the token name for types in VSCode Typescript syntax highlighting?VSCode Typescript 语法高亮中类型的标记名称是什么?
【发布时间】:2021-10-21 10:25:18
【问题描述】:

我想更改 VSCode 语法突出显示的样式,以便区分类型和类。

class Thing; // should be one color
type ThingT; // should be another color

我需要指定的令牌名称是什么?我需要TODO Highlight吗?

【问题讨论】:

标签: typescript visual-studio-code vscode-settings syntax-highlighting


【解决方案1】:

class 的前景色使用范围entity.name.type.class.tstype 使用 entity.name.type.alias.ts

更新:如果在 settings.json 中覆盖,请使用:

"editor.semanticTokenColorCustomizations": {
    "enabled": true,
    "rules": {
        "type": {
            "foreground": "#ff0000" // color here
        }
    }
}

仅供参考,您可以使用Developer: Inspect Editor Tokens and Scopes 命令查看范围。例如,我为我的 TypeScript 类得到了这个:

language typescript
standard token type Other
foreground #FFCB6B
background #0F0F0F
contrast ratio 12.78
--- ---
textmate scopes entity.name.type.class.ts meta.class.ts source.ts
foreground entity.name.type.class { "foreground": "#FFCB6B" }

您也可以使用Developer: Generate Color Theme From Current Settings 命令:

【讨论】:

  • 谢谢!我想将类着色保持为默认值并更改类型着色。当我执行上述操作时,我遇到了一些奇怪的行为:(1)当我输入类型名称时,颜色与预期一致。但是,当我完成输入时,它会恢复。 (2) 当我查看类型名称的悬停弹出窗口时,颜色符合预期。
  • 好的,我可以通过在editor.semanticTokenColorCustomizations 下定位"type" 对其进行测试并使其正常工作。请参阅更新的答案。它应该立即应用,但您可能需要使用 Reload Window 命令重新启动 vs 代码。
  • 可爱!而且,界面也暴露了!只是好奇,你是怎么想出来的?
  • 我只是在命令面板中随机输入关键字,直到找到有用的东西。通过这种方式,您可以了解很多有关 VS Code 功能的信息。
猜你喜欢
  • 2022-09-24
  • 2020-05-18
  • 2019-09-30
  • 2017-02-10
  • 2021-09-03
  • 1970-01-01
  • 2018-06-04
  • 2016-05-07
  • 1970-01-01
相关资源
最近更新 更多