From 3e454059d47000a13c9958a69be00371458fa0ae Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 22 Dec 2025 15:46:20 -0800 Subject: [PATCH] Allow example name to be specified in markdown --- crates/edit_prediction/src/example_spec.rs | 7 +++++-- crates/edit_prediction_cli/src/example.rs | 10 +++++++--- crates/edit_prediction_cli/src/load_project.rs | 3 +-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/edit_prediction/src/example_spec.rs b/crates/edit_prediction/src/example_spec.rs index 2b76d4dda1a22f07a7ea402c84e76ea31529d14d..47e8390691ae36bde751b8bba67ade52db0d7315 100644 --- a/crates/edit_prediction/src/example_spec.rs +++ b/crates/edit_prediction/src/example_spec.rs @@ -104,11 +104,11 @@ impl ExampleSpec { } /// Parse an example spec from markdown. - pub fn from_markdown(name: String, mut input: &str) -> anyhow::Result { + pub fn from_markdown(mut input: &str) -> anyhow::Result { use pulldown_cmark::{CodeBlockKind, CowStr, Event, HeadingLevel, Parser, Tag, TagEnd}; let mut spec = ExampleSpec { - name, + name: String::new(), repository_url: String::new(), revision: String::new(), uncommitted_diff: String::new(), @@ -150,6 +150,9 @@ impl ExampleSpec { Event::Text(line) => { text.push_str(&line); } + Event::End(TagEnd::Heading(HeadingLevel::H1)) => { + spec.name = mem::take(&mut text); + } Event::End(TagEnd::Heading(HeadingLevel::H2)) => { let title = mem::take(&mut text); current_section = if title.eq_ignore_ascii_case(UNCOMMITTED_DIFF_HEADING) { diff --git a/crates/edit_prediction_cli/src/example.rs b/crates/edit_prediction_cli/src/example.rs index e37619bf224b3fa506516714856cfbc5024ece14..ef3bbd95508da0fef7e5a56c431805d93ab1a8cc 100644 --- a/crates/edit_prediction_cli/src/example.rs +++ b/crates/edit_prediction_cli/src/example.rs @@ -190,7 +190,11 @@ pub fn read_examples(inputs: &[PathBuf]) -> Vec { .collect::>(), ), "md" => { - examples.push(parse_markdown_example(filename, &content).unwrap()); + let mut example = parse_markdown_example(&content).unwrap(); + if example.spec.name.is_empty() { + example.spec.name = filename; + } + examples.push(example); } ext => { panic!("{} has invalid example extension `{ext}`", path.display()) @@ -236,8 +240,8 @@ pub fn group_examples_by_repo(examples: &mut [Example]) -> Vec examples_by_repo.into_values().collect() } -fn parse_markdown_example(name: String, input: &str) -> Result { - let spec = ExampleSpec::from_markdown(name, input)?; +fn parse_markdown_example(input: &str) -> Result { + let spec = ExampleSpec::from_markdown(input)?; Ok(Example { spec, buffer: None, diff --git a/crates/edit_prediction_cli/src/load_project.rs b/crates/edit_prediction_cli/src/load_project.rs index 29b2ba351771fba4a346d47208a760d027d8ead5..b2b289b249ad8707ff49e92cb780f93d428844af 100644 --- a/crates/edit_prediction_cli/src/load_project.rs +++ b/crates/edit_prediction_cli/src/load_project.rs @@ -14,15 +14,14 @@ use futures::{ }; use gpui::{AsyncApp, Entity}; use language::{Anchor, Buffer, LanguageNotFound, ToOffset, ToPoint}; +use project::Project; use project::buffer_store::BufferStoreEvent; -use project::{Project, ProjectPath}; use std::{ cell::RefCell, fs, path::{Path, PathBuf}, sync::Arc, }; -use util::{paths::PathStyle, rel_path::RelPath}; use zeta_prompt::CURSOR_MARKER; pub async fn run_load_project(