jab*_*tta 8 javascript textmate visual-studio-code vscode-settings
我试图通过TextMate语言语法使用Visual Studio Code的主题设置创建自定义语法样式。
具体来说,我想将所有JavaScript的保留关键字都斜体化。通过以下设置,我已经设法达到了98%的性能(剩余的注释包括在内)。
不幸的是,我找不到一些规则:
storage包括脂肪箭头符号,这一点我不希望包括。我想更具体的,如下面的设置可见,但无法找到更具体的设置constructor和const。另外,这"storage.type.function"是我能找到的最明确的功能设置(需要function关键字,但其中包含粗箭头)。keyword包括字符,如逻辑运算符等,同样,我不希望有。keyword.operator是必要的文本运营商(例如in,instanceof),但是包括字符运算符。eval(严格禁止的)或package(未使用的将来关键字)的规则。有任何想法吗?
const settings = {
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": [
// TODO: missing keywords: package, eval
// all comment types
"comment",
// true, false, null
"constant.language",
// import, from, export, default, return, if, for, break, continue, try, catch, finally,
// throw, default, yield, await
"keyword.control",
// TODO: remove operator symbols
// in, void, delete, instanceof
"keyword.operator",
// debugger
"keyword.other",
// new
"keyword.operator.new",
// enum
"storage.type.enum",
// super, this, arguments
"variable.language",
// attributes in html, jsx, etc.
"entity.other.attribute-name",
// TODO: remove storage.type after finding explicit for constructor, const, let, var
"storage.type",
// static, extends, async, private, public, implements
"storage.modifier",
// TODO: exclude fat arrow
// function
"storage.type.function",
// class
"storage.type.class",
// interface
"storage.type.interface",
],
"settings": {
"fontStyle": "italic"
}
},
]
},
};
Run Code Online (Sandbox Code Playgroud)
jab*_*tta 11
事实证明,在VS Code中,您可以轻松找到所需的范围。
用ctrl/cmd+ shift+ 打开命令搜索p并搜索Developer: Inspect TM scopes。然后,您可以单击想要查找范围的任何符号/单词左侧。
要回答我自己的问题:
const,let,var或function由本身关键字(storage.type.function包括保留字和箭头)。但是,功能箭头存在明确的范围:storage.type.function.arrow。这使我们可以包括整个storage范围,然后明确排除箭头。keyword.operator.expression 是仅以单词表示的运算符所需的范围。eval和package尚未公布。您可以指定eval与support.function和package用variable.other.readwrite,但这些范围很广泛,将包括许多其他的结果。话虽如此,以下列出了斜体显示VS Code中所有JavaScript保留关键字所必需的规则(还包括注释和jsx/ html属性):
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": [
// all comment types
"comment",
// true, false, null
"constant.language",
// import, from, export, default, return, if, for, break, continue, try, catch, finally,
// throw, default, yield, await
"keyword.control",
// in, void, delete, instanceof
"keyword.operator.expression",
// debugger
"keyword.other",
// new
"keyword.operator.new",
// super, this, arguments
"variable.language",
// attributes in html, jsx, etc.
"entity.other.attribute-name",
// static, extends, async, private, public, implements
// constructor, const, let, var, enum, class, function, interface
// no explicit scopes for constructor, const, let, var
// also no explicit scope for function without the arrow
// therefore we enable all storage and explictly exclude the arrow in another scope
"storage",
// // no explicit scope for the eval keyword yet
// // can be targeted with the scope below, but scope is too broad
// "support.function",
// // no explicit scope for the package keyword yet
// // can be targeted with the scope below, but scope is too broad
// "variable.other.readwrite",
],
"settings": {
"fontStyle": "italic"
}
},
{
"scope": [
// function keyword does not have an explicit scope without the arrow
// therefore we explictly exclude the function arrow from being italicized
"storage.type.function.arrow",
],
"settings": {
"fontStyle": ""
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1301 次 |
| 最近记录: |