如何在VSCode扩展中自定义语法标记的颜色 [英] How to customize the color of custom syntax tokens in VSCode extension
问题描述
TLDR;如何让扩展对扩展定义的语法进行着色,而不是用户必须启用的颜色主题?
我正在尝试将此Sublime Text plugin (ToDone)移植到VSCode。
它为待办事项列表创建语法,然后使用语法突出显示来强调重要任务、静音已完成任务等。
我通过Customize a Color Theme找到"editor.tokenColorCustomizations"
。当我在我的用户设置中使用它时,它可以使用新语法,但当我在扩展清单的package.json#contributes
部分使用它时,它会失败。
{
"contributes": {
"languages": [
{
"id": "todone",
"aliases": [
"ToDone",
"To-Done"
],
"extensions": [
".todone",
".todo"
]
}
],
"grammars": [
{
"language": "todone",
"scopeName": "text.todone",
"path": "./todone.tmLanguage"
}
],
"configurationDefaults": {
"[todone]": {
"editor.insertSpaces": false,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "symbol.definition.task-heading.todone",
"settings": {
"foreground": "#ff8800"
}
}
]
}
}
}
}
}
到目前为止,语法看起来还不错--这正是Sublime插件正在使用的内容,并且正确地应用了用户设置中的颜色。此外,设置的格式似乎还可以,因为"editor.insertSpaces"
正在应用,并且颜色在用户设置中显示时可以正常工作。
最后,我收到一条关于扩展包.json中"editor.tokenColorCustomizations"
设置的非常令人失望的'Warning' 'Unknown editor configuration setting'
消息。
所以,听起来好像没有为扩展启用此设置?
我看到的另一种可能的方法是使用装饰物。但是,我没有看到任何关于检查与文档中的部分文本相关联的语法标记的内容,例如迭代文档的语法标记以应用修饰符的方法。因此,与"editor.tokenColorCustomations"相比,修饰器路由听起来很难。
如有任何有关如何开展这项工作的建议,我们将不胜感激。
编辑:到目前为止,代码在GitHub上:tiffon/vscode-todone
推荐答案
仅当您指定特定语言时才会失败。如果我不指定TODONE扩展名,则它对我有效。
"configurationDefaults": {
"editor.insertSpaces": false,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "symbol.definition.task-heading.todone",
"settings": {
"foreground": "#ff8800"
}
}
]
}
}
这篇关于如何在VSCode扩展中自定义语法标记的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!