Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

ep cli: Create entries from new files in edit history (#46196)

Agus Zubiaga6070b305248a
diff --git a/crates/edit_prediction/src/udiff.rs b/crates/edit_prediction/src/udiff.rs
index c11eecaaae4..d8967828ae8 100644
--- a/crates/edit_prediction/src/udiff.rs
+++ b/crates/edit_prediction/src/udiff.rs
@@ -12,7 +12,7 @@ use collections::HashMap;
use gpui::{AsyncApp, Entity};
use language::{Anchor, Buffer, OffsetRangeExt as _, TextBufferSnapshot, text_diff};
use postage::stream::Stream as _;
-use project::Project;
+use project::{Project, ProjectPath};
use util::{paths::PathStyle, rel_path::RelPath};
use worktree::Worktree;
@@ -56,14 +56,35 @@ pub async fn apply_diff(
hunk,
is_new_file,
} => {
- let project_path = project
- .update(cx, |project, cx| {
- project.find_project_path(path.as_ref(), cx)
- })?
- .context("no such path")?;
-
let buffer = match current_file {
None => {
+ if is_new_file {
+ let rel_path = RelPath::new(Path::new(path.as_ref()), PathStyle::Posix)
+ .unwrap()
+ .into_arc();
+
+ project
+ .update(cx, |project, cx| {
+ project.create_entry(
+ ProjectPath {
+ worktree_id: worktree.read(cx).id(),
+ path: rel_path,
+ },
+ false,
+ cx,
+ )
+ })?
+ .await?;
+ }
+
+ let project_path = project
+ .update(cx, |project, cx| {
+ project.find_project_path(path.as_ref(), cx)
+ })?
+ .with_context(|| {
+ format!("Failed to find project path in diff: {}", path)
+ })?;
+
let buffer = project
.update(cx, |project, cx| project.open_buffer(project_path, cx))?
.await?;