aboutsummaryrefslogtreecommitdiff
path: root/runtime/queries
diff options
context:
space:
mode:
authorSkyler Hawthorne2023-04-14 15:00:15 +0000
committerBlaž Hrastnik2023-08-10 21:22:22 +0000
commit7078e8400736dce923be44a4d26f136a22640f93 (patch)
treee1f9d821b605c5809d3210a79b91922c6edeb06b /runtime/queries
parent57f093d83641642ad5d4ba42ae59f03272efcfcc (diff)
Fix YAML auto indent
YAML indents queries are tweaked to fix auto indent behavior. A new capture type `indent.always` is introduced to address use cases where combining indent captures on a single line is desired. Fixes #6661
Diffstat (limited to 'runtime/queries')
-rw-r--r--runtime/queries/yaml/indents.scm36
1 files changed, 35 insertions, 1 deletions
diff --git a/runtime/queries/yaml/indents.scm b/runtime/queries/yaml/indents.scm
index 70a00b69..87853eb6 100644
--- a/runtime/queries/yaml/indents.scm
+++ b/runtime/queries/yaml/indents.scm
@@ -1,2 +1,36 @@
-(block_mapping_pair) @indent
+(block_scalar) @indent @extend
+; indent sequence items only if they span more than one line, e.g.
+;
+; - foo:
+; bar: baz
+; - quux:
+; bar: baz
+;
+; but not
+;
+; - foo
+; - bar
+; - baz
+((block_sequence_item) @item @indent.always @extend
+ (#not-one-line? @item))
+
+; map pair where without a key
+;
+; foo:
+((block_mapping_pair
+ key: (_) @key
+ !value
+ ) @indent.always @extend
+)
+
+; map pair where the key and value are on different lines
+;
+; foo:
+; bar: baz
+((block_mapping_pair
+ key: (_) @key
+ value: (_) @val
+ (#not-same-line? @key @val)
+ ) @indent.always @extend
+) \ No newline at end of file