# Fix json\! empty-string highlighting in Rust \(\#55126\) · gitcafe/zed

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

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

Visibility: public

Requested revision: f4f527073d2a9afdffea6bc3a1207fe9c1f93af8

Requested commit: f4f527073d2a9afdffea6bc3a1207fe9c1f93af8

Commit: f4f527073d2a9afdffea6bc3a1207fe9c1f93af8

Tree: 27d607e0e66ab78068ec978ac6f325da7e491d31

Author: saberoueslati

Committer: GitHub

## Message

```
Fix json! empty-string highlighting in Rust (#55126)

## Context

This fixes incorrect syntax highlighting inside Rust `json!` macros when
a JSON value is an empty string. In the current Rust tree-sitter
injection setup, most macro bodies are reparsed as nested Rust, which
works for macros like `vec!` but breaks down for JSON-shaped `json!({
... })` content. When the nested Rust parse loses sync at `""`, later
values can inherit incorrect highlighting.

Closes #54838

The fix treats `json!` as an exception to the generic nested-Rust macro
injection rule. That keeps the outer Rust layer responsible for
token-level highlighting inside the macro body, which is enough to
correctly color JSON keys, string values, and booleans without
introducing a brittle JSON-specific injection for Rust token trees.

Manual test after the fix below :

[Screencast from 2026-04-29
00-53-01.webm](https://github.com/user-attachments/assets/26453acf-1d72-4a97-9969-3f8e236dc0cd)

## How to Review

- `crates/grammars/src/rust/injections.scm`: Start here. This is the
functional fix. The generic Rust macro injection rule now excludes
`json`, so `json!` and `serde_json::json!` bodies are no longer reparsed
as nested Rust. Existing special cases like `view!`, `html!`, `sql!`,
and regex-related behavior are left unchanged.

- `crates/language/src/syntax_map/syntax_map_tests.rs`: This adds a
regression test covering the reported case. It verifies that an empty
string inside `serde_json::json!({ ... })` does not break subsequent
highlighting, and that the expected string and boolean captures still
appear for the later JSON entries.

## Self-Review Checklist

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

Release Notes:

- Fixed incorrect Rust syntax highlighting after empty string values
inside `json!` macros.
```

## Parents

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

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