Files
zed/crates/languages/Cargo.toml
T
Ryan The Dev 27bbbc1cc4 languages: Highlight C/C++ preprocessor call arguments (#66875)
## Summary

Arguments of `preproc_call` nodes, like the `pack(push, 4)` in `#pragma
pack(push, 4)` or the `FOO` in `#undef FOO`, had no highlight capture,
so they always rendered as plain text. `#define` bodies are covered by
the injection, and `#if` conditions are parsed as expressions, but
nothing reached `preproc_call`'s `preproc_arg`.

I added a `(preproc_call argument: (preproc_arg) @preproc)` rule to both
the C and C++ highlight queries. I went with `@preproc` because every
built-in theme already defines it, and it makes the whole directive line
one color, like VS Code does. Happy to switch to `@constant.macro` or
`@string` if you'd prefer.

| Before | After |
| --- | --- |
| <img alt="preproc-before"
src="https://github.com/user-attachments/assets/95fa0660-c41f-4433-98c7-887d9871fe1d"
/> | <img alt="preproc-after"
src="https://github.com/user-attachments/assets/7c4fa978-a6c1-4707-a627-6d7e32dd897a"
/> |
| <img alt="preproc-before-light"
src="https://github.com/user-attachments/assets/3d2479ce-cd04-42ae-bfeb-e5c8c49fb9a6"
/> | <img alt="preproc-after-light"
src="https://github.com/user-attachments/assets/8d342f73-25e2-4dae-b984-72b88fd23287"
/> |


`#define FOO 1` and `#if defined(BAR)` look the same before and after.

Closes #66675

## Testing

- Added a query test for C and one for C++, checking that `#pragma` and
`#undef` arguments are captured as `preproc` and that a `#define` body
isn't. Both fail without the query change.
- `cargo test -p languages` passes (105 tests), and `./script/clippy -p
languages` is clean.
- Built the branch on macOS and compared it with Zed 1.28.1 on the same
file, in One Dark and One Light (screenshots above).

To try it: open a `.c` or `.cpp` file and type `#pragma pack(push, 4)` /
`#undef FOO`. The arguments should now take the directive's color.

I used Claude Code to help with this change and tested it myself.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Improved syntax highlighting of `#pragma` and `#undef` arguments in C
and C++.

---------

Co-authored-by: imryanthedev <352313849+imryanthedev@users.noreply.github.com>
2026-11-12 22:39:26 +00:00

88 lines
2.2 KiB
TOML

[package]
name = "languages"
version = "0.1.0"
edition.workspace = true
publish.workspace = true
license = "GPL-3.0-or-later"
[lints]
workspace = true
[lib]
doctest = false
[features]
test-support = [
"load-grammars"
]
load-grammars = [
"grammars/load-grammars",
"tree-sitter",
"tree-sitter-gitcommit",
]
[dependencies]
anyhow.workspace = true
async-compression.workspace = true
async-fs.workspace = true
async-tar.workspace = true
async-trait.workspace = true
chrono.workspace = true
collections.workspace = true
futures.workspace = true
github_releases.workspace = true
globset.workspace = true
gpui.workspace = true
grammars.workspace = true
itertools.workspace = true
json_schema_store.workspace = true
language.workspace = true
log.workspace = true
lsp.workspace = true
node_runtime.workspace = true
parking_lot.workspace = true
pet-conda.workspace = true
pet-core.workspace = true
pet-fs.workspace = true
pet-poetry.workspace = true
pet-reporter.workspace = true
pet-virtualenv.workspace = true
pet.workspace = true
project.workspace = true
regex.workspace = true
rope.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_json_lenient.workspace = true
settings.workspace = true
smallvec.workspace = true
semver.workspace = true
smol.workspace = true
snippet.workspace = true
task.workspace = true
terminal.workspace = true
theme.workspace = true
tree-sitter = { workspace = true, optional = true , features = ["wasm"] }
tree-sitter-gitcommit = { workspace = true, optional = true }
url.workspace = true
util.workspace = true
[dev-dependencies]
fs = { workspace = true, features = ["test-support"] }
indoc.workspace = true
language = { workspace = true, features = ["test-support"] }
pretty_assertions.workspace = true
tempfile.workspace = true
settings = { workspace = true, features = ["test-support"] }
theme = { workspace = true, features = ["test-support"] }
tree-sitter-bash.workspace = true
tree-sitter-c.workspace = true
tree-sitter-cpp.workspace = true
tree-sitter-css.workspace = true
tree-sitter-go.workspace = true
tree-sitter-python.workspace = true
tree-sitter-rust.workspace = true
tree-sitter-typescript.workspace = true
tree-sitter = { workspace = true, features = ["wasm"] }
unindent.workspace = true