Fix yaml comment indent (#33882)
Closes #33761 The problem was that in the indentation regex we were treating lines that had `:` in them as requiring an indent on the next line, even if that `:` was inside a comment. Release Notes: - Fixed YAML indentation for lines containing comments with `:` in them
This commit is contained in:
parent
91bfe6f968
commit
03ca2f4d2b
4 changed files with 67 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4830,6 +4830,7 @@ dependencies = [
|
|||
"tree-sitter-python",
|
||||
"tree-sitter-rust",
|
||||
"tree-sitter-typescript",
|
||||
"tree-sitter-yaml",
|
||||
"ui",
|
||||
"unicode-script",
|
||||
"unicode-segmentation",
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue