# Handle dynamic registration of semantic tokens capability \(\#60015\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/2a93ca53fd1e56d5257ac0ee7f9b5d28f5f812fe)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 2a93ca53fd1e56d5257ac0ee7f9b5d28f5f812fe

Requested commit: 2a93ca53fd1e56d5257ac0ee7f9b5d28f5f812fe

Commit: 2a93ca53fd1e56d5257ac0ee7f9b5d28f5f812fe

Tree: 0f19a0e8d75a7c5c5eca9ea99380ababc24817a2

Author: Artem Kalytiuk

Committer: GitHub

## Message

```
Handle dynamic registration of semantic tokens capability (#60015)

In C# files nothing gets semantic highlighting — class fields and other
identifiers are colored by tree-sitter only, so a private field looks
the same as a plain local variable.

The reason: Roslyn (the C# language server) doesn't declare
`semanticTokensProvider` statically in its `initialize` response. It
registers it **dynamically** (`client/registerCapability`), and only
when the client advertises
`textDocument.semanticTokens.dynamicRegistration = true`. Zed advertised
`false` and didn't handle such a registration, so Roslyn never offered
semantic tokens at all. (rust-analyzer/gopls are unaffected — they
declare the capability statically.)

This is the first of two PRs. This one makes Roslyn actually **send**
semantic tokens. The companion PR (#60027) maps Roslyn's C#-specific
token types to theme styles — without it the tokens arrive but most are
dropped, since their types aren't in Zed's default rules.

## Solution

- Advertise `textDocument.semanticTokens.dynamicRegistration = true`.
- Handle the `textDocument/semanticTokens` registration and
unregistration so the capability is stored, following the existing arms
for `documentLink`, diagnostics, etc.

## Testing

- Added a test that dynamically registers and unregisters
`textDocument/semanticTokens` and checks the stored capability appears
and is cleared.
- Verified manually against Roslyn on a C# project: Zed now sends
`textDocument/semanticTokens/full` and gets tokens back; before this
change there was no semantic-token traffic at all.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Support dynamic registration of the `textDocument/semanticTokens`
capability.

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
```

## Parents

- [afaef857b987d924c5ec09265a83feb030283f48](https://git.cafe/gitcafe/zed/commit/afaef857b987d924c5ec09265a83feb030283f48?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/2a93ca53fd1e56d5257ac0ee7f9b5d28f5f812fe?format=markdown)
