Fix jump capture (#58430)

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A or Added/Fixed/Improved ...

---------

Co-authored-by: Oleksiy <oleksiy@zed.dev>
This commit is contained in:
Ben KunkleandOleksiy authored and GitHub committed 2026-06-03 15:50:50 +00:00
1 parent 0e559e5519
commit 0bc571b903
4 files changed
+38 -20

No files matched your search

@@ -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 usage
pub uncommitted_diff: Option<String>,
pub recently_opened_files: Vec<JumpExampleRecentFile>,
pub recently_viewed_files: Vec<JumpExampleRecentFile>,
@@ -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()
+27 -17
View File
@@ -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();
@@ -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)