Merge pull request #358 from zed-industries/move-buffers-to-project
Move buffers to project
This commit is contained in:
@@ -725,7 +725,6 @@ mod tests {
|
||||
use gpui::TestAppContext;
|
||||
use language::{Diagnostic, DiagnosticEntry, DiagnosticSeverity, PointUtf16};
|
||||
use serde_json::json;
|
||||
use std::sync::Arc;
|
||||
use unindent::Unindent as _;
|
||||
use workspace::WorkspaceParams;
|
||||
|
||||
@@ -764,21 +763,18 @@ mod tests {
|
||||
)
|
||||
.await;
|
||||
|
||||
let (worktree, _) = project
|
||||
project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path("/test", false, cx)
|
||||
project.find_or_create_local_worktree("/test", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let worktree_id = worktree.read_with(&cx, |tree, _| tree.id());
|
||||
|
||||
// Create some diagnostics
|
||||
worktree.update(&mut cx, |worktree, cx| {
|
||||
worktree
|
||||
.as_local_mut()
|
||||
.unwrap()
|
||||
project.update(&mut cx, |project, cx| {
|
||||
project
|
||||
.update_diagnostic_entries(
|
||||
Arc::from("/test/main.rs".as_ref()),
|
||||
PathBuf::from("/test/main.rs"),
|
||||
None,
|
||||
vec![
|
||||
DiagnosticEntry {
|
||||
@@ -926,12 +922,11 @@ mod tests {
|
||||
});
|
||||
|
||||
// Diagnostics are added for another earlier path.
|
||||
worktree.update(&mut cx, |worktree, cx| {
|
||||
worktree
|
||||
.as_local_mut()
|
||||
.unwrap()
|
||||
project.update(&mut cx, |project, cx| {
|
||||
project.disk_based_diagnostics_started(cx);
|
||||
project
|
||||
.update_diagnostic_entries(
|
||||
Arc::from("/test/consts.rs".as_ref()),
|
||||
PathBuf::from("/test/consts.rs"),
|
||||
None,
|
||||
vec![DiagnosticEntry {
|
||||
range: PointUtf16::new(0, 15)..PointUtf16::new(0, 15),
|
||||
@@ -947,13 +942,7 @@ mod tests {
|
||||
cx,
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
project.update(&mut cx, |_, cx| {
|
||||
cx.emit(project::Event::DiagnosticsUpdated(ProjectPath {
|
||||
worktree_id,
|
||||
path: Arc::from("/test/consts.rs".as_ref()),
|
||||
}));
|
||||
cx.emit(project::Event::DiskBasedDiagnosticsFinished);
|
||||
project.disk_based_diagnostics_finished(cx);
|
||||
});
|
||||
|
||||
view.next_notification(&cx).await;
|
||||
@@ -1032,12 +1021,11 @@ mod tests {
|
||||
});
|
||||
|
||||
// Diagnostics are added to the first path
|
||||
worktree.update(&mut cx, |worktree, cx| {
|
||||
worktree
|
||||
.as_local_mut()
|
||||
.unwrap()
|
||||
project.update(&mut cx, |project, cx| {
|
||||
project.disk_based_diagnostics_started(cx);
|
||||
project
|
||||
.update_diagnostic_entries(
|
||||
Arc::from("/test/consts.rs".as_ref()),
|
||||
PathBuf::from("/test/consts.rs"),
|
||||
None,
|
||||
vec![
|
||||
DiagnosticEntry {
|
||||
@@ -1067,13 +1055,7 @@ mod tests {
|
||||
cx,
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
project.update(&mut cx, |_, cx| {
|
||||
cx.emit(project::Event::DiagnosticsUpdated(ProjectPath {
|
||||
worktree_id,
|
||||
path: Arc::from("/test/consts.rs".as_ref()),
|
||||
}));
|
||||
cx.emit(project::Event::DiskBasedDiagnosticsFinished);
|
||||
project.disk_based_diagnostics_finished(cx);
|
||||
});
|
||||
|
||||
view.next_notification(&cx).await;
|
||||
|
||||
@@ -457,7 +457,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(Path::new("/root"), false, cx)
|
||||
project.find_or_create_local_worktree("/root", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -518,7 +518,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(Path::new("/dir"), false, cx)
|
||||
project.find_or_create_local_worktree("/dir", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -584,11 +584,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(
|
||||
Path::new("/root/the-parent-dir/the-file"),
|
||||
false,
|
||||
cx,
|
||||
)
|
||||
project.find_or_create_local_worktree("/root/the-parent-dir/the-file", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -1653,8 +1653,13 @@ impl MutableAppContext {
|
||||
Fut: 'static + Future<Output = T>,
|
||||
T: 'static,
|
||||
{
|
||||
let future = f(self.to_async());
|
||||
let cx = self.to_async();
|
||||
self.foreground.spawn(f(cx))
|
||||
self.foreground.spawn(async move {
|
||||
let result = future.await;
|
||||
cx.0.borrow_mut().flush_effects();
|
||||
result
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_async(&self) -> AsyncAppContext {
|
||||
|
||||
@@ -856,7 +856,7 @@ impl Buffer {
|
||||
version: Option<i32>,
|
||||
mut diagnostics: Vec<DiagnosticEntry<T>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<Operation>
|
||||
) -> Result<()>
|
||||
where
|
||||
T: Copy + Ord + TextDimension + Sub<Output = T> + Clip + ToPoint,
|
||||
{
|
||||
@@ -869,19 +869,19 @@ impl Buffer {
|
||||
}
|
||||
|
||||
let version = version.map(|version| version as usize);
|
||||
let content = if let Some(version) = version {
|
||||
let language_server = self.language_server.as_mut().unwrap();
|
||||
language_server
|
||||
.pending_snapshots
|
||||
.retain(|&v, _| v >= version);
|
||||
let snapshot = language_server
|
||||
.pending_snapshots
|
||||
.get(&version)
|
||||
.ok_or_else(|| anyhow!("missing snapshot"))?;
|
||||
&snapshot.buffer_snapshot
|
||||
} else {
|
||||
self.deref()
|
||||
};
|
||||
let content =
|
||||
if let Some((version, language_server)) = version.zip(self.language_server.as_mut()) {
|
||||
language_server
|
||||
.pending_snapshots
|
||||
.retain(|&v, _| v >= version);
|
||||
let snapshot = language_server
|
||||
.pending_snapshots
|
||||
.get(&version)
|
||||
.ok_or_else(|| anyhow!("missing snapshot"))?;
|
||||
&snapshot.buffer_snapshot
|
||||
} else {
|
||||
self.deref()
|
||||
};
|
||||
|
||||
diagnostics.sort_unstable_by(|a, b| {
|
||||
Ordering::Equal
|
||||
@@ -944,10 +944,13 @@ impl Buffer {
|
||||
|
||||
let set = DiagnosticSet::new(sanitized_diagnostics, content);
|
||||
self.apply_diagnostic_update(set.clone(), cx);
|
||||
Ok(Operation::UpdateDiagnostics {
|
||||
|
||||
let op = Operation::UpdateDiagnostics {
|
||||
diagnostics: set.iter().cloned().collect(),
|
||||
lamport_timestamp: self.text.lamport_clock.tick(),
|
||||
})
|
||||
};
|
||||
self.send_operation(op, cx);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn request_autoindent(&mut self, cx: &mut ModelContext<Self>) {
|
||||
|
||||
+1311
-153
File diff suppressed because it is too large
Load Diff
+199
-1697
File diff suppressed because it is too large
Load Diff
@@ -644,7 +644,7 @@ mod tests {
|
||||
});
|
||||
let (root1, _) = project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path("/root1", false, cx)
|
||||
project.find_or_create_local_worktree("/root1", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -653,7 +653,7 @@ mod tests {
|
||||
.await;
|
||||
let (root2, _) = project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path("/root2", false, cx)
|
||||
project.find_or_create_local_worktree("/root2", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -144,35 +144,30 @@ message OpenBufferResponse {
|
||||
|
||||
message CloseBuffer {
|
||||
uint64 project_id = 1;
|
||||
uint64 worktree_id = 2;
|
||||
uint64 buffer_id = 3;
|
||||
uint64 buffer_id = 2;
|
||||
}
|
||||
|
||||
message UpdateBuffer {
|
||||
uint64 project_id = 1;
|
||||
uint64 worktree_id = 2;
|
||||
uint64 buffer_id = 3;
|
||||
uint64 buffer_id = 2;
|
||||
repeated Operation operations = 4;
|
||||
}
|
||||
|
||||
message SaveBuffer {
|
||||
uint64 project_id = 1;
|
||||
uint64 worktree_id = 2;
|
||||
uint64 buffer_id = 3;
|
||||
uint64 buffer_id = 2;
|
||||
}
|
||||
|
||||
message BufferSaved {
|
||||
uint64 project_id = 1;
|
||||
uint64 worktree_id = 2;
|
||||
uint64 buffer_id = 3;
|
||||
repeated VectorClockEntry version = 4;
|
||||
Timestamp mtime = 5;
|
||||
uint64 buffer_id = 2;
|
||||
repeated VectorClockEntry version = 3;
|
||||
Timestamp mtime = 4;
|
||||
}
|
||||
|
||||
message FormatBuffer {
|
||||
uint64 project_id = 1;
|
||||
uint64 worktree_id = 2;
|
||||
uint64 buffer_id = 3;
|
||||
uint64 buffer_id = 2;
|
||||
}
|
||||
|
||||
message UpdateDiagnosticSummary {
|
||||
|
||||
+80
-97
@@ -1162,18 +1162,17 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/a", false, cx)
|
||||
p.find_or_create_local_worktree("/a", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
|
||||
worktree_a
|
||||
.read_with(&cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
|
||||
.await;
|
||||
let project_id = project_a
|
||||
.update(&mut cx_a, |project, _| project.next_remote_id())
|
||||
.await;
|
||||
let project_id = project_a.update(&mut cx_a, |p, _| p.next_remote_id()).await;
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.share(cx))
|
||||
.update(&mut cx_a, |p, cx| p.share(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -1188,7 +1187,6 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let worktree_b = project_b.update(&mut cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
|
||||
let replica_id_b = project_b.read_with(&cx_b, |project, _| {
|
||||
assert_eq!(
|
||||
@@ -1214,25 +1212,26 @@ mod tests {
|
||||
.await;
|
||||
|
||||
// Open the same file as client B and client A.
|
||||
let buffer_b = worktree_b
|
||||
.update(&mut cx_b, |worktree, cx| worktree.open_buffer("b.txt", cx))
|
||||
let buffer_b = project_b
|
||||
.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "b.txt"), cx))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
.unwrap();
|
||||
let buffer_b = cx_b.add_model(|cx| MultiBuffer::singleton(buffer_b, cx));
|
||||
buffer_b.read_with(&cx_b, |buf, cx| {
|
||||
assert_eq!(buf.read(cx).text(), "b-contents")
|
||||
});
|
||||
worktree_a.read_with(&cx_a, |tree, cx| assert!(tree.has_open_buffer("b.txt", cx)));
|
||||
let buffer_a = worktree_a
|
||||
.update(&mut cx_a, |tree, cx| tree.open_buffer("b.txt", cx))
|
||||
project_a.read_with(&cx_a, |project, cx| {
|
||||
assert!(project.has_open_buffer((worktree_id, "b.txt"), cx))
|
||||
});
|
||||
let buffer_a = project_a
|
||||
.update(&mut cx_a, |p, cx| p.open_buffer((worktree_id, "b.txt"), cx))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
.unwrap();
|
||||
|
||||
let editor_b = cx_b.add_view(window_b, |cx| {
|
||||
Editor::for_buffer(buffer_b, Arc::new(|cx| EditorSettings::test(cx)), cx)
|
||||
});
|
||||
|
||||
// TODO
|
||||
// // Create a selection set as client B and see that selection set as client A.
|
||||
// buffer_a
|
||||
@@ -1256,8 +1255,10 @@ mod tests {
|
||||
|
||||
// Close the buffer as client A, see that the buffer is closed.
|
||||
cx_a.update(move |_| drop(buffer_a));
|
||||
worktree_a
|
||||
.condition(&cx_a, |tree, cx| !tree.has_open_buffer("b.txt", cx))
|
||||
project_a
|
||||
.condition(&cx_a, |project, cx| {
|
||||
!project.has_open_buffer((worktree_id, "b.txt"), cx)
|
||||
})
|
||||
.await;
|
||||
|
||||
// Dropping the client B's project removes client B from client A's collaborators.
|
||||
@@ -1299,18 +1300,17 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/a", false, cx)
|
||||
p.find_or_create_local_worktree("/a", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
worktree_a
|
||||
.read_with(&cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
|
||||
.await;
|
||||
let project_id = project_a
|
||||
.update(&mut cx_a, |project, _| project.next_remote_id())
|
||||
.await;
|
||||
let project_id = project_a.update(&mut cx_a, |p, _| p.next_remote_id()).await;
|
||||
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.share(cx))
|
||||
.update(&mut cx_a, |p, cx| p.share(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(worktree_a.read_with(&cx_a, |tree, _| tree.as_local().unwrap().is_shared()));
|
||||
@@ -1326,13 +1326,12 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let worktree_b = project_b.read_with(&cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
worktree_b
|
||||
.update(&mut cx_b, |tree, cx| tree.open_buffer("a.txt", cx))
|
||||
project_b
|
||||
.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Unshare the project as client A
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.unshare(cx))
|
||||
.await
|
||||
@@ -1349,6 +1348,7 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(worktree_a.read_with(&cx_a, |tree, _| tree.as_local().unwrap().is_shared()));
|
||||
|
||||
let project_c = Project::remote(
|
||||
project_id,
|
||||
client_b.clone(),
|
||||
@@ -1359,9 +1359,8 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let worktree_c = project_c.read_with(&cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
worktree_c
|
||||
.update(&mut cx_b, |tree, cx| tree.open_buffer("a.txt", cx))
|
||||
project_c
|
||||
.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
@@ -1403,18 +1402,17 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/a", false, cx)
|
||||
p.find_or_create_local_worktree("/a", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
worktree_a
|
||||
.read_with(&cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
|
||||
.await;
|
||||
let project_id = project_a
|
||||
.update(&mut cx_a, |project, _| project.next_remote_id())
|
||||
.await;
|
||||
let project_id = project_a.update(&mut cx_a, |p, _| p.next_remote_id()).await;
|
||||
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.share(cx))
|
||||
.update(&mut cx_a, |p, cx| p.share(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -1439,29 +1437,26 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Open and edit a buffer as both guests B and C.
|
||||
let worktree_b = project_b.read_with(&cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
let worktree_c = project_c.read_with(&cx_c, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
let buffer_b = worktree_b
|
||||
.update(&mut cx_b, |tree, cx| tree.open_buffer("file1", cx))
|
||||
|
||||
// Open and edit a buffer as both guests B and C.
|
||||
let buffer_b = project_b
|
||||
.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
let buffer_c = worktree_c
|
||||
.update(&mut cx_c, |tree, cx| tree.open_buffer("file1", cx))
|
||||
.unwrap();
|
||||
let buffer_c = project_c
|
||||
.update(&mut cx_c, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
.unwrap();
|
||||
buffer_b.update(&mut cx_b, |buf, cx| buf.edit([0..0], "i-am-b, ", cx));
|
||||
buffer_c.update(&mut cx_c, |buf, cx| buf.edit([0..0], "i-am-c, ", cx));
|
||||
|
||||
// Open and edit that buffer as the host.
|
||||
let buffer_a = worktree_a
|
||||
.update(&mut cx_a, |tree, cx| tree.open_buffer("file1", cx))
|
||||
let buffer_a = project_a
|
||||
.update(&mut cx_a, |p, cx| p.open_buffer((worktree_id, "file1"), cx))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
.unwrap();
|
||||
|
||||
buffer_a
|
||||
.condition(&mut cx_a, |buf, _| buf.text() == "i-am-c, i-am-b, ")
|
||||
@@ -1475,7 +1470,9 @@ mod tests {
|
||||
.condition(&mut cx_a, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a")
|
||||
.await;
|
||||
buffer_b
|
||||
.condition(&mut cx_b, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a")
|
||||
.condition(&mut cx_b, |buf, _| {
|
||||
dbg!(buf.text()) == "i-am-c, i-am-b, i-am-a"
|
||||
})
|
||||
.await;
|
||||
buffer_c
|
||||
.condition(&mut cx_c, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a")
|
||||
@@ -1557,18 +1554,17 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/dir", false, cx)
|
||||
p.find_or_create_local_worktree("/dir", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
worktree_a
|
||||
.read_with(&cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
|
||||
.await;
|
||||
let project_id = project_a
|
||||
.update(&mut cx_a, |project, _| project.next_remote_id())
|
||||
.await;
|
||||
let project_id = project_a.update(&mut cx_a, |p, _| p.next_remote_id()).await;
|
||||
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.share(cx))
|
||||
.update(&mut cx_a, |p, cx| p.share(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -1586,11 +1582,10 @@ mod tests {
|
||||
let worktree_b = project_b.update(&mut cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
|
||||
// Open a buffer as client B
|
||||
let buffer_b = worktree_b
|
||||
.update(&mut cx_b, |worktree, cx| worktree.open_buffer("a.txt", cx))
|
||||
let buffer_b = project_b
|
||||
.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
.unwrap();
|
||||
let mtime = buffer_b.read_with(&cx_b, |buf, _| buf.file().unwrap().mtime());
|
||||
|
||||
buffer_b.update(&mut cx_b, |buf, cx| buf.edit([0..0], "world ", cx));
|
||||
@@ -1654,18 +1649,17 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/dir", false, cx)
|
||||
p.find_or_create_local_worktree("/dir", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
worktree_a
|
||||
.read_with(&cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
|
||||
.await;
|
||||
let project_id = project_a
|
||||
.update(&mut cx_a, |project, _| project.next_remote_id())
|
||||
.await;
|
||||
let project_id = project_a.update(&mut cx_a, |p, _| p.next_remote_id()).await;
|
||||
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.share(cx))
|
||||
.update(&mut cx_a, |p, cx| p.share(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -1680,26 +1674,24 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let worktree_b = project_b.update(&mut cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
|
||||
// Open a buffer as client A
|
||||
let buffer_a = worktree_a
|
||||
.update(&mut cx_a, |tree, cx| tree.open_buffer("a.txt", cx))
|
||||
let buffer_a = project_a
|
||||
.update(&mut cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
.unwrap();
|
||||
|
||||
// Start opening the same buffer as client B
|
||||
let buffer_b = cx_b
|
||||
.background()
|
||||
.spawn(worktree_b.update(&mut cx_b, |worktree, cx| worktree.open_buffer("a.txt", cx)));
|
||||
.spawn(project_b.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx)));
|
||||
task::yield_now().await;
|
||||
|
||||
// Edit the buffer as client A while client B is still opening it.
|
||||
buffer_a.update(&mut cx_a, |buf, cx| buf.edit([0..0], "z", cx));
|
||||
|
||||
let text = buffer_a.read_with(&cx_a, |buf, _| buf.text());
|
||||
let buffer_b = buffer_b.await.unwrap().0;
|
||||
let buffer_b = buffer_b.await.unwrap();
|
||||
buffer_b.condition(&cx_b, |buf, _| buf.text() == text).await;
|
||||
}
|
||||
|
||||
@@ -1737,18 +1729,17 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/dir", false, cx)
|
||||
p.find_or_create_local_worktree("/dir", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
worktree_a
|
||||
.read_with(&cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
|
||||
.await;
|
||||
let project_id = project_a
|
||||
.update(&mut cx_a, |project, _| project.next_remote_id())
|
||||
.await;
|
||||
let project_id = project_a.update(&mut cx_a, |p, _| p.next_remote_id()).await;
|
||||
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.share(cx))
|
||||
.update(&mut cx_a, |p, cx| p.share(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -1763,7 +1754,6 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let worktree_b = project_b.update(&mut cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
|
||||
// See that a guest has joined as client A.
|
||||
project_a
|
||||
@@ -1773,7 +1763,7 @@ mod tests {
|
||||
// Begin opening a buffer as client B, but leave the project before the open completes.
|
||||
let buffer_b = cx_b
|
||||
.background()
|
||||
.spawn(worktree_b.update(&mut cx_b, |worktree, cx| worktree.open_buffer("a.txt", cx)));
|
||||
.spawn(project_b.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx)));
|
||||
cx_b.update(|_| drop(project_b));
|
||||
drop(buffer_b);
|
||||
|
||||
@@ -1815,7 +1805,7 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/a", false, cx)
|
||||
p.find_or_create_local_worktree("/a", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -1904,19 +1894,17 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/a", false, cx)
|
||||
p.find_or_create_local_worktree("/a", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
worktree_a
|
||||
.read_with(&cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
|
||||
.await;
|
||||
let project_id = project_a
|
||||
.update(&mut cx_a, |project, _| project.next_remote_id())
|
||||
.await;
|
||||
let project_id = project_a.update(&mut cx_a, |p, _| p.next_remote_id()).await;
|
||||
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.share(cx))
|
||||
.update(&mut cx_a, |p, cx| p.share(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -2041,13 +2029,11 @@ mod tests {
|
||||
.await;
|
||||
|
||||
// Open the file with the errors on client B. They should be present.
|
||||
let worktree_b = project_b.update(&mut cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
let buffer_b = cx_b
|
||||
.background()
|
||||
.spawn(worktree_b.update(&mut cx_b, |worktree, cx| worktree.open_buffer("a.rs", cx)))
|
||||
.spawn(project_b.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
.unwrap();
|
||||
|
||||
buffer_b.read_with(&cx_b, |buffer, _| {
|
||||
assert_eq!(
|
||||
@@ -2128,18 +2114,17 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/a", false, cx)
|
||||
p.find_or_create_local_worktree("/a", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
worktree_a
|
||||
.read_with(&cx_a, |tree, _| tree.as_local().unwrap().scan_complete())
|
||||
.await;
|
||||
let project_id = project_a
|
||||
.update(&mut cx_a, |project, _| project.next_remote_id())
|
||||
.await;
|
||||
let project_id = project_a.update(&mut cx_a, |p, _| p.next_remote_id()).await;
|
||||
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
|
||||
project_a
|
||||
.update(&mut cx_a, |project, cx| project.share(cx))
|
||||
.update(&mut cx_a, |p, cx| p.share(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -2156,13 +2141,11 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
// Open the file to be formatted on client B.
|
||||
let worktree_b = project_b.update(&mut cx_b, |p, cx| p.worktrees(cx).next().unwrap());
|
||||
let buffer_b = cx_b
|
||||
.background()
|
||||
.spawn(worktree_b.update(&mut cx_b, |worktree, cx| worktree.open_buffer("a.rs", cx)))
|
||||
.spawn(project_b.update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.rs"), cx)))
|
||||
.await
|
||||
.unwrap()
|
||||
.0;
|
||||
.unwrap();
|
||||
|
||||
let format = buffer_b.update(&mut cx_b, |buffer, cx| buffer.format(cx));
|
||||
let (request_id, _) = fake_language_server
|
||||
@@ -2638,7 +2621,7 @@ mod tests {
|
||||
});
|
||||
let (worktree_a, _) = project_a
|
||||
.update(&mut cx_a, |p, cx| {
|
||||
p.find_or_create_worktree_for_abs_path("/a", false, cx)
|
||||
p.find_or_create_local_worktree("/a", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -723,7 +723,7 @@ impl Workspace {
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<ProjectPath>> {
|
||||
let entry = self.project().update(cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(abs_path, false, cx)
|
||||
project.find_or_create_local_worktree(abs_path, false, cx)
|
||||
});
|
||||
cx.spawn(|_, cx| async move {
|
||||
let (worktree, path) = entry.await?;
|
||||
|
||||
@@ -245,7 +245,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(Path::new("/root"), false, cx)
|
||||
project.find_or_create_local_worktree("/root", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -358,7 +358,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(Path::new("/dir1"), false, cx)
|
||||
project.find_or_create_local_worktree("/dir1", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -425,7 +425,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(Path::new("/root"), false, cx)
|
||||
project.find_or_create_local_worktree("/root", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -474,7 +474,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(Path::new("/root"), false, cx)
|
||||
project.find_or_create_local_worktree("/root", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -626,7 +626,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(Path::new("/root"), false, cx)
|
||||
project.find_or_create_local_worktree("/root", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -689,7 +689,7 @@ mod tests {
|
||||
params
|
||||
.project
|
||||
.update(&mut cx, |project, cx| {
|
||||
project.find_or_create_worktree_for_abs_path(Path::new("/root"), false, cx)
|
||||
project.find_or_create_local_worktree("/root", false, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user