Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
edit_prediction: Normalize prompt paths to Unix style (#61792)
Ben Kunkle6dcb0e57b5a6
diff --git a/crates/edit_prediction/src/edit_prediction.rs b/crates/edit_prediction/src/edit_prediction.rsindex 965d8bc2699..850851dc694 100644--- a/crates/edit_prediction/src/edit_prediction.rs+++ b/crates/edit_prediction/src/edit_prediction.rs@@ -70,7 +70,7 @@ use std::sync::Arc;use std::time::{Duration, Instant};use thiserror::Error;-use util::ResultExt as _;+use util::{ResultExt as _, rel_path::RelPath};pub mod cursor_excerpt;pub mod data_collection;@@ -904,11 +904,14 @@ pub(crate) fn buffer_path_with_id_fallback(snapshot: &TextBufferSnapshot,cx: &App,) -> Arc<Path> {- if let Some(file) = file {- file.full_path(cx).into()- } else {- Path::new(&format!("untitled-{}", snapshot.remote_id())).into()- }+ let Some(file) = file else {+ return Path::new(&format!("untitled-{}", snapshot.remote_id())).into();+ };+ let full_path = file.full_path(cx);+ let Some(path) = RelPath::new(&full_path, file.path_style(cx)).ok() else {+ return Path::new(&format!("untitled-{}", snapshot.remote_id())).into();+ };+ path.as_std_path().into()}fn predict_edits_request_trigger_from_editor_trigger(diff --git a/crates/edit_prediction/src/edit_prediction_tests.rs b/crates/edit_prediction/src/edit_prediction_tests.rsindex dd8b866a6b1..eb0851ffb22 100644--- a/crates/edit_prediction/src/edit_prediction_tests.rs+++ b/crates/edit_prediction/src/edit_prediction_tests.rs@@ -4127,13 +4127,22 @@ async fn test_edit_prediction_settled_drops_future_events_when_their_oss_status_}#[gpui::test]-fn test_buffer_path_with_id_fallback_for_untitled_buffers(cx: &mut TestAppContext) {+fn test_buffer_path_with_id_fallback(cx: &mut TestAppContext) {let buffer_1 = cx.new(|cx| Buffer::local("one", cx));let buffer_2 = cx.new(|cx| Buffer::local("two", cx));let snapshot_1 = buffer_1.read_with(cx, |buffer, _| buffer.text_snapshot());let snapshot_2 = buffer_2.read_with(cx, |buffer, _| buffer.text_snapshot());+ let windows_file: Arc<dyn language::File> = Arc::new(language::TestFile {+ path: util::rel_path::rel_path("src/main.rs").into(),+ root_name: "workspace".into(),+ local_root: None,+ });+ let windows_path =+ cx.read(|cx| buffer_path_with_id_fallback(Some(&windows_file), &snapshot_1, cx));+ assert_eq!(windows_path.to_string_lossy(), "workspace/src/main.rs");+let path_1 = cx.read(|cx| buffer_path_with_id_fallback(None, &snapshot_1, cx));let path_2 = cx.read(|cx| buffer_path_with_id_fallback(None, &snapshot_2, cx));