mirror of
https://github.com/zed-industries/zed.git
synced 2026-07-30 18:18:07 +00:00
# Objective Closes #60928 Currently, only the declaration of parameters in a function header is highlighted as `variable.parameter`. Inside the function body, parameters are highlighted as normal variables, making them indistinguishable from local variables. This PR ensures consistent highlighting for parameters throughout their entire scope, helping developers distinguish between function inputs and locally defined variables. ## Solution - Updated the `default_semantic_token_rules.json`: when the token type is `parameter`, no matter what token modifiers are, it is now mapped to `variable.parameter` highlight style. ## Testing Tested locally with Rust. The improvement in visual hierarchy is demonstrated in the comparison below. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase | Before | After | | :---: | :---: | | <img width="1178" height="400" alt="before" src="https://github.com/user-attachments/assets/90a01543-2dcc-41e0-a2a3-f8020c6d77ee" /> | <img width="1194" height="387" alt="after" src="https://github.com/user-attachments/assets/c81ba273-2ea7-4d38-b7df-a6069c09c28a" />| --- Release Notes: - Improved semantic token highlighting to distinguish function parameters from local variables.
246 lines
6.3 KiB
JSON
246 lines
6.3 KiB
JSON
// Default semantic token rules for Zed (read-only).
|
|
//
|
|
// These rules map LSP semantic token types to syntax theme styles.
|
|
// To customize, add rules to "semantic_token_rules" in your settings.json.
|
|
// User-defined rules are prepended and take highest precedence.
|
|
// Extension language rules are applied next.
|
|
// These built-in defaults are applied last.
|
|
//
|
|
// Each rule has the following properties:
|
|
// - `token_type`: The LSP semantic token type to match. If omitted, matches all types.
|
|
// - `token_modifiers`: A list of LSP semantic token modifiers to match. All must be present.
|
|
// - `style`: A list of syntax theme styles to try. The first one found is used.
|
|
// - `foreground_color`: Override foreground color in hex format (e.g., "#ff0000").
|
|
// - `background_color`: Override background color in hex format.
|
|
// - `underline`: Boolean or color to underline with. If `true`, uses text color.
|
|
// - `strikethrough`: Boolean or color. If `true`, uses text color.
|
|
// - `font_weight`: One of "normal", "bold".
|
|
// - `font_style`: One of "normal", "italic".
|
|
//
|
|
// See the VSCode docs [1] and the LSP Spec [2] for reasoning behind these defaults.
|
|
//
|
|
// [1]: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers
|
|
// [2]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#semanticTokenTypes
|
|
[
|
|
// Types
|
|
{
|
|
"token_type": "namespace",
|
|
"token_modifiers": [],
|
|
"style": ["namespace", "module", "type"],
|
|
},
|
|
{
|
|
"token_type": "class",
|
|
"token_modifiers": ["declaration"],
|
|
"style": ["type.class.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "class",
|
|
"token_modifiers": ["definition"],
|
|
"style": ["type.class.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "class",
|
|
"token_modifiers": [],
|
|
"style": ["type.class", "class", "type"],
|
|
},
|
|
{
|
|
"token_type": "enum",
|
|
"token_modifiers": ["declaration"],
|
|
"style": ["type.enum.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "enum",
|
|
"token_modifiers": ["definition"],
|
|
"style": ["type.enum.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "enum",
|
|
"token_modifiers": [],
|
|
"style": ["type.enum", "enum", "type"],
|
|
},
|
|
{
|
|
"token_type": "interface",
|
|
"token_modifiers": ["declaration"],
|
|
"style": ["type.interface.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "interface",
|
|
"token_modifiers": ["definition"],
|
|
"style": ["type.interface.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "interface",
|
|
"token_modifiers": [],
|
|
"style": ["type.interface", "interface", "type"],
|
|
},
|
|
{
|
|
"token_type": "struct",
|
|
"token_modifiers": ["declaration"],
|
|
"style": ["type.struct.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "struct",
|
|
"token_modifiers": ["definition"],
|
|
"style": ["type.struct.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "struct",
|
|
"token_modifiers": [],
|
|
"style": ["type.struct", "struct", "type"],
|
|
},
|
|
{
|
|
"token_type": "typeParameter",
|
|
"token_modifiers": ["declaration"],
|
|
"style": ["type.parameter.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "typeParameter",
|
|
"token_modifiers": ["definition"],
|
|
"style": ["type.parameter.definition", "type.definition"],
|
|
},
|
|
{
|
|
"token_type": "typeParameter",
|
|
"token_modifiers": [],
|
|
"style": ["type.parameter", "type"],
|
|
},
|
|
{
|
|
"token_type": "type",
|
|
"token_modifiers": ["declaration"],
|
|
"style": ["type.definition"],
|
|
},
|
|
{
|
|
"token_type": "type",
|
|
"token_modifiers": ["definition"],
|
|
"style": ["type.definition"],
|
|
},
|
|
{
|
|
"token_type": "type",
|
|
"token_modifiers": [],
|
|
"style": ["type"],
|
|
},
|
|
// References
|
|
{
|
|
"token_type": "parameter",
|
|
"token_modifiers": [],
|
|
"style": ["variable.parameter"],
|
|
},
|
|
{
|
|
"token_type": "variable",
|
|
"token_modifiers": ["defaultLibrary", "constant"],
|
|
"style": ["constant.builtin"],
|
|
},
|
|
{
|
|
"token_type": "variable",
|
|
"token_modifiers": ["defaultLibrary"],
|
|
"style": ["variable.builtin"],
|
|
},
|
|
{
|
|
"token_type": "variable",
|
|
"token_modifiers": ["constant"],
|
|
"style": ["constant"],
|
|
},
|
|
{
|
|
"token_type": "variable",
|
|
"token_modifiers": [],
|
|
"style": ["variable"],
|
|
},
|
|
{
|
|
"token_type": "property",
|
|
"token_modifiers": [],
|
|
"style": ["property"],
|
|
},
|
|
{
|
|
"token_type": "enumMember",
|
|
"token_modifiers": [],
|
|
"style": ["type.enum.member", "type.enum", "variant"],
|
|
},
|
|
{
|
|
"token_type": "decorator",
|
|
"token_modifiers": [],
|
|
"style": ["function.decorator", "function.annotation", "attribute"],
|
|
},
|
|
// Declarations in the docs, but in practice, also references
|
|
{
|
|
"token_type": "function",
|
|
"token_modifiers": ["defaultLibrary"],
|
|
"style": ["function.builtin"],
|
|
},
|
|
{
|
|
"token_type": "function",
|
|
"token_modifiers": [],
|
|
"style": ["function"],
|
|
},
|
|
{
|
|
"token_type": "method",
|
|
"token_modifiers": ["defaultLibrary"],
|
|
"style": ["function.builtin"],
|
|
},
|
|
{
|
|
"token_type": "method",
|
|
"token_modifiers": [],
|
|
"style": ["function.method", "function"],
|
|
},
|
|
{
|
|
"token_type": "macro",
|
|
"token_modifiers": [],
|
|
"style": ["function.macro", "function"],
|
|
},
|
|
{
|
|
"token_type": "label",
|
|
"token_modifiers": [],
|
|
"style": ["label"],
|
|
},
|
|
// Tokens
|
|
{
|
|
"token_type": "comment",
|
|
"token_modifiers": ["documentation"],
|
|
"style": ["comment.documentation", "comment.doc"],
|
|
},
|
|
{
|
|
"token_type": "comment",
|
|
"token_modifiers": [],
|
|
"style": ["comment"],
|
|
},
|
|
{
|
|
"token_type": "string",
|
|
"token_modifiers": ["documentation"],
|
|
"style": ["string.doc"],
|
|
},
|
|
{
|
|
"token_type": "string",
|
|
"token_modifiers": [],
|
|
"style": ["string"],
|
|
},
|
|
{
|
|
"token_type": "keyword",
|
|
"token_modifiers": [],
|
|
"style": ["keyword"],
|
|
},
|
|
{
|
|
"token_type": "number",
|
|
"token_modifiers": [],
|
|
"style": ["number"],
|
|
},
|
|
{
|
|
"token_type": "regexp",
|
|
"token_modifiers": [],
|
|
"style": ["string.regexp", "string"],
|
|
},
|
|
{
|
|
"token_type": "operator",
|
|
"token_modifiers": [],
|
|
"style": ["operator"],
|
|
},
|
|
// Not in the VS Code docs, but in the LSP spec.
|
|
{
|
|
"token_type": "modifier",
|
|
"token_modifiers": [],
|
|
"style": ["keyword.modifier"],
|
|
},
|
|
// C#
|
|
{
|
|
"token_type": "event",
|
|
"token_modifiers": [],
|
|
"style": ["type.event", "type"],
|
|
},
|
|
]
|