Avoid reloading file when reversing its unsaved changes due to a

Max Brunsfeld created

format-on-save

Change summary

crates/project/src/lsp_store.rs | 5 +++++
crates/project/src/project.rs   | 4 +++-
2 files changed, 8 insertions(+), 1 deletion(-)

Detailed changes

crates/project/src/lsp_store.rs 🔗

@@ -4184,6 +4184,11 @@ impl LspStore {
         }
     }
 
+    pub fn is_buffer_being_formatted(&self, buffer_id: BufferId) -> bool {
+        self.as_local()
+            .is_some_and(|local| local.buffers_being_formatted.contains(&buffer_id))
+    }
+
     pub fn as_local_mut(&mut self) -> Option<&mut LocalLspStore> {
         match &mut self.mode {
             LspStoreMode::Local(local_lsp_store) => Some(local_lsp_store),

crates/project/src/project.rs 🔗

@@ -3694,7 +3694,9 @@ impl Project {
         let buffer_id = buffer.read(cx).remote_id();
         match event {
             BufferEvent::ReloadNeeded => {
-                if !self.is_via_collab() {
+                if !self.is_via_collab()
+                    && !self.lsp_store.read(cx).is_buffer_being_formatted(buffer_id)
+                {
                     self.reload_buffers([buffer.clone()].into_iter().collect(), true, cx)
                         .detach_and_log_err(cx);
                 }