# Fix race condition between auto-indent and on-type-formatting \(\#32005\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 36eebb7ba8d5799f08dcf9bd624895b50275a2c2

Requested commit: 36eebb7ba8d5799f08dcf9bd624895b50275a2c2

Commit: 36eebb7ba8d5799f08dcf9bd624895b50275a2c2

Tree: 1c0711b473cf1dcbeb33bfc88c14b207a88b17e0

Author: Maxim

Committer: GitHub

## Message

```
Fix race condition between auto-indent and on-type-formatting (#32005)

This PR addresses to fix (#31308) a race condition where auto-indent (in
buffer.cs) and on-type-formatting (in lsp_store.rs) concurrently
calculate indentation using the same buffer snapshot.

Previous Solution (Abandoned): 
https://github.com/zed-industries/zed/pull/31340

Final Solution:
Delay applying on-type-formatting until auto-indent is complete.

Issue:

If AutoindentMode finishes first, formatting works correctly. If
"Formatting on typing" starts before AutoindentMode completes, it
results in double indentation.

Closes #31308

Release Notes:

- Fixed a race condition resulting in incorrect buffer contents when combining auto-indent and on-type-formatting
```

## Parents

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

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