VSCode Java 语法高亮配置 - 仿 IDEA Darcula 主题
在 VSCode 中实现接近 IntelliJ IDEA Darcula 主题的 Java 语法高亮效果。
依赖:
- JetBrains Mono 字体
- Better Comments 插件(可选,用于 TODO 高亮)
特性:
- 静态成员斜体显示
- Javadoc
/***/与内容统一绿色 - TODO/FIXME 独立高亮
- 完整的 Semantic Token + TextMate 双层配置
配置如下
json
{
"java.compile.nullAnalysis.mode": "automatic",
"editor.fontSize": 14,
"editor.fontWeight": 400,
"editor.fontFamily": "JetBrains Mono",
// Better Comments 插件配置 (需安装插件)
"better-comments.tags": [
{ "tag": "TODO", "color": "#A8C023", "strikethrough": false, "underline": false, "bold": false, "italic": false },
{ "tag": "FIXME", "color": "#FF6B68", "strikethrough": false, "underline": false, "bold": false, "italic": false }
],
// Semantic Token 颜色 (语义级别,优先级高于 TextMate)
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"class": "#A9B7C6", // 类名
"interface": "#A9B7C6", // 接口名
"enum": "#A9B7C6", // 枚举名
"typeParameter": "#A9B7C6", // 泛型参数
"type": "#A9B7C6", // 类型
"namespace": "#A9B7C6", // 命名空间
"function": "#FFC66D", // 函数
"method": "#FFC66D", // 方法
"function.static": { "foreground": "#FFC66D", "fontStyle": "italic" },
"method.static": { "foreground": "#FFC66D", "fontStyle": "italic" },
"variable": "#A9B7C6", // 变量
"variable.readonly": { "foreground": "#9876AA", "fontStyle": "italic" },
"parameter": "#A9B7C6", // 参数
"property": "#9876AA", // 属性/字段
"property.static": { "foreground": "#9876AA", "fontStyle": "italic" },
"enumMember": { "foreground": "#9876AA", "fontStyle": "italic" },
"keyword": "#CC7832", // 关键字
"string": "#6A8759", // 字符串
"number": "#6897BB", // 数字
"comment": "#808080", // 注释
"regexp": "#6A8759", // 正则
"decorator": "#BBB529", // 装饰器
"annotation": "#BBB529" // 注解
}
},
// TextMate 规则 (词法级别)
"editor.tokenColorCustomizations": {
"textMateRules": [
// 普通注释 (灰色)
{ "scope": ["comment", "comment.line", "comment.block"], "settings": { "foreground": "#808080" } },
// TODO/FIXME 标记 (嫩绿)
{ "scope": "keyword.codetag.notation", "settings": { "foreground": "#A8C023" } },
// Javadoc 注释 (绿色斜体,包含 /** 和 */)
{
"scope": [
"comment.block.documentation",
"comment.block.javadoc",
"comment.block.documentation.java",
"comment.block.documentation.java punctuation.definition.comment.java",
"comment.block.javadoc punctuation.definition.comment.java"
],
"settings": { "foreground": "#629755", "fontStyle": "italic" }
},
// 关键字 (橙色)
{ "scope": ["keyword", "keyword.control", "keyword.operator.new", "storage.modifier"], "settings": { "foreground": "#CC7832" } },
// 字符串 (绿色)
{ "scope": ["string", "string.quoted"], "settings": { "foreground": "#6A8759" } },
// 转义字符 (橙色)
{ "scope": "constant.character.escape", "settings": { "foreground": "#CC7832" } },
// 数字 (蓝色)
{ "scope": "constant.numeric", "settings": { "foreground": "#6897BB" } },
// 函数/方法名 (黄色)
{ "scope": ["entity.name.function", "support.function"], "settings": { "foreground": "#FFC66D" } },
// 类型名 (浅灰)
{ "scope": ["entity.name.type", "entity.name.type.class", "entity.name.type.interface"], "settings": { "foreground": "#A9B7C6" } },
// 常量/枚举成员 (紫色斜体)
{ "scope": ["variable.other.constant", "variable.other.enummember"], "settings": { "foreground": "#9876AA", "fontStyle": "italic" } },
// 属性 (紫色)
{ "scope": "variable.other.property", "settings": { "foreground": "#9876AA" } },
// 注解 (黄色)
{ "scope": ["meta.annotation", "punctuation.definition.annotation"], "settings": { "foreground": "#BBB529" } },
// XML/HTML 标签 (黄色)
{ "scope": "entity.name.tag", "settings": { "foreground": "#E8BF6A" } },
// 属性名 (浅灰)
{ "scope": "entity.other.attribute-name", "settings": { "foreground": "#A9B7C6" } },
// JSON 属性名 (紫色)
{ "scope": "support.type.property-name", "settings": { "foreground": "#9876AA" } },
// 标点符号 (浅灰)
{ "scope": "punctuation", "settings": { "foreground": "#A9B7C6" } },
// 无效代码 (红色)
{ "scope": "invalid", "settings": { "foreground": "#FF6B68" } }
]
}
}