Skip to content

Commit

Permalink
Add Indentation rules
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCMD committed Dec 16, 2024
1 parent cc26e5e commit 7b258bf
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Syntax highlighting
- Bracket matching
- Indentation rules
- YAML versions [1.2](https://yaml.org/spec/1.2.2), [1.1](https://yaml.org/spec/1.1/), [1.0](https://yaml.org/spec/1.0/) and [1.3](https://spec.yaml.io/main/spec/1.3.0/)


Expand All @@ -14,6 +15,6 @@
- Previously known [Issues](https://github.com/RedCMD/YAML-Syntax-Highlighter/issues/1)
- Original YAML [grammar](https://github.com/textmate/yaml.tmbundle)
- Atom's YAML [grammar](https://github.com/atom/language-yaml)
- Offical YAML [website](https://yaml.org/)
- Official YAML [website](https://yaml.org/)
- Github [repo](https://github.com/RedCMD/YAML-Syntax-Highlighter)
- Marketplace [extension](https://marketplace.visualstudio.com/items?itemName=RedCMD.yaml-syntax)
123 changes: 119 additions & 4 deletions language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,130 @@
["{", "}"],
["[", "]"]
],
// markers that can be folded
"folding": {
"offSide": true,
"markers": {
"start": "^[ \t]*#[ \t]*region\\b|^---[ \t]*(#.*)?$",
"end": "^[ \t]*#[ \t]*endregion\\b|^\\.{3}[ \t]*(#.*)?$"
}
},
"indentationRules": {
"increaseIndentPattern": "^\\s*.*(:|-) ?(&\\w+)?(\\{[^}\"']*|\\[[^\\]\"']*)?$",
"decreaseIndentPattern": "^\\s+[\\]\\}]$"
}
// Only the first successful rule is chosen
"onEnterRules": [
{
// indent 1 space after block-scalar with indentation-indicator
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?1"
},
{
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?2"
},
{
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?3"
},
{
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?4"
},
{
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?5"
},
{
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?6"
},
{
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?7"
},
{
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?8"
},
{
// indent 9 spaces after block-scalar with indentation-indicator
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "([ \t]+|^)[|>][+-]?9"
},
{
// - block-map: # with an empty value OR block-scalar. Prefixed with a block-seq
"action": {
"appendText": " ",
"indent": "none"
},
"beforeText": "(^| |\t)-[ \t]+[^#,\\[\\]{}].*:(([ \t]+[|>][+-]?)?([ \t]+#.*)?|[ \t]*)$"
},
{
// indent 2 spaces after non-root block-scalar
"action": {
"appendText": " ",
"indent": "none",
},
"afterText": "^(?![ \t]*#)",
"beforeText": "[-?:][ \t]+[|>][+-]?[ \t]*(#.*)?$"
},
{
// block-map: cursor_must_be_before_value
"action": {
"appendText": " ",
"indent": "none"
},
"beforeText": "(?<!( |\t|^)(#|\\?[ \t]).*):([ \t]*|[ \t]+#.*)$"
},
{
// - #empty block-seq
"action": {
"appendText": " ",
"indent": "none"
},
"beforeText": "(^| |\t)-([ \t]*|[ \t]+#.*)$"
},
{
// - block-seq
"action": {
"appendText": "- ",
"indent": "none"
},
"beforeText": "(^| |\t)-[ \t].*$"
}
]
}

0 comments on commit 7b258bf

Please sign in to comment.