Skip to content

languages: Improve semantic token highlighting for parameters and Python#52130

Merged
SomeoneToIgnore merged 6 commits intozed-industries:mainfrom
lingyaochu:semantic
Mar 23, 2026
Merged

languages: Improve semantic token highlighting for parameters and Python#52130
SomeoneToIgnore merged 6 commits intozed-industries:mainfrom
lingyaochu:semantic

Conversation

@lingyaochu
Copy link
Copy Markdown
Contributor

@lingyaochu lingyaochu commented Mar 22, 2026

Context

Zed's semantic token highlighting does not cover all token types returned by language servers, so the highlighting looks fairly primitive compared with tree-sitter highlighting, especially for Python language servers. This PR adds some global and Python-specific rules for better highlighting.

I need to admit that the built-in Python language servers currently have weak semantic highlighting implementations. Pylance, the closed-source Python language server from Microsoft, provides the best highlighting for now, but I think ty will do better, even though it still has a long way to go.

How to Review

Basically, this is a rule-adding change. Some rules are made global, and some are made Python-specific.

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

Release Notes:

  • Improved semantic token highlighting for parameters and Python

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 22, 2026
@github-actions github-actions bot added the community champion Issues filed by our amazing community champions! 🫶 label Mar 22, 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 Mar 22, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, ConradIrwin, SomeoneToIgnore, rtfeldman and smitbarmase and removed request for a team March 22, 2026 13:11
Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Given that something visual is changed in this PR and we have https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#sending-changes , please add before/after screenshots.

@lingyaochu
Copy link
Copy Markdown
Contributor Author

I've attached a side-by-side comparison to show the rendering changes, where the old behavior is on the left and the new version is on the right. The examples include Python using the ty language server and Rust with rust-analyzer. I used red boxes and labels to highlight exactly how specific token types and modifiers—like docstrings, cls/self parameters, and constants—are now being handled. This should cover all the visual updates I made in this PR, and I apologize for not providing these screenshots in the initial submission.

comparision rust-comparision

@SomeoneToIgnore SomeoneToIgnore self-assigned this Mar 23, 2026
Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Thank you a lot!

@SomeoneToIgnore SomeoneToIgnore enabled auto-merge (squash) March 23, 2026 16:01
@SomeoneToIgnore SomeoneToIgnore merged commit 23e1bcf into zed-industries:main Mar 23, 2026
32 checks passed
@lingyaochu lingyaochu deleted the semantic branch March 23, 2026 16:44
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…hon (zed-industries#52130)

## Context

Zed's semantic token highlighting does not cover all token types
returned by language servers, so the highlighting looks fairly primitive
compared with tree-sitter highlighting, especially for Python language
servers. This PR adds some global and Python-specific rules for better
highlighting.

I need to admit that the built-in Python language servers currently have
weak semantic highlighting implementations. Pylance, the closed-source
Python language server from Microsoft, provides the best highlighting
for now, but I think ty will do better, even though it still has a long
way to go.
## How to Review

Basically, this is a rule-adding change. Some rules are made global, and
some are made Python-specific.

## Self-Review Checklist

<!-- Check before requesting review: -->
- [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

Release Notes:

- Improved semantic token highlighting for parameters and Python
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.

3 participants