diff --git a/crates/zeta_cli/src/main.rs b/crates/zeta_cli/src/main.rs index d72a0f5cf7cf00166a2bbaa60c1700d1007fc8af..a9c8b5998cdd32a94a71f1894dfbdc40c22abaed 100644 --- a/crates/zeta_cli/src/main.rs +++ b/crates/zeta_cli/src/main.rs @@ -26,6 +26,7 @@ use edit_prediction_context::{ }; use gpui::{Application, AsyncApp, Entity, prelude::*}; use language::{Bias, Buffer, BufferSnapshot, Point}; +use metrics::delta_chr_f; use project::{Project, Worktree}; use reqwest_client::ReqwestClient; use serde_json::json; @@ -33,6 +34,7 @@ use std::io::{self}; use std::time::Duration; use std::{collections::HashSet, path::PathBuf, str::FromStr, sync::Arc}; use zeta::ContextMode; +use zeta::udiff::DiffLine; #[derive(Parser, Debug)] #[command(name = "zeta")] @@ -54,6 +56,10 @@ enum Command { #[arg(long, value_enum, default_value_t = ExampleFormat::Md)] output_format: ExampleFormat, }, + Score { + golden_patch: PathBuf, + actual_patch: PathBuf, + }, Clean, } @@ -522,6 +528,26 @@ fn main() { let example = NamedExample::load(path).unwrap(); example.write(output_format, io::stdout()).unwrap(); } + Some(Command::Score { + golden_patch, + actual_patch, + }) => { + let golden_content = std::fs::read_to_string(golden_patch).unwrap(); + let actual_content = std::fs::read_to_string(actual_patch).unwrap(); + + let golden_diff: Vec = golden_content + .lines() + .map(|line| DiffLine::parse(line)) + .collect(); + + let actual_diff: Vec = actual_content + .lines() + .map(|line| DiffLine::parse(line)) + .collect(); + + let score = delta_chr_f(&golden_diff, &actual_diff); + println!("{:.2}", score); + } Some(Command::Clean) => { std::fs::remove_dir_all(&*crate::paths::TARGET_ZETA_DIR).unwrap() }