Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix jump capture (#58430)
Ben Kunkle971453678286
diff --git a/crates/cloud_api_types/src/cloud_api_types.rs b/crates/cloud_api_types/src/cloud_api_types.rsindex e5a67e68ef8..2c9c46b0793 100644--- a/crates/cloud_api_types/src/cloud_api_types.rs+++ b/crates/cloud_api_types/src/cloud_api_types.rs@@ -155,6 +155,8 @@ pub struct SubmitEditPredictionJumpExampleBody {pub trigger: JumpExampleTrigger,pub repository_url: Option<String>,pub revision: Option<String>,+ /// Note: this is only the uncommitted diff for files in `edit_history`+ /// This is done to avoid excessive memory usagepub uncommitted_diff: Option<String>,pub recently_opened_files: Vec<JumpExampleRecentFile>,pub recently_viewed_files: Vec<JumpExampleRecentFile>,diff --git a/crates/edit_prediction/src/capture_example.rs b/crates/edit_prediction/src/capture_example.rsindex 1f5ccf8ed5d..4f6e0f34b30 100644--- a/crates/edit_prediction/src/capture_example.rs+++ b/crates/edit_prediction/src/capture_example.rs@@ -354,12 +354,17 @@ mod tests {);let worktree_id = buffer.read_with(cx, |buffer, cx| buffer.file().unwrap().worktree_id(cx));- let failed_capture = ep_store+ let unfiltered_uncommitted_diffs = ep_store.update(cx, |_store, cx| {uncommitted_diffs_for_events(project.clone(), worktree_id, events.clone(), cx)})- .await;- assert!(failed_capture.is_err());+ .await+ .unwrap();+ assert!(+ unfiltered_uncommitted_diffs+ .iter()+ .all(|(path, _, _)| path.as_ref() != Path::new("external.rs"))+ );let project_events = events.into_iter()diff --git a/crates/edit_prediction/src/data_collection.rs b/crates/edit_prediction/src/data_collection.rsindex 26e8a77a7f3..b56609a9d96 100644--- a/crates/edit_prediction/src/data_collection.rs+++ b/crates/edit_prediction/src/data_collection.rs@@ -1,13 +1,14 @@use crate::{EditPredictionStore, StoredEvent};-use anyhow::{Context as _, Result};+use anyhow::Context as _;use buffer_diff::BufferDiffSnapshot;use collections::HashMap;use gpui::{Context, Entity, Task};use language::BufferSnapshot;-use project::{Project, WorktreeId};+use project::{Project, ProjectPath, WorktreeId};use std::{fmt::Write as _, ops::Range, path::Path, sync::Arc};use text::{OffsetRangeExt, Point};+use util::rel_path::RelPath;pub type UncommittedDiffSnapshot = Vec<(Arc<Path>, BufferSnapshot, BufferDiffSnapshot)>;pub type UncommittedDiffResult = std::result::Result<UncommittedDiffSnapshot, Arc<anyhow::Error>>;@@ -23,25 +24,34 @@ pub fn uncommitted_diffs_for_events(let git_store = project.read_with(cx, |project, _| project.git_store().clone());cx.spawn(async move |_store, cx| {+ let (worktree_root_name, worktree_abs_path, path_style) = project+ .read_with(cx, |project, cx| {+ let worktree = project.worktree_for_id(worktree_id, cx)?;+ let worktree = worktree.read(cx);+ let path_style = worktree.path_style();+ let root_name = RelPath::new(Path::new(worktree.root_name_str()), path_style)+ .ok()?+ .into_owned();+ Some((root_name, worktree.abs_path(), path_style))+ })+ .context("failed to find worktree for uncommitted diff capture")+ .map_err(Arc::new)?;+let events_with_paths = events.into_iter()- .map(|stored_event| {+ .filter_map(|stored_event| {let zeta_prompt::Event::BufferChange { path, .. } = stored_event.event.as_ref();- project- .read_with(cx, |project, cx| {- let project_path = project- .find_project_path(path, cx)- .filter(|path| path.worktree_id == worktree_id)?;- let relative_path: Arc<Path> = project_path.path.as_std_path().into();- Some((project_path, relative_path))- })- .map(|(project_path, relative_path)| {- (stored_event, project_path, relative_path)- })- .context("failed to find project path for uncommitted diff capture")+ let path = if let Ok(path) = RelPath::new(path, path_style) {+ path.strip_prefix(&worktree_root_name).ok()?.into_arc()+ } else {+ let path = path.strip_prefix(worktree_abs_path.as_ref()).ok()?;+ RelPath::new(path, path_style).ok()?.into_arc()+ };+ let project_path = ProjectPath { worktree_id, path };+ let relative_path: Arc<Path> = project_path.path.as_std_path().into();+ Some((stored_event, project_path, relative_path))})- .collect::<Result<Vec<_>>>()- .map_err(Arc::new)?;+ .collect::<Vec<_>>();let mut snapshots_by_path: HashMap<Arc<Path>, (BufferSnapshot, BufferDiffSnapshot)> =HashMap::default();diff --git a/crates/edit_prediction/src/edit_prediction.rs b/crates/edit_prediction/src/edit_prediction.rsindex 483916a15ea..f76cece98a1 100644--- a/crates/edit_prediction/src/edit_prediction.rs+++ b/crates/edit_prediction/src/edit_prediction.rs@@ -1275,6 +1275,7 @@ impl EditPredictionStore {file_context.git_changed_file_sets = result.context("failed to receive git changed file sets").flatten()+ .log_with_level(log::Level::Trace).map(|mut file_sets| file_sets.pop().unwrap_or_default()).context("failed to load git changed file sets").map(Arc::new)