[英]VS Code : how to use a semantic token in color theme?
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...我尝试更新我为 VS Code 制作的颜色主题(简单的焦点),但我从未找到任何主题创建者关于如何使用新语义标记的指南......
I have set "semanticHighlighting": true
in my theme我在我的主题中设置了
"semanticHighlighting": true
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.例如,我想为类着色,并且 class 定义(
entity.name.type.class.js
)和创建( entity.name.type.js
)有特定的 textMate 范围,但是当使用MyClass.props = {}
时,否则 - 如 MyClass.4 MyClass.props = {}
– 唯一的 scope 是一个通用variable.other.object.js
。other.object.js 我不想碰它,因为它会弄乱其他东西。 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?因此,当我检查范围时,我看到语义标记
class
也匹配所有类定义和创建,但我们应该如何使用它?
I tried naively to just add a scope "class", which isn't working.我天真地尝试添加一个 scope “类”,但它不起作用。
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.我能找到的关于语义标记的所有信息都与创建自定义语言有关,对主题创建者没有任何意义,所以我的猜测是它只是假设它像 textMate 范围一样工作,但事实并非如此。 Please someone enlighten me!
请有人赐教!
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
.在您的主题文件中,您需要添加
semanticTokenColors
,据我所知,这些将覆盖您在 tokenColors 中设置的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
语法类似于
tokenColors
但您也可以为每个标记指定修饰符,例如class.defaultLibrary
或class.declaration
您也可以通过设置*.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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.