语法突出显示颜色的含义分为两部分:
第一部分由VSCode内置的语法描述确定。VSCode使用基于TextMate语法的系统。语法是在VSCode源代码中定义的(例如JavaScript.tmLanguage.json),但是以这种形式经历了两个后期处理阶段,使它们几乎不可读。没有关于这些语法文件的意图的文档。它们通常至少大致遵循相关的语言规范,但存在许多特殊的偏差。
了解定义令牌的最实用方法是使用命令面板(Ctrl + Shift + P)中的“开发人员:检查TM范围”工具。当您将光标放在标记上时,它将显示描述该标记的“作用域标签”。这些标签或多或少是人类可读的。
编辑2020-07-24:从VSCode 1.47开始(可能更早一点),该命令称为“开发人员:检查编辑器标记和作用域”。
例:
在上方,我们可以看到return
关键字最具体地分类为keyword.control.flow.js
。它位于Java语言源代码()中meta.block.js
的函数定义(meta.function.js
)中的括号括起来的代码块(source.js
)中。
That sequence of scope labels is the closest thing there is to a "meaning" for a token in VSCode.
Next, there is the process of mapping that sequence of scope labels to a color and font style. That is done by the theme. In my case I am using Visual Studio Light, defined in the VSCode sources in light_vs.json. In the case of the return
keyword, this is the applicable fragment:
{
"scope": "keyword.control",
"settings": {
"foreground": "#0000ff"
}
},
This says, basically, that anything with a scope label beginning with "keyword.control" shall have a blue color. But other fragments may override this one; the rules are somewhat complex. Why blue? It's an arbitrary aesthetic choice.
为什么function
和NaN
具有相同的颜色?语法为它们分配了不同的范围标签(storage.type.function.js
vs constant.language.nan.js
),但是恰好您正在使用的主题(Dark +)为它们分配了相同的颜色(与我的一样)。我发现这是一个奇怪的选择,但只能推测原因。
您没有问,但是接下来的一个明显问题是如何自定义这些颜色,例如给定颜色function
和NaN
其他颜色。看到这个答案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句