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

如何在VSCode中修改C++文件类JSDoc标签及Doxygen标记的高亮颜色

Got it, let's break this down so you can get those C++ Doxygen tags looking exactly like your JS JSDoc ones—blue @param, @return, and all. Here's how to make it happen in VSCode:

1. Open Your User Settings in JSON Format

First, pull up the command palette:

  • Windows/Linux: Press Ctrl+Shift+P
  • Mac: Press Cmd+Shift+P

Type in Preferences: Open User Settings (JSON) and hit enter. This opens the raw JSON config file where we'll add our custom highlighting rules.

2. Add Custom Textmate Rules for C++ Comments

VSCode uses Textmate syntax scopes to style text, so we'll target the Doxygen tags in C++ comments and force them to use the same blue as JS JSDoc tags. Paste this into your settings.json file (make sure it's inside the top-level curly braces):

"editor.tokenColorCustomizations": {
    "textMateRules": [
        // Target all Doxygen-style @tags in C++ single-line and block comments
        {
            "scope": "comment.line.double-slash.cpp entity.name.tag.doxygen.cpp, comment.block.cpp entity.name.tag.doxygen.cpp",
            "settings": {
                "foreground": "#569CD6" // This is VSCode's default JS JSDoc tag blue—feel free to tweak the hex code!
            }
        },
        // Optional: If you also want to style JSDoc-style class tags (like @class) the same way
        {
            "scope": "comment.line.double-slash.cpp storage.type.class.jsdoc.cpp, comment.block.cpp storage.type.class.jsdoc.cpp",
            "settings": {
                "foreground": "#569CD6"
            }
        }
    ]
}

Quick breakdown of what this does:

  • The first rule targets every @param, @return, @brief, etc., in both // single-line comments and /* */ block comments in .cpp/.hpp files.
  • The hex color #569CD6 matches the default blue used for JSDoc tags in JavaScript files. If you want a different shade, just swap in your preferred hex value.
3. Double-Check the Scope (If the Rules Don't Work)

Sometimes syntax scopes can vary based on installed extensions (like the official C/C++ extension). To confirm exactly what scope your Doxygen tags are using:

  1. Open a .cpp file with a comment containing @param
  2. Open the command palette again and run Developer: Inspect Editor Tokens and Scopes
  3. Click directly on the @param text—look in the right-hand panel for the "Scope" section. You'll see something like entity.name.tag.doxygen.cpp.
  4. If your scope is different, just replace the scope string in the JSON rule above with the one you found.
4. Optional: Match JS JSDoc's Exact Style (Including Font)

If you want the C++ tags to mirror JS JSDoc perfectly (like having italic text too), add the fontStyle property to the settings:

"settings": {
    "foreground": "#569CD6",
    "fontStyle": "italic"
}

Once you save the settings.json file, close and re-open your .cpp/.hpp files—your @param and @return tags should now be bright blue, just like they are in your JavaScript files.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:02:35