如何让PHP属性(含参数、括号)从#[到]完全显示灰色?
VS Code PHP 属性全区域着色解决方案
你当前的配置仅匹配了meta.attribute.php基础作用域,无法覆盖属性内部的括号、参数名、参数值等子元素,所以这些部分未被着色。要实现从#[到]的整个属性标签统一设为灰色,需要补充覆盖所有相关子作用域:
在settings.json中更新配置如下:
"editor.tokenColorCustomizations": { "textMateRules": [ { "scope": [ "meta.attribute.php", "punctuation.definition.attribute.begin.php", "punctuation.definition.attribute.end.php", "meta.attribute-with-arguments.php", "variable.other.attribute.php", "constant.other.attribute.php", "string.quoted.single.attribute.php", "string.quoted.double.attribute.php", "punctuation.separator.key-value.attribute.php" ], "settings": { "foreground": "#464646" } } ] }
作用域说明
punctuation.definition.attribute.begin.php/end.php:匹配属性的#[和]括号meta.attribute-with-arguments.php:匹配带参数的属性整体variable.other.attribute.php:匹配参数名(如type、length)constant.other.attribute.php:匹配常量类型的参数值(如integer)string.quoted.*.attribute.php:匹配字符串类型的参数值(如'string')punctuation.separator.key-value.attribute.php:匹配参数的冒号分隔符
保存配置后,你的示例代码中所有#[...]区域都会统一显示为灰色。
内容的提问来源于stack exchange,提问作者NameX
相关产品推荐
相关产品推荐

