Snapshot file instead of path when creating a buffer snapshot
This commit is contained in:
parent
15b13fe511
commit
eda569d6b2
5 changed files with 21 additions and 20 deletions
|
@ -126,7 +126,7 @@ impl Debug for TransformBlock {
|
||||||
Self::Custom(block) => f.debug_struct("Custom").field("block", block).finish(),
|
Self::Custom(block) => f.debug_struct("Custom").field("block", block).finish(),
|
||||||
Self::ExcerptHeader { buffer, .. } => f
|
Self::ExcerptHeader { buffer, .. } => f
|
||||||
.debug_struct("ExcerptHeader")
|
.debug_struct("ExcerptHeader")
|
||||||
.field("path", &buffer.path())
|
.field("path", &buffer.file().map(|f| f.path()))
|
||||||
.finish(),
|
.finish(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -838,7 +838,8 @@ impl EditorElement {
|
||||||
|
|
||||||
let mut filename = None;
|
let mut filename = None;
|
||||||
let mut parent_path = None;
|
let mut parent_path = None;
|
||||||
if let Some(path) = buffer.path() {
|
if let Some(file) = buffer.file() {
|
||||||
|
let path = file.path();
|
||||||
filename =
|
filename =
|
||||||
path.file_name().map(|f| f.to_string_lossy().to_string());
|
path.file_name().map(|f| f.to_string_lossy().to_string());
|
||||||
parent_path =
|
parent_path =
|
||||||
|
|
|
@ -49,7 +49,7 @@ lazy_static! {
|
||||||
|
|
||||||
pub struct Buffer {
|
pub struct Buffer {
|
||||||
text: TextBuffer,
|
text: TextBuffer,
|
||||||
file: Option<Box<dyn File>>,
|
file: Option<Arc<dyn File>>,
|
||||||
saved_version: clock::Global,
|
saved_version: clock::Global,
|
||||||
saved_mtime: SystemTime,
|
saved_mtime: SystemTime,
|
||||||
language: Option<Arc<Language>>,
|
language: Option<Arc<Language>>,
|
||||||
|
@ -72,7 +72,7 @@ pub struct Buffer {
|
||||||
pub struct BufferSnapshot {
|
pub struct BufferSnapshot {
|
||||||
text: text::BufferSnapshot,
|
text: text::BufferSnapshot,
|
||||||
tree: Option<Tree>,
|
tree: Option<Tree>,
|
||||||
path: Option<Arc<Path>>,
|
file: Option<Arc<dyn File>>,
|
||||||
diagnostics: DiagnosticSet,
|
diagnostics: DiagnosticSet,
|
||||||
diagnostics_update_count: usize,
|
diagnostics_update_count: usize,
|
||||||
file_update_count: usize,
|
file_update_count: usize,
|
||||||
|
@ -152,7 +152,7 @@ pub enum Event {
|
||||||
Closed,
|
Closed,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait File {
|
pub trait File: Send + Sync {
|
||||||
fn as_local(&self) -> Option<&dyn LocalFile>;
|
fn as_local(&self) -> Option<&dyn LocalFile>;
|
||||||
|
|
||||||
fn is_local(&self) -> bool {
|
fn is_local(&self) -> bool {
|
||||||
|
@ -306,7 +306,7 @@ impl Buffer {
|
||||||
pub fn from_file<T: Into<Arc<str>>>(
|
pub fn from_file<T: Into<Arc<str>>>(
|
||||||
replica_id: ReplicaId,
|
replica_id: ReplicaId,
|
||||||
base_text: T,
|
base_text: T,
|
||||||
file: Box<dyn File>,
|
file: Arc<dyn File>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::build(
|
Self::build(
|
||||||
|
@ -322,7 +322,7 @@ impl Buffer {
|
||||||
pub fn from_proto(
|
pub fn from_proto(
|
||||||
replica_id: ReplicaId,
|
replica_id: ReplicaId,
|
||||||
message: proto::BufferState,
|
message: proto::BufferState,
|
||||||
file: Option<Box<dyn File>>,
|
file: Option<Arc<dyn File>>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let buffer = TextBuffer::new(
|
let buffer = TextBuffer::new(
|
||||||
|
@ -403,7 +403,7 @@ impl Buffer {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(buffer: TextBuffer, file: Option<Box<dyn File>>) -> Self {
|
fn build(buffer: TextBuffer, file: Option<Arc<dyn File>>) -> Self {
|
||||||
let saved_mtime;
|
let saved_mtime;
|
||||||
if let Some(file) = file.as_ref() {
|
if let Some(file) = file.as_ref() {
|
||||||
saved_mtime = file.mtime();
|
saved_mtime = file.mtime();
|
||||||
|
@ -438,7 +438,7 @@ impl Buffer {
|
||||||
BufferSnapshot {
|
BufferSnapshot {
|
||||||
text: self.text.snapshot(),
|
text: self.text.snapshot(),
|
||||||
tree: self.syntax_tree(),
|
tree: self.syntax_tree(),
|
||||||
path: self.file.as_ref().map(|f| f.path().clone()),
|
file: self.file.clone(),
|
||||||
remote_selections: self.remote_selections.clone(),
|
remote_selections: self.remote_selections.clone(),
|
||||||
diagnostics: self.diagnostics.clone(),
|
diagnostics: self.diagnostics.clone(),
|
||||||
diagnostics_update_count: self.diagnostics_update_count,
|
diagnostics_update_count: self.diagnostics_update_count,
|
||||||
|
@ -496,7 +496,7 @@ impl Buffer {
|
||||||
&mut self,
|
&mut self,
|
||||||
version: clock::Global,
|
version: clock::Global,
|
||||||
mtime: SystemTime,
|
mtime: SystemTime,
|
||||||
new_file: Option<Box<dyn File>>,
|
new_file: Option<Arc<dyn File>>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
self.saved_mtime = mtime;
|
self.saved_mtime = mtime;
|
||||||
|
@ -550,7 +550,7 @@ impl Buffer {
|
||||||
|
|
||||||
pub fn file_updated(
|
pub fn file_updated(
|
||||||
&mut self,
|
&mut self,
|
||||||
new_file: Box<dyn File>,
|
new_file: Arc<dyn File>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<()> {
|
) -> Task<()> {
|
||||||
let old_file = if let Some(file) = self.file.as_ref() {
|
let old_file = if let Some(file) = self.file.as_ref() {
|
||||||
|
@ -1980,8 +1980,8 @@ impl BufferSnapshot {
|
||||||
self.selections_update_count
|
self.selections_update_count
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn path(&self) -> Option<&Arc<Path>> {
|
pub fn file(&self) -> Option<&Arc<dyn File>> {
|
||||||
self.path.as_ref()
|
self.file.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_update_count(&self) -> usize {
|
pub fn file_update_count(&self) -> usize {
|
||||||
|
@ -1994,7 +1994,7 @@ impl Clone for BufferSnapshot {
|
||||||
Self {
|
Self {
|
||||||
text: self.text.clone(),
|
text: self.text.clone(),
|
||||||
tree: self.tree.clone(),
|
tree: self.tree.clone(),
|
||||||
path: self.path.clone(),
|
file: self.file.clone(),
|
||||||
remote_selections: self.remote_selections.clone(),
|
remote_selections: self.remote_selections.clone(),
|
||||||
diagnostics: self.diagnostics.clone(),
|
diagnostics: self.diagnostics.clone(),
|
||||||
selections_update_count: self.selections_update_count,
|
selections_update_count: self.selections_update_count,
|
||||||
|
|
|
@ -4013,7 +4013,7 @@ impl Project {
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
}
|
}
|
||||||
buffer.file_updated(Box::new(new_file), cx).detach();
|
buffer.file_updated(Arc::new(new_file), cx).detach();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -4565,7 +4565,7 @@ impl Project {
|
||||||
.and_then(|b| b.upgrade(cx))
|
.and_then(|b| b.upgrade(cx))
|
||||||
.ok_or_else(|| anyhow!("no such buffer"))?;
|
.ok_or_else(|| anyhow!("no such buffer"))?;
|
||||||
buffer.update(cx, |buffer, cx| {
|
buffer.update(cx, |buffer, cx| {
|
||||||
buffer.file_updated(Box::new(file), cx).detach();
|
buffer.file_updated(Arc::new(file), cx).detach();
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
@ -5089,8 +5089,8 @@ impl Project {
|
||||||
anyhow!("no worktree found for id {}", file.worktree_id)
|
anyhow!("no worktree found for id {}", file.worktree_id)
|
||||||
})?;
|
})?;
|
||||||
buffer_file =
|
buffer_file =
|
||||||
Some(Box::new(File::from_proto(file, worktree.clone(), cx)?)
|
Some(Arc::new(File::from_proto(file, worktree.clone(), cx)?)
|
||||||
as Box<dyn language::File>);
|
as Arc<dyn language::File>);
|
||||||
buffer_worktree = Some(worktree);
|
buffer_worktree = Some(worktree);
|
||||||
Ok::<_, anyhow::Error>(())
|
Ok::<_, anyhow::Error>(())
|
||||||
})?;
|
})?;
|
||||||
|
|
|
@ -519,7 +519,7 @@ impl LocalWorktree {
|
||||||
let (file, contents) = this
|
let (file, contents) = this
|
||||||
.update(&mut cx, |t, cx| t.as_local().unwrap().load(&path, cx))
|
.update(&mut cx, |t, cx| t.as_local().unwrap().load(&path, cx))
|
||||||
.await?;
|
.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_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(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue