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
This commit is contained in:
Maxim 2025-06-24 00:59:06 +03:00 committed by GitHub
parent d34d4f2ef1
commit 36eebb7ba8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 97 additions and 14 deletions

View file

@ -1593,7 +1593,7 @@ impl FakeLanguageServer {
T: 'static + request::Request,
T::Params: 'static + Send,
F: 'static + Send + FnMut(T::Params, gpui::AsyncApp) -> Fut,
Fut: 'static + Send + Future<Output = Result<T::Result>>,
Fut: 'static + Future<Output = Result<T::Result>>,
{
let (responded_tx, responded_rx) = futures::channel::mpsc::unbounded();
self.server.remove_request_handler::<T>();