Deserialize buffer's diagnostics

Max Brunsfeld and Nathan Sobo created

Co-Authored-By: Nathan Sobo <nathan@zed.dev>

Change summary

crates/language/src/lib.rs     | 8 +++++++-
crates/project/src/worktree.rs | 2 +-
script/sqlx                    | 2 +-
3 files changed, 9 insertions(+), 3 deletions(-)

Detailed changes

crates/language/src/lib.rs 🔗

@@ -256,6 +256,7 @@ impl Buffer {
         replica_id: ReplicaId,
         message: proto::Buffer,
         file: Option<Box<dyn File>>,
+        cx: &mut ModelContext<Self>,
     ) -> Result<Self> {
         let mut buffer =
             buffer::Buffer::new(replica_id, message.id, History::new(message.content.into()));
@@ -268,7 +269,11 @@ impl Buffer {
             let set = proto::deserialize_selection_set(set);
             buffer.add_raw_selection_set(set.id, set);
         }
-        Ok(Self::build(buffer, file))
+        let mut this = Self::build(buffer, file);
+        if let Some(diagnostics) = message.diagnostics {
+            this.apply_diagnostic_update(proto::deserialize_diagnostics(diagnostics), cx);
+        }
+        Ok(this)
     }
 
     pub fn to_proto(&self) -> proto::Buffer {
@@ -1351,6 +1356,7 @@ impl Buffer {
         cx: &mut ModelContext<Self>,
     ) {
         self.diagnostics = diagnostics;
+        self.diagnostics_update_count += 1;
         cx.notify();
     }
 

crates/project/src/worktree.rs 🔗

@@ -1391,7 +1391,7 @@ impl RemoteWorktree {
                 let remote_buffer = response.buffer.ok_or_else(|| anyhow!("empty buffer"))?;
                 let buffer_id = remote_buffer.id as usize;
                 let buffer = cx.add_model(|cx| {
-                    Buffer::from_proto(replica_id, remote_buffer, Some(Box::new(file)))
+                    Buffer::from_proto(replica_id, remote_buffer, Some(Box::new(file)), cx)
                         .unwrap()
                         .with_language(language, None, cx)
                 });

script/sqlx 🔗

@@ -5,7 +5,7 @@ set -e
 # Install sqlx-cli if needed
 [[ "$(sqlx --version)" == "sqlx-cli 0.5.7" ]] || cargo install sqlx-cli --version 0.5.7
 
-cd server
+cd crates/server
 
 # Export contents of .env.toml
 eval "$(cargo run --bin dotenv)"