diff --git a/crates/cloud_api_types/src/cloud_api_types.rs b/crates/cloud_api_types/src/cloud_api_types.rs index e5a67e68ef..2c9c46b079 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, pub revision: Option, + /// Note: this is only the uncommitted diff for files in `edit_history` + /// This is done to avoid excessive memory usage pub uncommitted_diff: Option, pub recently_opened_files: Vec, pub recently_viewed_files: Vec, diff --git a/crates/edit_prediction/src/capture_example.rs b/crates/edit_prediction/src/capture_example.rs index 1f5ccf8ed5..4f6e0f34b3 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.rs index 26e8a77a7f..b56609a9d9 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, BufferSnapshot, BufferDiffSnapshot)>; pub type UncommittedDiffResult = std::result::Result>; @@ -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 = 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 = project_path.path.as_std_path().into(); + Some((stored_event, project_path, relative_path)) }) - .collect::>>() - .map_err(Arc::new)?; + .collect::>(); let mut snapshots_by_path: HashMap, (BufferSnapshot, BufferDiffSnapshot)> = HashMap::default(); diff --git a/crates/edit_prediction/src/edit_prediction.rs b/crates/edit_prediction/src/edit_prediction.rs index 483916a15e..f76cece98a 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)