yaml.md

  1# YAML
  2
  3YAML support is available natively in Zed.
  4
  5- Tree-sitter: [zed-industries/tree-sitter-yaml](https://github.com/zed-industries/tree-sitter-yaml)
  6- Language Server: [redhat-developer/yaml-language-server](https://github.com/redhat-developer/yaml-language-server)
  7
  8## Configuration
  9
 10You can configure various [yaml-language-server settings](https://github.com/redhat-developer/yaml-language-server?tab=readme-ov-file#language-server-settings) by adding them to your Zed settings.json in a `yaml-language-server` block under the `lsp` key. For example:
 11
 12```json [settings]
 13  "lsp": {
 14    "yaml-language-server": {
 15      "settings": {
 16        "yaml": {
 17          "keyOrdering": true,
 18          "format": {
 19            "singleQuote": true
 20          },
 21          "schemas": {
 22              "http://json.schemastore.org/composer": ["/*"],
 23              "../relative/path/schema.json": ["/config*.yaml"]
 24          }
 25        }
 26      }
 27    }
 28  }
 29```
 30
 31Note, settings keys must be nested, so `yaml.keyOrdering` becomes `{"yaml": { "keyOrdering": true }}`.
 32
 33## Formatting
 34
 35By default, Zed uses Prettier for formatting YAML files.
 36
 37### Prettier Formatting
 38
 39You can customize the formatting behavior of Prettier. For example to use single-quotes in yaml files add the following to your `.prettierrc` configuration file:
 40
 41```json [settings]
 42{
 43  "overrides": [
 44    {
 45      "files": ["*.yaml", "*.yml"],
 46      "options": {
 47        "singleQuote": false
 48      }
 49    }
 50  ]
 51}
 52```
 53
 54### yaml-language-server Formatting
 55
 56To use `yaml-language-server` instead of Prettier for YAML formatting, add the following to your Zed `settings.json`:
 57
 58```json [settings]
 59  "languages": {
 60    "YAML": {
 61      "formatter": "language_server"
 62    }
 63  }
 64```
 65
 66## Schemas
 67
 68By default yaml-language-server will attempt to determine the correct schema for a given yaml file and retrieve the appropriate JSON Schema from [Json Schema Store](https://schemastore.org/).
 69
 70You can override any auto-detected schema via the `schemas` settings key (demonstrated above) or by providing an [inlined schema](https://github.com/redhat-developer/yaml-language-server#using-inlined-schema) reference via a modeline comment at the top of your yaml file:
 71
 72```yaml
 73# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
 74name: Issue Assignment
 75on:
 76  issues:
 77    types: [oppened]
 78```
 79
 80You can disable the automatic detection and retrieval of schemas from the JSON Schema if desired:
 81
 82```json [settings]
 83  "lsp": {
 84    "yaml-language-server": {
 85      "settings": {
 86        "yaml": {
 87          "schemaStore": {
 88            "enable": false
 89          }
 90        }
 91      }
 92    }
 93  }
 94```
 95
 96## Custom Tags
 97
 98Yaml-language-server supports [custom tags](https://github.com/redhat-developer/yaml-language-server#adding-custom-tags) which can be used to inject custom application functionality at runtime into your yaml files.
 99
100For example Amazon CloudFormation YAML uses a number of custom tags, to support these you can add the following to your settings.json:
101
102```json [settings]
103  "lsp": {
104    "yaml-language-server": {
105      "settings": {
106        "yaml": {
107          "customTags": [
108            "!And scalar",
109            "!And mapping",
110            "!And sequence",
111            "!If scalar",
112            "!If mapping",
113            "!If sequence",
114            "!Not scalar",
115            "!Not mapping",
116            "!Not sequence",
117            "!Equals scalar",
118            "!Equals mapping",
119            "!Equals sequence",
120            "!Or scalar",
121            "!Or mapping",
122            "!Or sequence",
123            "!FindInMap scalar",
124            "!FindInMap mapping",
125            "!FindInMap sequence",
126            "!Base64 scalar",
127            "!Base64 mapping",
128            "!Base64 sequence",
129            "!Cidr scalar",
130            "!Cidr mapping",
131            "!Cidr sequence",
132            "!Ref scalar",
133            "!Ref mapping",
134            "!Ref sequence",
135            "!Sub scalar",
136            "!Sub mapping",
137            "!Sub sequence",
138            "!GetAtt scalar",
139            "!GetAtt mapping",
140            "!GetAtt sequence",
141            "!GetAZs scalar",
142            "!GetAZs mapping",
143            "!GetAZs sequence",
144            "!ImportValue scalar",
145            "!ImportValue mapping",
146            "!ImportValue sequence",
147            "!Select scalar",
148            "!Select mapping",
149            "!Select sequence",
150            "!Split scalar",
151            "!Split mapping",
152            "!Split sequence",
153            "!Join scalar",
154            "!Join mapping",
155            "!Join sequence",
156            "!Condition scalar",
157            "!Condition mapping",
158            "!Condition sequence"
159          ]
160        }
161      }
162    }
163  }
164```