Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
yaml: Fix indentation with dictionary when editing (#40913)
Coenen Benjamin3ef81633571d
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 903ca3b9c1d..3709709c71f 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -3136,6 +3136,77 @@ fn test_newline(cx: &mut TestAppContext) {});}+#[gpui::test]+async fn test_newline_yaml(cx: &mut TestAppContext) {+ 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));++ // Object (between 2 fields)+ cx.set_state(indoc! {"+ test:ˇ+ hello: bye"});+ cx.update_editor(|e, window, cx| e.newline(&Newline, window, cx));+ cx.assert_editor_state(indoc! {"+ test:+ ˇ+ hello: bye"});++ // Object (first and single line)+ cx.set_state(indoc! {"+ test:ˇ"});+ cx.update_editor(|e, window, cx| e.newline(&Newline, window, cx));+ cx.assert_editor_state(indoc! {"+ test:+ ˇ"});++ // Array with objects (after first element)+ cx.set_state(indoc! {"+ test:+ - foo: barˇ"});+ cx.update_editor(|e, window, cx| e.newline(&Newline, window, cx));+ cx.assert_editor_state(indoc! {"+ test:+ - foo: bar+ ˇ"});++ // Array with objects and comment+ cx.set_state(indoc! {"+ test:+ - foo: bar+ - bar: # testˇ"});+ cx.update_editor(|e, window, cx| e.newline(&Newline, window, cx));+ cx.assert_editor_state(indoc! {"+ test:+ - foo: bar+ - bar: # test+ ˇ"});++ // Array with objects (after second element)+ cx.set_state(indoc! {"+ test:+ - foo: bar+ - bar: fooˇ"});+ cx.update_editor(|e, window, cx| e.newline(&Newline, window, cx));+ cx.assert_editor_state(indoc! {"+ test:+ - foo: bar+ - bar: foo+ ˇ"});++ // Array with strings (after first element)+ cx.set_state(indoc! {"+ test:+ - fooˇ"});+ cx.update_editor(|e, window, cx| e.newline(&Newline, window, cx));+ cx.assert_editor_state(indoc! {"+ test:+ - foo+ ˇ"});+}+#[gpui::test]fn test_newline_with_old_selections(cx: &mut TestAppContext) {init_test(cx, |_| {});diff --git a/crates/language/src/language.rs b/crates/language/src/language.rsindex e3fb6733dd5..3d777e5ff6f 100644--- a/crates/language/src/language.rs+++ b/crates/language/src/language.rs@@ -680,7 +680,7 @@ pub struct CodeLabelBuilder {filter_range: Range<usize>,}-#[derive(Clone, Deserialize, JsonSchema)]+#[derive(Clone, Deserialize, JsonSchema, Debug)]pub struct LanguageConfig {/// Human-readable name of the language.pub name: LanguageName,@@ -823,7 +823,7 @@ pub struct LanguageMatcher {}/// The configuration for JSX tag auto-closing.-#[derive(Clone, Deserialize, JsonSchema)]+#[derive(Clone, Deserialize, JsonSchema, Debug)]pub struct JsxTagAutoCloseConfig {/// The name of the node for a opening tagpub open_tag_node_name: String,diff --git a/crates/languages/src/yaml/config.toml b/crates/languages/src/yaml/config.tomlindex e54bceda1ae..e941497bf3f 100644--- a/crates/languages/src/yaml/config.toml+++ b/crates/languages/src/yaml/config.toml@@ -12,6 +12,13 @@ brackets = [auto_indent_on_paste = falseauto_indent_using_last_non_empty_line = false-increase_indent_pattern = "^[^#]*:\\s*[|>]?\\s*$"+# 1st block to match basic elements followed by ':' like 'test: ' for example+# 2nd block to match for first element in an array if it's an object+# For example:+# ```yaml+# test:+# - first: one+# ```+increase_indent_pattern = "(:?^[^#]*:\\s*[|>]?\\s*$)|(:?^\\s*-[^#]*:\\s*(:?#+.*)$)"prettier_parser_name = "yaml"tab_size = 2