# Indent statements under C/C\+\+ case labels \(\#60758\) · gitcafe/zed

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

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

Visibility: public

Requested revision: aeeacf5439b2d30d01e38d65d767e6f31b255ecc

Requested commit: aeeacf5439b2d30d01e38d65d767e6f31b255ecc

Commit: aeeacf5439b2d30d01e38d65d767e6f31b255ecc

Tree: 46e9e0a8ad8f20cb964b3f995f986b4f61084791

Author: Apoorva Verma

Committer: GitHub

## Message

```
Indent statements under C/C++ case labels (#60758)

# Objective

Fixes #60261

Nothing under a `case` gets indented in C or C++, and the next `case`
doesn't come back out. It stays flat until you hit `editor: format`.

## Solution

The indent queries had no rule for case labels. Added the same pair
`cpp/indents.scm` uses for `access_specifier`: open an indent range at
the label, close it at the switch's `}`, outdent on the next label.

The part that got me: `@start` uses the *end* of the node you capture.
Fine for `access_specifier`, which is just `public:`. But a
`case_statement` swallows the statements under it, so capturing the node
starts the range after the last one. Capture the `:` instead. `default:`
is a `case_statement` too, so it comes along free.

Only affects what happens after a label, so existing `case` alignment
doesn't move.

## Testing

`test_c_autoindent_switch_case` and `test_cpp_autoindent_switch_case`
cover a plain case, fall-through labels and `default`. Both fail on
main. The `access_specifier` tests still pass.

Not mine, but worth knowing: `typescript::tests::test_outline` and
`test_generator_function_outline` are flaky on main, failing about half
my full `cargo test -p languages --lib` runs with or without this
change.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed statements under a `case` label not being indented in C and C++
([#60261](https://github.com/zed-industries/zed/issues/60261)).
```

## Parents

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

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