Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix line comment rewrap in golang and C/C++ (#54931)
Nathan Witmerf506d161286b
diff --git a/Cargo.lock b/Cargo.lockindex a054d2657aa..0fbbd3c6bb8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5513,6 +5513,7 @@ dependencies = ["tracing","tree-sitter-bash","tree-sitter-c",+ "tree-sitter-go","tree-sitter-html","tree-sitter-md","tree-sitter-python",diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.tomlindex e97cc68c2f9..c88d1d2c4cd 100644--- a/crates/editor/Cargo.toml+++ b/crates/editor/Cargo.toml@@ -124,6 +124,7 @@ settings = { workspace = true, features = ["test-support"] }text = { workspace = true, features = ["test-support"] }theme = { workspace = true, features = ["test-support"] }tree-sitter-c.workspace = true+tree-sitter-go.workspace = truetree-sitter-html.workspace = truetree-sitter-rust.workspace = truetree-sitter-typescript.workspace = truediff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 8110c211a50..ee6b2be18b8 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -14003,7 +14003,8 @@ impl Editor {Some(CommentFormat::BlockCommentWithEnd(config.clone()))}(Some(config), _) | (_, Some(config))- if buffer.contains_str_at(indent_end, &config.prefix) =>+ if !config.prefix.is_empty()+ && buffer.contains_str_at(indent_end, &config.prefix) =>{Some(CommentFormat::BlockLine(config.prefix.to_string()))}diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex ea666367127..3a23bb1147b 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -8451,6 +8451,62 @@ async fn test_rewrap_block_comments(cx: &mut TestAppContext) {}}+#[gpui::test]+async fn test_rewrap_line_comment_in_go(cx: &mut TestAppContext) {+ init_test(cx, |settings| {+ settings.languages.0.extend([(+ "Go".into(),+ LanguageSettingsContent {+ allow_rewrap: Some(language_settings::RewrapBehavior::InComments),+ preferred_line_length: Some(40),+ ..Default::default()+ },+ )])+ });++ let mut cx = EditorTestContext::new(cx).await;++ let go_lang = languages::language("go", tree_sitter_go::LANGUAGE.into());++ cx.update_buffer(|buffer, cx| buffer.set_language(Some(go_lang), cx));+ cx.set_state(indoc! {"+ // Lorem ipsum dolor sit amet, consectetur adipiscing elit.ˇ+ "});+ cx.update_editor(|e, window, cx| e.rewrap(&Rewrap, window, cx));+ cx.assert_editor_state(indoc! {"+ // Lorem ipsum dolor sit amet,+ // consectetur adipiscing elit.ˇ+ "});+}++#[gpui::test]+async fn test_rewrap_line_comment_in_c(cx: &mut TestAppContext) {+ init_test(cx, |settings| {+ settings.languages.0.extend([(+ "C".into(),+ LanguageSettingsContent {+ allow_rewrap: Some(language_settings::RewrapBehavior::InComments),+ preferred_line_length: Some(40),+ ..Default::default()+ },+ )])+ });++ let mut cx = EditorTestContext::new(cx).await;++ let c_lang = languages::language("c", tree_sitter_c::LANGUAGE.into());++ cx.update_buffer(|buffer, cx| buffer.set_language(Some(c_lang), cx));+ cx.set_state(indoc! {"+ // Lorem ipsum dolor sit amet, consectetur adipiscing elit.ˇ+ "});+ cx.update_editor(|e, window, cx| e.rewrap(&Rewrap, window, cx));+ cx.assert_editor_state(indoc! {"+ // Lorem ipsum dolor sit amet,+ // consectetur adipiscing elit.ˇ+ "});+}+#[gpui::test]async fn test_hard_wrap(cx: &mut TestAppContext) {init_test(cx, |_| {});