我正在对this color theme进行VSCode的本地调整。该主题将主要用于Java和C ++代码。
我希望函数和方法声明颜色与函数和方法调用调用不同。
因此,以下两个实例中的单词Foo将是不同的颜色......
public void Foo(String s, int d) {
}
someClass.Foo("blah" , 2);
目前,为此功能设置颜色的代码块如下所示
{
"name": "Functions",
"scope": "entity.name.function, meta.require, support.function.any-method",
"settings": {
"foreground": "#e26660"
}
},
如果函数调用使用默认的前景文本颜色,我会没事的。
对于以下范围的函数调用集颜色,请添加以下设置:
{
"name": "Function call",
"scope": "meta.function-call.generic, meta.function-call.object, meta.function-call.static",
"settings": {
"foreground": "#e26f60"
}
},
此外,您可以通过设置范围来设置仅CPP的颜色
meta.function-call.cpp
如果您没有获得基于范围的答案,则可以通过基于正则表达式的方法完成更多工作。使用像Highlight这样的扩展,它允许您为可以通过正则表达式捕获的字符串指定synatx突出显示。例如,
"highlight.regexes": {
"(\\b.*\\.)([^(\\s]*)(\\s*\\(.*\\))": {
"regexFlags": "g",
"filterLanguageRegex": "(java|cpp)",
\\ "filterFileRegex" : ".*\\.java",
"decorations" : [
{}, // first capture group, " do nothing
{ "color": "red",
"fontWeight": "bold",
"padding": "3px", // only pads top and bottom unfortunately
"backgroundColor": "darkgreen",
// "border": "1px solid white",
// "borderRadius": "4px"
},
{} // third capture group, ", do nothing
]
},
"((?:void|int)\\s+)([^(\\s]*)(\\s*\\(.*\\))": {
"regexFlags": "g",
"filterLanguageRegex": "(java|cpp)",
\\ "filterFileRegex" : ".*\\.java",
"decorations" : [
{}, // first capture group, " do nothing
{ "color": "red",
"fontWeight": "bold",
"padding": "3px", // only pads top and bottom unfortunately
"backgroundColor": "darkgreen",
// "border": "1px solid white",
// "borderRadius": "4px"
},
{} // third capture group, ", do nothing
]
}
其中第一个在第二个捕获组中捕获了像someClass.Foo("blah" , 2);
和Foo
这样的调用。
其中第二个在第二个捕获组中捕获了像public void Foo(String s, int d)
和Foo
这样的调用。
我稍微简化了第二个正则表达式(我只添加了void
和int
,但你可以轻松添加其他替代品)。