Zed nightly: rust: Refine sql! syntax injection (#58778)
Zed · IDE / editor · Released
View official release notes ↗ Copy link
Thanks for taking a look at this. I think this is a small but worthwhile
refinement to Zed's existing Rust SQL syntax injection behaviour.
Before screenshot
After screenshot
The main rationale is that Zed already recognises sql! as an explicit
Rust SQL injection marker. This PR does not introduce a new broad
heuristic, infer SQL from arbitrary Rust strings, or add
framework-specific matching. It narrows the existing sql! behaviour so
literal forms inject only the Rust string_content as SQL, rather than
the whole macro payload.
That distinction matters for real Rust SQL authoring. The current broad
payload capture can work for simple token-tree examples like:
sql!(SELECT * FROM carts);
but practical embedded SQL is often written as a normal string or raw
string, especially for PostgreSQL queries with single-quoted values,
multiline statements, dollar parameters, comments, and other syntax:
sql!(
r#"
SELECT *
FROM carts
WHERE status IN ('open', 'checkout_started')
"#
);
For those literal forms, treating Rust delimiters such as ", r#", or
"# as part of the SQL layer makes the injected SQL range less precise.
This PR fixes that by injecting the literal body only, whilst preserving
the historical unquoted token-tree form.
The practical benefit for Rust developers is straightforward: SQL
snippets, migrations, test fixtures, schema fragments, and other
explicit sql! blocks become easier to read and review in Zed without
requiring database-aware LSP support or any project-specific
configuration. The change is also deliberately conservative: it is
syntactic, opt-in through the existing sql! marker, test-backed, and
leaves non-sql! macros alone.
This should be a good fit for upstream because it improves behaviour Zed
already supports instead of expanding the matching policy into ambiguous
territory. It also follows the same general pattern used elsewhere in
Zed's injections: when a host-language string literal contains an
injected language, capture the literal body rather than the
host-language wrapper syntax.
I also want to call out related work in
#58016 and explicitly support
that PR as well.
The two changes are different in scope. This PR refines the existing
generic sql! marker and does not add SQLx matching. PR #58016 is the
SQLx-specific improvement, targeting sqlx::query!-style macros and
functions where many Rust backend developers write production queries
directly. That matters because SQLx users should not need to wrap SQLx
calls in another marker macro just to get highlighting; SQLx's
compile-time checking and call-site ergonomics are part of its value.
I see these as complementary rather than competing improvements. This PR
covers explicit generic SQL contexts such as snippets, migrations,
fixtures, and non-SQLx embedded SQL. PR #58016 covers first-class SQLx
call sites. Together, they move Zed toward a much stronger Rust
embedded-SQL editing experience while keeping each individual change
focused and reviewable.
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 SQL syntax highlighting in Rust
sql!string literals.
Source: Zed's official Zed release notes at github.com. Text reproduced from the source for reference; all rights belong to Zed. Patchwire is not affiliated with Zed.
More Zed releases
- v1.24.3 · Oct 16, 2026
- collab-staging: agent_ui: Respect effort-specific thinking controls (#62480) · Oct 16, 2026
- v1.25.0-pre · Oct 14, 2026
- v1.24.2 · Oct 14, 2026
- collab-staging: anthropic: Add support for Sonnet and Haiku 5.5 (#65555) · Oct 13, 2026
- nightly: Fix cpal-related issue on Windows (#65550) · Oct 13, 2026
- v1.24.2-pre · Oct 12, 2026
- v1.23.3 · Oct 12, 2026