Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix yaml comment indent (#33882)

Richard Feldman03ca2f4d2be4
diff --git a/Cargo.lock b/Cargo.lock
index 48928bcea0f..d7e645131d9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4830,6 +4830,7 @@ dependencies = [
"tree-sitter-python",
"tree-sitter-rust",
"tree-sitter-typescript",
+ "tree-sitter-yaml",
"ui",
"unicode-script",
"unicode-segmentation",
diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml
index bea83b1df82..4d6939567eb 100644
--- a/crates/editor/Cargo.toml
+++ b/crates/editor/Cargo.toml
@@ -109,6 +109,7 @@ theme = { workspace = true, features = ["test-support"] }
tree-sitter-html.workspace = true
tree-sitter-rust.workspace = true
tree-sitter-typescript.workspace = true
+tree-sitter-yaml.workspace = true
unindent.workspace = true
util = { workspace = true, features = ["test-support"] }
workspace = { workspace = true, features = ["test-support"] }
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index 8615ff2a97d..ade9a9322bc 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -3468,6 +3468,70 @@ async fn test_indent_outdent(cx: &mut TestAppContext) {
"});
}
+#[gpui::test]
+async fn test_indent_yaml_comments_with_multiple_cursors(cx: &mut TestAppContext) {
+ // This is a regression test for issue #33761
+ init_test(cx, |_| {});
+
+ let mut cx = EditorTestContext::new(cx).await;
+ let yaml_language = languages::language("yaml", tree_sitter_yaml::LANGUAGE.into());
+ cx.update_buffer(|buffer, cx| buffer.set_language(Some(yaml_language), cx));
+
+ cx.set_state(
+ r#"ˇ# ingress:
+ˇ# api:
+ˇ# enabled: false
+ˇ# pathType: Prefix
+ˇ# console:
+ˇ# enabled: false
+ˇ# pathType: Prefix
+"#,
+ );
+
+ // Press tab to indent all lines
+ cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx));
+
+ cx.assert_editor_state(
+ r#" ˇ# ingress:
+ ˇ# api:
+ ˇ# enabled: false
+ ˇ# pathType: Prefix
+ ˇ# console:
+ ˇ# enabled: false
+ ˇ# pathType: Prefix
+"#,
+ );
+}
+
+#[gpui::test]
+async fn test_indent_yaml_non_comments_with_multiple_cursors(cx: &mut TestAppContext) {
+ // This is a test to make sure our fix for issue #33761 didn't break anything
+ init_test(cx, |_| {});
+
+ let mut cx = EditorTestContext::new(cx).await;
+ let yaml_language = languages::language("yaml", tree_sitter_yaml::LANGUAGE.into());
+ cx.update_buffer(|buffer, cx| buffer.set_language(Some(yaml_language), cx));
+
+ cx.set_state(
+ r#"ˇingress:
+ˇ api:
+ˇ enabled: false
+ˇ pathType: Prefix
+"#,
+ );
+
+ // Press tab to indent all lines
+ cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx));
+
+ cx.assert_editor_state(
+ r#"ˇingress:
+ ˇapi:
+ ˇenabled: false
+ ˇpathType: Prefix
+"#,
+ );
+}
+
#[gpui::test]
async fn test_indent_outdent_with_hard_tabs(cx: &mut TestAppContext) {
init_test(cx, |settings| {
diff --git a/crates/languages/src/yaml/config.toml b/crates/languages/src/yaml/config.toml
index cf3d9e1181a..4dfb890c548 100644
--- a/crates/languages/src/yaml/config.toml
+++ b/crates/languages/src/yaml/config.toml
@@ -12,6 +12,6 @@ brackets = [
auto_indent_on_paste = false
auto_indent_using_last_non_empty_line = false
-increase_indent_pattern = ":\\s*[|>]?\\s*$"
+increase_indent_pattern = "^[^#]*:\\s*[|>]?\\s*$"
prettier_parser_name = "yaml"
tab_size = 2