diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index 013ef305b3..43b28974a9 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -126,7 +126,7 @@ impl Debug for TransformBlock { Self::Custom(block) => f.debug_struct("Custom").field("block", block).finish(), Self::ExcerptHeader { buffer, .. } => f .debug_struct("ExcerptHeader") - .field("path", &buffer.path()) + .field("path", &buffer.file().map(|f| f.path())) .finish(), } } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 594c047d5b..f3ecc6e773 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -838,7 +838,8 @@ impl EditorElement { let mut filename = None; let mut parent_path = None; - if let Some(path) = buffer.path() { + if let Some(file) = buffer.file() { + let path = file.path(); filename = path.file_name().map(|f| f.to_string_lossy().to_string()); parent_path = diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 38dbaa29fd..de7425b76b 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -49,7 +49,7 @@ lazy_static! { pub struct Buffer { text: TextBuffer, - file: Option>, + file: Option>, saved_version: clock::Global, saved_mtime: SystemTime, language: Option>, @@ -72,7 +72,7 @@ pub struct Buffer { pub struct BufferSnapshot { text: text::BufferSnapshot, tree: Option, - path: Option>, + file: Option>, diagnostics: DiagnosticSet, diagnostics_update_count: usize, file_update_count: usize, @@ -152,7 +152,7 @@ pub enum Event { Closed, } -pub trait File { +pub trait File: Send + Sync { fn as_local(&self) -> Option<&dyn LocalFile>; fn is_local(&self) -> bool { @@ -306,7 +306,7 @@ impl Buffer { pub fn from_file>>( replica_id: ReplicaId, base_text: T, - file: Box, + file: Arc, cx: &mut ModelContext, ) -> Self { Self::build( @@ -322,7 +322,7 @@ impl Buffer { pub fn from_proto( replica_id: ReplicaId, message: proto::BufferState, - file: Option>, + file: Option>, cx: &mut ModelContext, ) -> Result { let buffer = TextBuffer::new( @@ -403,7 +403,7 @@ impl Buffer { self } - fn build(buffer: TextBuffer, file: Option>) -> Self { + fn build(buffer: TextBuffer, file: Option>) -> Self { let saved_mtime; if let Some(file) = file.as_ref() { saved_mtime = file.mtime(); @@ -438,7 +438,7 @@ impl Buffer { BufferSnapshot { text: self.text.snapshot(), tree: self.syntax_tree(), - path: self.file.as_ref().map(|f| f.path().clone()), + file: self.file.clone(), remote_selections: self.remote_selections.clone(), diagnostics: self.diagnostics.clone(), diagnostics_update_count: self.diagnostics_update_count, @@ -496,7 +496,7 @@ impl Buffer { &mut self, version: clock::Global, mtime: SystemTime, - new_file: Option>, + new_file: Option>, cx: &mut ModelContext, ) { self.saved_mtime = mtime; @@ -550,7 +550,7 @@ impl Buffer { pub fn file_updated( &mut self, - new_file: Box, + new_file: Arc, cx: &mut ModelContext, ) -> Task<()> { let old_file = if let Some(file) = self.file.as_ref() { @@ -1980,8 +1980,8 @@ impl BufferSnapshot { self.selections_update_count } - pub fn path(&self) -> Option<&Arc> { - self.path.as_ref() + pub fn file(&self) -> Option<&Arc> { + self.file.as_ref() } pub fn file_update_count(&self) -> usize { @@ -1994,7 +1994,7 @@ impl Clone for BufferSnapshot { Self { text: self.text.clone(), tree: self.tree.clone(), - path: self.path.clone(), + file: self.file.clone(), remote_selections: self.remote_selections.clone(), diagnostics: self.diagnostics.clone(), selections_update_count: self.selections_update_count, diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index c502b1eccc..63a77f2642 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -4013,7 +4013,7 @@ impl Project { }) .log_err(); } - buffer.file_updated(Box::new(new_file), cx).detach(); + buffer.file_updated(Arc::new(new_file), cx).detach(); } }); } else { @@ -4565,7 +4565,7 @@ impl Project { .and_then(|b| b.upgrade(cx)) .ok_or_else(|| anyhow!("no such buffer"))?; buffer.update(cx, |buffer, cx| { - buffer.file_updated(Box::new(file), cx).detach(); + buffer.file_updated(Arc::new(file), cx).detach(); }); Ok(()) }) @@ -5089,8 +5089,8 @@ impl Project { anyhow!("no worktree found for id {}", file.worktree_id) })?; buffer_file = - Some(Box::new(File::from_proto(file, worktree.clone(), cx)?) - as Box); + Some(Arc::new(File::from_proto(file, worktree.clone(), cx)?) + as Arc); buffer_worktree = Some(worktree); Ok::<_, anyhow::Error>(()) })?; diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 599d6f0a2a..1007b43d75 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -519,7 +519,7 @@ impl LocalWorktree { let (file, contents) = this .update(&mut cx, |t, cx| t.as_local().unwrap().load(&path, cx)) .await?; - Ok(cx.add_model(|cx| Buffer::from_file(0, contents, Box::new(file), cx))) + Ok(cx.add_model(|cx| Buffer::from_file(0, contents, Arc::new(file), cx))) }) } @@ -648,7 +648,7 @@ impl LocalWorktree { }; buffer_handle.update(&mut cx, |buffer, cx| { - buffer.did_save(version, file.mtime, Some(Box::new(file)), cx); + buffer.did_save(version, file.mtime, Some(Arc::new(file)), cx); }); Ok(())