【问题标题】:VS Code : how to use a semantic token in color theme?VS Code:如何在颜色主题中使用语义标记?
【发布时间】:2020-05-14 16:42:04
【问题描述】:

我尝试更新我为 VS Code 制作的颜色主题(简单的焦点),但我从未找到任何主题创建者关于如何使用新语义标记的指南...

我在我的主题中设置了"semanticHighlighting" : true

例如,我想为类着色,并且有用于类定义 (entity.name.type.class.js) 和创建 (​​entity.name.type.js) 的特定 textMate 范围,但是当使用其他类时 - 例如 MyClass.props = {} - 唯一的范围是通用的variable.other.object.js,我不想碰它,因为它会弄乱其他东西。因此,当我检查范围时,我看到语义标记 class 也匹配所有类定义和创建,但我们应该如何使用它?

我天真地尝试只添加一个范围“类”,但这是行不通的。

我能找到的关于语义标记的所有信息都与创建自定义语言有关,对主题创建者没有任何作用,所以我猜测它只是假设它像 textMate 范围一样工作,但事实并非如此。请高人赐教!

inspecting scopes

【问题讨论】:

标签: visual-studio-code themes


【解决方案1】:

在您的主题文件中,您需要添加semanticTokenColors,据我所知,这些将覆盖您在tokenColors 中设置的颜色。语法类似于tokenColors,但您也可以为每个标记指定修饰符,例如class.defaultLibraryclass.declaration,您还可以通过设置*.declaration 一次性设置所有修饰符

这是一个示例

   "semanticTokenColors": {
      "namespace": "#ffffff",
      "type": "#ffffff",
      "struct": "#ffffff",
      "class": "#ffffff",
      "class.readonly": {
         "foreground": "#ffffff",
         "fontStyle": "bold italic"
      },
      "*.declaration" : {
         "fontStyle": "bold"
      },
      "*.readonly" : "#ffffff",
  }

你可以找到所有的作用域和修饰符here

标准语义标记类型:

namespace
type, class, enum, interface, struct, typeParameter
parameter, variable, property, enumMember, event
function, member, macro
label
comment, string, keyword, number, regexp, operator

标准语义标记修饰符:

declaration
readonly, static, deprecated, abstract
async, modification, documentation, defaultLibrary

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 2018-04-10
    • 1970-01-01
    • 2019-07-24
    • 2017-07-07
    • 1970-01-01
    相关资源
    最近更新 更多