Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
zeta: Reduce request payload (#35968)
Oleksiy Syvokond5ed569fad87
diff --git a/crates/zeta/src/input_excerpt.rs b/crates/zeta/src/input_excerpt.rsindex 5949e713e9e..8ca6d394075 100644--- a/crates/zeta/src/input_excerpt.rs+++ b/crates/zeta/src/input_excerpt.rs@@ -9,7 +9,6 @@ use std::{fmt::Write, ops::Range};pub struct InputExcerpt {pub editable_range: Range<Point>,pub prompt: String,- pub speculated_output: String,}pub fn excerpt_for_cursor_position(@@ -46,7 +45,6 @@ pub fn excerpt_for_cursor_position(let context_range = expand_range(snapshot, editable_range.clone(), context_token_limit);let mut prompt = String::new();- let mut speculated_output = String::new();writeln!(&mut prompt, "```{path}").unwrap();if context_range.start == Point::zero() {@@ -58,12 +56,6 @@ pub fn excerpt_for_cursor_position(}push_editable_range(position, snapshot, editable_range.clone(), &mut prompt);- push_editable_range(- position,- snapshot,- editable_range.clone(),- &mut speculated_output,- );for chunk in snapshot.chunks(editable_range.end..context_range.end, false) {prompt.push_str(chunk.text);@@ -73,7 +65,6 @@ pub fn excerpt_for_cursor_position(InputExcerpt {editable_range,prompt,- speculated_output,}}diff --git a/crates/zeta/src/zeta.rs b/crates/zeta/src/zeta.rsindex 1ddbd25cb88..69000820035 100644--- a/crates/zeta/src/zeta.rs+++ b/crates/zeta/src/zeta.rs@@ -37,7 +37,6 @@ use release_channel::AppVersion;use settings::WorktreeId;use std::str::FromStr;use std::{- borrow::Cow,cmp,fmt::Write,future::Future,@@ -66,6 +65,7 @@ const ZED_PREDICT_DATA_COLLECTION_CHOICE: &str = "zed_predict_data_collection_chconst MAX_CONTEXT_TOKENS: usize = 150;const MAX_REWRITE_TOKENS: usize = 350;const MAX_EVENT_TOKENS: usize = 500;+const MAX_DIAGNOSTIC_GROUPS: usize = 10;/// Maximum number of events to track.const MAX_EVENT_COUNT: usize = 16;@@ -1175,7 +1175,9 @@ pub fn gather_context(cx.background_spawn({let snapshot = snapshot.clone();async move {- let diagnostic_groups = if diagnostic_groups.is_empty() {+ let diagnostic_groups = if diagnostic_groups.is_empty()+ || diagnostic_groups.len() >= MAX_DIAGNOSTIC_GROUPS+ {None} else {Some(diagnostic_groups)@@ -1189,21 +1191,16 @@ pub fn gather_context(MAX_CONTEXT_TOKENS,);let input_events = make_events_prompt();- let input_outline = if can_collect_data {- prompt_for_outline(&snapshot)- } else {- String::new()- };let editable_range = input_excerpt.editable_range.to_offset(&snapshot);let body = PredictEditsBody {input_events,input_excerpt: input_excerpt.prompt,- speculated_output: Some(input_excerpt.speculated_output),- outline: Some(input_outline),can_collect_data,diagnostic_groups,git_info,+ outline: None,+ speculated_output: None,};Ok(GatherContextOutput {@@ -1214,32 +1211,6 @@ pub fn gather_context(})}-fn prompt_for_outline(snapshot: &BufferSnapshot) -> String {- let mut input_outline = String::new();-- writeln!(- input_outline,- "```{}",- snapshot- .file()- .map_or(Cow::Borrowed("untitled"), |file| file- .path()- .to_string_lossy())- )- .unwrap();-- if let Some(outline) = snapshot.outline(None) {- for item in &outline.items {- let spacing = " ".repeat(item.depth);- writeln!(input_outline, "{}{}", spacing, item.text).unwrap();- }- }-- writeln!(input_outline, "```").unwrap();-- input_outline-}-fn prompt_for_events(events: &VecDeque<Event>, mut remaining_tokens: usize) -> String {let mut result = String::new();for event in events.iter().rev() {