mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Added absolute path info to remote worktrees (updated protocol version)
This commit is contained in:
parent
1789dfb8b1
commit
5bb2edca8b
@ -8,7 +8,7 @@ use collections::{BTreeMap, HashSet};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use gpui::{AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task};
|
use gpui::{AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use std::sync::Arc;
|
use std::{os::unix::prelude::OsStrExt, sync::Arc};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
@ -389,6 +389,7 @@ impl Room {
|
|||||||
id: worktree.id().to_proto(),
|
id: worktree.id().to_proto(),
|
||||||
root_name: worktree.root_name().into(),
|
root_name: worktree.root_name().into(),
|
||||||
visible: worktree.is_visible(),
|
visible: worktree.is_visible(),
|
||||||
|
abs_path: worktree.abs_path().as_os_str().as_bytes().to_vec(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -3038,7 +3038,7 @@ async fn test_references(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
|
|||||||
assert_eq!(references[1].buffer, references[0].buffer);
|
assert_eq!(references[1].buffer, references[0].buffer);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
three_buffer.file().unwrap().full_path(cx),
|
three_buffer.file().unwrap().full_path(cx),
|
||||||
Path::new("/OUTSIDE_PROJECT/three.rs")
|
Path::new("/root/dir-2/three.rs")
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(references[0].range.to_offset(two_buffer), 24..27);
|
assert_eq!(references[0].range.to_offset(two_buffer), 24..27);
|
||||||
|
@ -42,6 +42,7 @@ use std::{
|
|||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
|
os::unix::prelude::OsStrExt,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering::SeqCst},
|
atomic::{AtomicBool, Ordering::SeqCst},
|
||||||
@ -941,6 +942,7 @@ impl Server {
|
|||||||
id: *id,
|
id: *id,
|
||||||
root_name: worktree.root_name.clone(),
|
root_name: worktree.root_name.clone(),
|
||||||
visible: worktree.visible,
|
visible: worktree.visible,
|
||||||
|
abs_path: worktree.abs_path.as_os_str().as_bytes().to_vec(),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@ -989,6 +991,7 @@ impl Server {
|
|||||||
let message = proto::UpdateWorktree {
|
let message = proto::UpdateWorktree {
|
||||||
project_id: project_id.to_proto(),
|
project_id: project_id.to_proto(),
|
||||||
worktree_id: *worktree_id,
|
worktree_id: *worktree_id,
|
||||||
|
abs_path: worktree.abs_path.as_os_str().as_bytes().to_vec(),
|
||||||
root_name: worktree.root_name.clone(),
|
root_name: worktree.root_name.clone(),
|
||||||
updated_entries: worktree.entries.values().cloned().collect(),
|
updated_entries: worktree.entries.values().cloned().collect(),
|
||||||
removed_entries: Default::default(),
|
removed_entries: Default::default(),
|
||||||
|
@ -66,6 +66,7 @@ pub struct Collaborator {
|
|||||||
|
|
||||||
#[derive(Default, Serialize)]
|
#[derive(Default, Serialize)]
|
||||||
pub struct Worktree {
|
pub struct Worktree {
|
||||||
|
pub abs_path: PathBuf,
|
||||||
pub root_name: String,
|
pub root_name: String,
|
||||||
pub visible: bool,
|
pub visible: bool,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
|
@ -2164,6 +2164,7 @@ async fn test_rescan_and_remote_updates(
|
|||||||
proto::WorktreeMetadata {
|
proto::WorktreeMetadata {
|
||||||
id: initial_snapshot.id().to_proto(),
|
id: initial_snapshot.id().to_proto(),
|
||||||
root_name: initial_snapshot.root_name().into(),
|
root_name: initial_snapshot.root_name().into(),
|
||||||
|
abs_path: initial_snapshot.abs_path().as_os_str().as_bytes().to_vec(),
|
||||||
visible: true,
|
visible: true,
|
||||||
},
|
},
|
||||||
rpc.clone(),
|
rpc.clone(),
|
||||||
|
@ -87,6 +87,7 @@ pub struct RemoteWorktree {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Snapshot {
|
pub struct Snapshot {
|
||||||
id: WorktreeId,
|
id: WorktreeId,
|
||||||
|
abs_path: Arc<Path>,
|
||||||
root_name: String,
|
root_name: String,
|
||||||
root_char_bag: CharBag,
|
root_char_bag: CharBag,
|
||||||
entries_by_path: SumTree<Entry>,
|
entries_by_path: SumTree<Entry>,
|
||||||
@ -118,7 +119,6 @@ impl std::fmt::Debug for GitRepositoryEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct LocalSnapshot {
|
pub struct LocalSnapshot {
|
||||||
abs_path: Arc<Path>,
|
|
||||||
ignores_by_parent_abs_path: HashMap<Arc<Path>, (Arc<Gitignore>, usize)>,
|
ignores_by_parent_abs_path: HashMap<Arc<Path>, (Arc<Gitignore>, usize)>,
|
||||||
git_repositories: Vec<GitRepositoryEntry>,
|
git_repositories: Vec<GitRepositoryEntry>,
|
||||||
removed_entry_ids: HashMap<u64, ProjectEntryId>,
|
removed_entry_ids: HashMap<u64, ProjectEntryId>,
|
||||||
@ -130,7 +130,6 @@ pub struct LocalSnapshot {
|
|||||||
impl Clone for LocalSnapshot {
|
impl Clone for LocalSnapshot {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
abs_path: self.abs_path.clone(),
|
|
||||||
ignores_by_parent_abs_path: self.ignores_by_parent_abs_path.clone(),
|
ignores_by_parent_abs_path: self.ignores_by_parent_abs_path.clone(),
|
||||||
git_repositories: self.git_repositories.iter().cloned().collect(),
|
git_repositories: self.git_repositories.iter().cloned().collect(),
|
||||||
removed_entry_ids: self.removed_entry_ids.clone(),
|
removed_entry_ids: self.removed_entry_ids.clone(),
|
||||||
@ -221,8 +220,11 @@ impl Worktree {
|
|||||||
.collect();
|
.collect();
|
||||||
let root_name = worktree.root_name.clone();
|
let root_name = worktree.root_name.clone();
|
||||||
let visible = worktree.visible;
|
let visible = worktree.visible;
|
||||||
|
|
||||||
|
let abs_path = PathBuf::from(OsString::from_vec(worktree.abs_path));
|
||||||
let snapshot = Snapshot {
|
let snapshot = Snapshot {
|
||||||
id: WorktreeId(remote_id as usize),
|
id: WorktreeId(remote_id as usize),
|
||||||
|
abs_path: Arc::from(abs_path.deref()),
|
||||||
root_name,
|
root_name,
|
||||||
root_char_bag,
|
root_char_bag,
|
||||||
entries_by_path: Default::default(),
|
entries_by_path: Default::default(),
|
||||||
@ -372,6 +374,13 @@ impl Worktree {
|
|||||||
Self::Remote(worktree) => worktree.poll_snapshot(cx),
|
Self::Remote(worktree) => worktree.poll_snapshot(cx),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn abs_path(&self) -> Arc<Path> {
|
||||||
|
match self {
|
||||||
|
Worktree::Local(worktree) => worktree.abs_path.clone(),
|
||||||
|
Worktree::Remote(worktree) => worktree.abs_path.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LocalWorktree {
|
impl LocalWorktree {
|
||||||
@ -402,13 +411,13 @@ impl LocalWorktree {
|
|||||||
watch::channel_with(ScanState::Initializing);
|
watch::channel_with(ScanState::Initializing);
|
||||||
let tree = cx.add_model(move |cx: &mut ModelContext<Worktree>| {
|
let tree = cx.add_model(move |cx: &mut ModelContext<Worktree>| {
|
||||||
let mut snapshot = LocalSnapshot {
|
let mut snapshot = LocalSnapshot {
|
||||||
abs_path,
|
|
||||||
ignores_by_parent_abs_path: Default::default(),
|
ignores_by_parent_abs_path: Default::default(),
|
||||||
git_repositories: Default::default(),
|
git_repositories: Default::default(),
|
||||||
removed_entry_ids: Default::default(),
|
removed_entry_ids: Default::default(),
|
||||||
next_entry_id,
|
next_entry_id,
|
||||||
snapshot: Snapshot {
|
snapshot: Snapshot {
|
||||||
id: WorktreeId::from_usize(cx.model_id()),
|
id: WorktreeId::from_usize(cx.model_id()),
|
||||||
|
abs_path,
|
||||||
root_name: root_name.clone(),
|
root_name: root_name.clone(),
|
||||||
root_char_bag,
|
root_char_bag,
|
||||||
entries_by_path: Default::default(),
|
entries_by_path: Default::default(),
|
||||||
@ -647,6 +656,7 @@ impl LocalWorktree {
|
|||||||
id: self.id().to_proto(),
|
id: self.id().to_proto(),
|
||||||
root_name: self.root_name().to_string(),
|
root_name: self.root_name().to_string(),
|
||||||
visible: self.visible,
|
visible: self.visible,
|
||||||
|
abs_path: self.abs_path().as_os_str().as_bytes().to_vec(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -980,6 +990,7 @@ impl LocalWorktree {
|
|||||||
let update = proto::UpdateWorktree {
|
let update = proto::UpdateWorktree {
|
||||||
project_id,
|
project_id,
|
||||||
worktree_id,
|
worktree_id,
|
||||||
|
abs_path: snapshot.abs_path().as_os_str().as_bytes().to_vec(),
|
||||||
root_name: snapshot.root_name().to_string(),
|
root_name: snapshot.root_name().to_string(),
|
||||||
updated_entries: snapshot
|
updated_entries: snapshot
|
||||||
.entries_by_path
|
.entries_by_path
|
||||||
@ -1389,6 +1400,7 @@ impl LocalSnapshot {
|
|||||||
proto::UpdateWorktree {
|
proto::UpdateWorktree {
|
||||||
project_id,
|
project_id,
|
||||||
worktree_id: self.id().to_proto(),
|
worktree_id: self.id().to_proto(),
|
||||||
|
abs_path: self.abs_path().as_os_str().as_bytes().to_vec(),
|
||||||
root_name,
|
root_name,
|
||||||
updated_entries: self.entries_by_path.iter().map(Into::into).collect(),
|
updated_entries: self.entries_by_path.iter().map(Into::into).collect(),
|
||||||
removed_entries: Default::default(),
|
removed_entries: Default::default(),
|
||||||
@ -1456,6 +1468,7 @@ impl LocalSnapshot {
|
|||||||
proto::UpdateWorktree {
|
proto::UpdateWorktree {
|
||||||
project_id,
|
project_id,
|
||||||
worktree_id,
|
worktree_id,
|
||||||
|
abs_path: self.abs_path().as_os_str().as_bytes().to_vec(),
|
||||||
root_name: self.root_name().to_string(),
|
root_name: self.root_name().to_string(),
|
||||||
updated_entries,
|
updated_entries,
|
||||||
removed_entries,
|
removed_entries,
|
||||||
@ -1844,16 +1857,13 @@ impl language::File for File {
|
|||||||
if worktree.is_visible() {
|
if worktree.is_visible() {
|
||||||
full_path.push(worktree.root_name());
|
full_path.push(worktree.root_name());
|
||||||
} else {
|
} else {
|
||||||
if let Some(path) = worktree.as_local().map(|local| local.abs_path.clone()) {
|
let path = worktree.abs_path();
|
||||||
if let Ok(trimmed_path) = path.strip_prefix(cx.global::<HomeDir>().as_path()) {
|
|
||||||
full_path.push("~");
|
if worktree.is_local() && path.starts_with(cx.global::<HomeDir>().as_path()) {
|
||||||
full_path.push(trimmed_path);
|
full_path.push("~");
|
||||||
} else {
|
full_path.push(path.strip_prefix(cx.global::<HomeDir>().as_path()).unwrap());
|
||||||
full_path.push(path)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
full_path.push(Path::new("/OUTSIDE_PROJECT"));
|
full_path.push(path)
|
||||||
full_path.push(worktree.root_name());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3473,7 +3483,6 @@ mod tests {
|
|||||||
let fs = Arc::new(RealFs);
|
let fs = Arc::new(RealFs);
|
||||||
let next_entry_id = Arc::new(AtomicUsize::new(0));
|
let next_entry_id = Arc::new(AtomicUsize::new(0));
|
||||||
let mut initial_snapshot = LocalSnapshot {
|
let mut initial_snapshot = LocalSnapshot {
|
||||||
abs_path: root_dir.path().into(),
|
|
||||||
removed_entry_ids: Default::default(),
|
removed_entry_ids: Default::default(),
|
||||||
ignores_by_parent_abs_path: Default::default(),
|
ignores_by_parent_abs_path: Default::default(),
|
||||||
git_repositories: Default::default(),
|
git_repositories: Default::default(),
|
||||||
@ -3482,6 +3491,7 @@ mod tests {
|
|||||||
id: WorktreeId::from_usize(0),
|
id: WorktreeId::from_usize(0),
|
||||||
entries_by_path: Default::default(),
|
entries_by_path: Default::default(),
|
||||||
entries_by_id: Default::default(),
|
entries_by_id: Default::default(),
|
||||||
|
abs_path: root_dir.path().into(),
|
||||||
root_name: Default::default(),
|
root_name: Default::default(),
|
||||||
root_char_bag: Default::default(),
|
root_char_bag: Default::default(),
|
||||||
scan_id: 0,
|
scan_id: 0,
|
||||||
|
@ -266,6 +266,7 @@ message UpdateWorktree {
|
|||||||
repeated uint64 removed_entries = 5;
|
repeated uint64 removed_entries = 5;
|
||||||
uint64 scan_id = 6;
|
uint64 scan_id = 6;
|
||||||
bool is_last_update = 7;
|
bool is_last_update = 7;
|
||||||
|
bytes abs_path = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateWorktreeExtensions {
|
message UpdateWorktreeExtensions {
|
||||||
@ -1052,6 +1053,7 @@ message WorktreeMetadata {
|
|||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
string root_name = 2;
|
string root_name = 2;
|
||||||
bool visible = 3;
|
bool visible = 3;
|
||||||
|
bytes abs_path = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateDiffBase {
|
message UpdateDiffBase {
|
||||||
|
@ -435,6 +435,7 @@ pub fn split_worktree_update(
|
|||||||
project_id: message.project_id,
|
project_id: message.project_id,
|
||||||
worktree_id: message.worktree_id,
|
worktree_id: message.worktree_id,
|
||||||
root_name: message.root_name.clone(),
|
root_name: message.root_name.clone(),
|
||||||
|
abs_path: message.abs_path.clone(),
|
||||||
updated_entries,
|
updated_entries,
|
||||||
removed_entries: mem::take(&mut message.removed_entries),
|
removed_entries: mem::take(&mut message.removed_entries),
|
||||||
scan_id: message.scan_id,
|
scan_id: message.scan_id,
|
||||||
|
@ -6,4 +6,4 @@ pub use conn::Connection;
|
|||||||
pub use peer::*;
|
pub use peer::*;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
pub const PROTOCOL_VERSION: u32 = 35;
|
pub const PROTOCOL_VERSION: u32 = 37;
|
||||||
|
Loading…
Reference in New Issue
Block a user