# Diff LSP format responses that replace the whole buffer \(\#57269\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 5d5963361f3080539f2d7034e92736167c53a04a

Requested commit: 5d5963361f3080539f2d7034e92736167c53a04a

Commit: 5d5963361f3080539f2d7034e92736167c53a04a

Tree: 51ecabc350c8c4fd2fd370c0eaf1965f2bfbf755

Author: kmdw

Committer: GitHub

## Message

```
Diff LSP format responses that replace the whole buffer (#57269)

#29120:
https://github.com/zed-industries/zed/issues/29120#issuecomment-2819789736

On format, some language servers, rather than responding with ranges to
change, just send a response to replace the entire buffer. This PR makes
it so that when this happens, it first diffs the buffer with the new
text to replace ranges instead.

This fixes a bug where formatting would select the whole document and
scroll all the way to the bottom.

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 is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #29120, closes #41184

Release Notes:

- Fixed language server formatting scrolling to the bottom when the
server replaces the entire buffer.

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
Co-authored-by: Amp <amp@ampcode.com>
```

## Parents

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

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