Fix stale pull diagnostics for open buffers (#46201)

John Tur created

Release Notes:

- N/A

Change summary

crates/collab/src/tests/editor_tests.rs | 17 ++++++++++-------
crates/editor/src/editor.rs             |  2 +-
2 files changed, 11 insertions(+), 8 deletions(-)

Detailed changes

crates/collab/src/tests/editor_tests.rs 🔗

@@ -3295,10 +3295,11 @@ async fn test_lsp_pull_diagnostics(
         editor.handle_input(":", window, cx);
     });
     pull_diagnostics_handle.next().await.unwrap();
+    pull_diagnostics_handle.next().await.unwrap();
     assert_eq!(
-        4,
+        5,
         diagnostics_pulls_made.load(atomic::Ordering::Acquire),
-        "Client lib.rs edits should trigger another diagnostics pull for a buffer"
+        "Client lib.rs edits should trigger another diagnostics pull for open buffers"
     );
     workspace_diagnostics_pulls_handle.next().await.unwrap();
     assert_eq!(
@@ -3314,10 +3315,11 @@ async fn test_lsp_pull_diagnostics(
     });
     pull_diagnostics_handle.next().await.unwrap();
     pull_diagnostics_handle.next().await.unwrap();
+    pull_diagnostics_handle.next().await.unwrap();
     assert_eq!(
-        6,
+        8,
         diagnostics_pulls_made.load(atomic::Ordering::Acquire),
-        "Client main.rs edits should trigger another diagnostics pull by both client and host as they share the buffer"
+        "Client main.rs edits should trigger diagnostics pull by both client and host and an extra pull for the client's lib.rs"
     );
     workspace_diagnostics_pulls_handle.next().await.unwrap();
     assert_eq!(
@@ -3333,10 +3335,11 @@ async fn test_lsp_pull_diagnostics(
     });
     pull_diagnostics_handle.next().await.unwrap();
     pull_diagnostics_handle.next().await.unwrap();
+    pull_diagnostics_handle.next().await.unwrap();
     assert_eq!(
-        8,
+        11,
         diagnostics_pulls_made.load(atomic::Ordering::Acquire),
-        "Host main.rs edits should trigger another diagnostics pull by both client and host as they share the buffer"
+        "Host main.rs edits should trigger another diagnostics pull by both client and host and another pull for the client's lib.rs"
     );
     workspace_diagnostics_pulls_handle.next().await.unwrap();
     assert_eq!(
@@ -3364,7 +3367,7 @@ async fn test_lsp_pull_diagnostics(
         .into_response()
         .expect("workspace diagnostics refresh request failed");
     assert_eq!(
-        8,
+        11,
         diagnostics_pulls_made.load(atomic::Ordering::Acquire),
         "No single file pulls should happen after the diagnostics refresh server request"
     );

crates/editor/src/editor.rs 🔗

@@ -18952,7 +18952,7 @@ impl Editor {
                 if already_used_buffers.insert(buffer_id) {
                     if let Some(worktree_id) = buffer.file().map(|f| f.worktree_id(cx)) {
                         return !edited_buffer_ids.contains(&buffer_id)
-                            && !edited_worktree_ids.contains(&worktree_id);
+                            && edited_worktree_ids.contains(&worktree_id);
                     }
                 }
                 false