diff --git a/crates/edit_prediction/src/edit_prediction.rs b/crates/edit_prediction/src/edit_prediction.rs index 406fd51bac5679429805f07dec6d7b288668bf15..5813cd40e9bc32463c172f3ad8bfef9299be0d49 100644 --- a/crates/edit_prediction/src/edit_prediction.rs +++ b/crates/edit_prediction/src/edit_prediction.rs @@ -2097,6 +2097,17 @@ impl EditPredictionStore { }); } + #[cfg(feature = "cli-support")] + pub fn set_recent_paths_for_project( + &mut self, + project: &Entity, + paths: impl IntoIterator, + cx: &mut Context, + ) { + let project_state = self.get_or_init_project(project, cx); + project_state.recent_paths = paths.into_iter().collect(); + } + fn is_file_open_source( &self, project: &Entity, diff --git a/crates/edit_prediction/src/udiff.rs b/crates/edit_prediction/src/udiff.rs index 2582c67615a7633c5a2aef494203a1c3618f7e76..a9cb4fea7713f4347011455ac9c4bf2fe77b06fa 100644 --- a/crates/edit_prediction/src/udiff.rs +++ b/crates/edit_prediction/src/udiff.rs @@ -23,6 +23,10 @@ impl OpenedBuffers { pub fn get(&self, path: &str) -> Option<&Entity> { self.0.get(path) } + + pub fn buffers(&self) -> impl Iterator> { + self.0.values() + } } #[must_use] diff --git a/crates/edit_prediction_cli/src/load_project.rs b/crates/edit_prediction_cli/src/load_project.rs index 7afbb871ff3957c3c70d64093b30e2dcea661b78..7dfaad47e1e6564912a1ed81c258c737cb06f4f1 100644 --- a/crates/edit_prediction_cli/src/load_project.rs +++ b/crates/edit_prediction_cli/src/load_project.rs @@ -12,8 +12,7 @@ use edit_prediction::{ use futures::AsyncWriteExt as _; use gpui::{AsyncApp, Entity}; use language::{Anchor, Buffer, LanguageNotFound, ToOffset, ToPoint}; -use project::Project; -use project::buffer_store::BufferStoreEvent; +use project::{Project, ProjectPath, buffer_store::BufferStoreEvent}; use std::{fs, path::PathBuf, sync::Arc}; pub async fn run_load_project( @@ -32,6 +31,25 @@ pub async fn run_load_project( progress.set_substatus("applying edit history"); let open_buffers = apply_edit_history(example, &project, &mut cx).await?; + let ep_store = cx + .update(|cx| EditPredictionStore::try_global(cx)) + .context("EditPredictionStore not initialized")?; + + let recent_paths: Vec = open_buffers + .buffers() + .filter_map(|buffer| { + buffer.read_with(&cx, |buffer, cx| { + buffer + .file() + .map(|file| ProjectPath::from_file(file.as_ref(), cx)) + }) + }) + .collect(); + + ep_store.update(&mut cx, |store, cx| { + store.set_recent_paths_for_project(&project, recent_paths, cx); + }); + progress.set_substatus("resolving cursor"); let (buffer, cursor_position) = cursor_position(example, &project, &open_buffers, &mut cx).await?; @@ -39,10 +57,6 @@ pub async fn run_load_project( .read_with(&cx, |buffer, _| buffer.parsing_idle()) .await; - let ep_store = cx - .update(|cx| EditPredictionStore::try_global(cx)) - .context("EditPredictionStore not initialized")?; - let edit_history = ep_store.update(&mut cx, |store, cx| { store .edit_history_for_project(&project, cx)