Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
edit_prediction: Fix special token check matching `=======` inside comments (#52510)
Shiven Garia56104fb17e6c
diff --git a/crates/zeta_prompt/src/zeta_prompt.rs b/crates/zeta_prompt/src/zeta_prompt.rsindex 3ec90baf6e7..e3aced7ed81 100644--- a/crates/zeta_prompt/src/zeta_prompt.rs+++ b/crates/zeta_prompt/src/zeta_prompt.rs@@ -211,9 +211,13 @@ pub struct RelatedExcerpt {}pub fn prompt_input_contains_special_tokens(input: &ZetaPromptInput, format: ZetaFormat) -> bool {- special_tokens_for_format(format)- .iter()- .any(|token| input.cursor_excerpt.contains(token))+ special_tokens_for_format(format).iter().any(|token| {+ if let Some(line_token) = token.strip_suffix('\n') {+ input.cursor_excerpt.lines().any(|line| line == line_token)+ } else {+ input.cursor_excerpt.contains(token)+ }+ })}pub fn format_zeta_prompt(input: &ZetaPromptInput, format: ZetaFormat) -> Option<String> {@@ -5287,4 +5291,15 @@ mod tests {assert_eq!(apply_edit(excerpt, &output1), apply_edit(excerpt, &output2));assert_eq!(apply_edit(excerpt, &output1), "new content\n");}++ #[test]+ fn test_special_tokens_not_triggered_by_comment_separator() {+ // Regression test for https://github.com/zed-industries/zed/issues/52489+ let excerpt = "fn main() {\n // =======\n println!(\"hello\");\n}\n";+ let input = make_input(excerpt, 0..excerpt.len(), 0, vec![], vec![]);+ assert!(+ !prompt_input_contains_special_tokens(&input, ZetaFormat::V0131GitMergeMarkersPrefix),+ "comment containing ======= should not trigger special token detection"+ );+ }}