VS Code:如何在颜色主题中使用语义标记? [英] VS Code : how to use a semantic token in color theme?

查看:32
本文介绍了VS Code:如何在颜色主题中使用语义标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我天真地尝试只添加一个范围类",但它不起作用.

我能找到的关于语义标记的所有内容都与创建自定义语言有关,对于主题创建者来说没有任何关系,所以我猜测它只是假设它像 textMate 范围一样工作,但事实并非如此.求大神赐教!

 "semanticTokenColors": {"命名空间": "#ffffff","type": "#ffffff","struct": "#ffffff","class": "#ffffff",class.readonly":{"前景": "#ffffff","fontStyle": "粗斜体"},*.宣言" : {"fontStyle": "粗体"},"*.readonly" : "#ffffff",}

您可以在此处找到所有范围和修饰符

<块引用>

标准语义标记类型:

命名空间类型、类、枚举、接口、结构、类型参数参数、变量、属性、枚举成员、事件函数、成员、宏标签注释、字符串、关键字、数字、正则表达式、运算符

<块引用>

标准语义标记修饰符:

声明只读、静态、弃用、抽象异步、修改、文档、defaultLibrary

I try to update a color theme I made (simple focus) for VS Code, but I never found any guide for theme creators on how to use the new semantic tokens...

I have set "semanticHighlighting" : true in my theme

For example I want to color classes, and there are specific textMate scopes for class definition (entity.name.type.class.js) and creation (entity.name.type.js), but when using a class otherwise – like MyClass.props = {} – the only scope is a generic variable.other.object.js which I don't want to touch for it messes others things. So when I inspect scopes, I see the semantic token class that also match all classes definitions and creation, but how are we suppose to use this?

I tried naively to just add a scope "class", which isn't working.

All I can find about semantic tokens is related to creating a custom language, nothing for theme creators, so my guess was that it was just suppose to work like textMate scopes, and yet it doesn't. Please someone enlighten me!

inspecting scopes

解决方案

In your theme file, you need to add the semanticTokenColors, these as far as I have seen will override the colors you have set in tokenColors. The syntax is similar to tokenColors but you can also specify modifiers for each token like class.defaultLibrary or class.declaration you can also set all modifiers at once by setting *.declaration

Here is a sample

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

You can find all the scopes and modifiers here

Standard semantic token types:

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

Standard semantic token modifiers:

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

这篇关于VS Code:如何在颜色主题中使用语义标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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