You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅为Rust语言开启VS Code的语义高亮?

仅为Rust开启语义高亮的解决方案

你当前的问题是全局关闭语义高亮后,仅为Rust开启,但设置semanticTokenColorCustomizations后所有语言都触发了语义高亮。问题出在语义颜色规则是全局生效的,即使其他语言的语义高亮开关关闭,这些规则仍可能被误触发。

正确的做法是将语义颜色规则限定在Rust语言范围内,修改后的配置如下:

"editor.semanticHighlighting.enabled": false,
"[rust]": {
    "editor.semanticHighlighting.enabled": true
},
"editor.semanticTokenColorCustomizations": {
    "[JetBrains Darcula Theme]": {
        "[rust]": {
            "rules": {
                "*.attribute": {
                    "foreground": "#BBB529"
                },
                "lifetime": {
                    "foreground": "#20999D"
                },
                "typeParameter": {
                    "foreground": "#20999D"
                },
                "*.mutable": {
                    "foreground": "#BCA5C4",
                    "underline": true
                },
                "macro": {
                    "foreground": "#4EADE5"
                },
                "macroBang": {
                    "foreground": "#4EADE5"
                },
                "enumMember": {
                    "foreground": "#9876AA"
                },
                "*.constant": {
                    "foreground": "#9876AA"
                },
                "string": {
                    "foreground": "#6A8759"
                },
                "unresolvedReference": {
                    "foreground": "#9876AA"
                },
                "operator": {
                    "foreground": "#abb2bf"
                }
            }
        }
    }
}

核心修改点是把rules嵌套在[rust]块内,这样语义颜色规则只会作用于Rust文件,同时保持全局语义高亮关闭、仅Rust开启的设置。

另外,确保你安装的Rust语言插件(rust-analyzer)是最新版本,旧版本可能存在语义高亮的兼容性问题。

内容的提问来源于stack exchange,提问作者bernardoamorim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 00:12:43