Skip to content

editor: Support disabling semantic token highlighting via empty rules#52963

Merged
Veykril merged 4 commits intozed-industries:mainfrom
lingyaochu:semantic_cover
Apr 2, 2026
Merged

editor: Support disabling semantic token highlighting via empty rules#52963
Veykril merged 4 commits intozed-industries:mainfrom
lingyaochu:semantic_cover

Conversation

@lingyaochu
Copy link
Copy Markdown
Contributor

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Closes #52882, should help #52723

According to the Zed documentation, users should be able to disable semantic highlighting for a specific token type by adding an empty rule in settings.json.

However, the current implementation fails to respect this because its merging logic allows lower-priority default styles to "leak through" even when a matching high-priority rule is empty. This makes it impossible to selectively disable semantic tokens to reveal the underlying Tree-sitter highlighting when using "semantic_tokens": "combined". This is particularly problematic for extensions that provide specialized Tree-sitter queries which are currently being obscured by less desirable semantic tokens(#52723).

This PR fixes the logic to ensure that a completely empty high-priority rule acts as an opaque override, correctly disabling semantic styling for that token type and allowing Tree-sitter highlighting to show through as intended.

Release Notes:

  • Fixed a bug where semantic token highlighting could not be disabled via empty rules in settings.json.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 2, 2026
@github-actions github-actions Bot added the community champion Issues filed by our amazing community champions! 🫶 label Apr 2, 2026
@zed-community-bot zed-community-bot Bot added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Apr 2, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, Veykril and dinocosta and removed request for a team April 2, 2026 06:23
@Veykril Veykril assigned Veykril and unassigned dinocosta Apr 2, 2026
Copy link
Copy Markdown
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly oversight, thank you!

@lingyaochu
Copy link
Copy Markdown
Contributor Author

Here is a comparison using Rust code, specifically highlighting the Result type on line 17:

treesitter highlight:
treesitter

"semantic_tokens" set to "combined", without any user-defined rule:
combined_without_rule

"semantic_tokens" set to "combined", with an empty rule defined as:

{
  "global_lsp_settings": {
    "semantic_token_rules": [
      {
        "token_type": "enum",
        "token_modifiers": ["library", "defaultLibrary"],
      },
    ],
  },
}
combined_with_rule

@Veykril Veykril enabled auto-merge (squash) April 2, 2026 06:30
@Veykril Veykril merged commit de28867 into zed-industries:main Apr 2, 2026
41 checks passed
@Veykril
Copy link
Copy Markdown
Member

Veykril commented Apr 2, 2026

/cherry-pick preview

github-actions Bot pushed a commit that referenced this pull request Apr 2, 2026
…#52963)

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 is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #52882, should help #52723

According to the [Zed
documentation](https://zed.dev/docs/semantic-tokens#example-disabling-a-token-type),
users should be able to disable semantic highlighting for a specific
token type by adding an empty rule in `settings.json`.

However, the current implementation fails to respect this because its
merging logic allows lower-priority default styles to "leak through"
even when a matching high-priority rule is empty. This makes it
impossible to selectively disable semantic tokens to reveal the
underlying Tree-sitter highlighting when using "semantic_tokens":
"combined". This is particularly problematic for extensions that provide
specialized Tree-sitter queries which are currently being obscured by
less desirable semantic tokens(#52723).

This PR fixes the logic to ensure that a completely empty high-priority
rule acts as an opaque override, correctly disabling semantic styling
for that token type and allowing Tree-sitter highlighting to show
through as intended.

Release Notes:

- Fixed a bug where semantic token highlighting could not be disabled
via empty rules in `settings.json`.
@zed-zippy
Copy link
Copy Markdown
Contributor

zed-zippy Bot commented Apr 2, 2026

🍒💥 Cherry-pick did not succeed
https://github.com/zed-industries/zed/actions/runs/23888590370

@lingyaochu lingyaochu deleted the semantic_cover branch April 2, 2026 07:40
piper-of-dawn pushed a commit to piper-of-dawn/zed that referenced this pull request Apr 25, 2026
…zed-industries#52963)

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 is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes zed-industries#52882, should help zed-industries#52723

According to the [Zed
documentation](https://zed.dev/docs/semantic-tokens#example-disabling-a-token-type),
users should be able to disable semantic highlighting for a specific
token type by adding an empty rule in `settings.json`.

However, the current implementation fails to respect this because its
merging logic allows lower-priority default styles to "leak through"
even when a matching high-priority rule is empty. This makes it
impossible to selectively disable semantic tokens to reveal the
underlying Tree-sitter highlighting when using "semantic_tokens":
"combined". This is particularly problematic for extensions that provide
specialized Tree-sitter queries which are currently being obscured by
less desirable semantic tokens(zed-industries#52723).

This PR fixes the logic to ensure that a completely empty high-priority
rule acts as an opaque override, correctly disabling semantic styling
for that token type and allowing Tree-sitter highlighting to show
through as intended.

Release Notes:

- Fixed a bug where semantic token highlighting could not be disabled
via empty rules in `settings.json`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶 guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semantic token rules with empty style do not disable highlighting as documented

3 participants