Languages and frameworks: YAML
JetBrains Rider enables you to work with YAML files (.yml, .yaml) and supports the following capabilities:
Syntax highlighting
You can change color settings on the Editor | Code Style | YAML page of the Settings/Preferences dialog (Ctrl+Alt+S) .
Code formatting
You can access code style settings related to YAML on the Editor | Code Style | YAML page of the Settings/Preferences dialog (Ctrl+Alt+S) .
JetBrains Rider detects duplicated keys, unused anchors in YAML documents, and so on.
For example, you can use code completion for YAML documents that have the JSON schema, or you can complete anchor aliases.
Navigation and search
For instance, you can navigate between anchors and aliases.
Rename refactorings (for example, for anchors and aliases)
Let’s explore some YAML-specific features available in the editor.
Anchors and aliases
JetBrains Rider supports working with anchors and aliases. If you specify a new anchor in the YAML file, the editor will show a warning that this anchor is not used by any node.
The editor enables you now to complete aliases for this anchor.
To quickly find usages of an anchor, place the caret on the anchor and press Ctrl+B.
JetBrains Rider supports the rename refactoring for anchors and aliases: Place the caret on the anchor and press Shift+F6. Alternatively, right-click the anchor and select .
Use the Structure tool window (Alt+7) to quickly navigate through YAML files. To show or hide elements of reused anchors in the Structure tool window, click use Aliased sub-trees.
JSON schemas
JetBrains Rider supports code completion and inspections for YAML files using the JSON schema. JetBrains Rider can infer a schema automatically (based on the file location or structure), or you can select it manually. For example, if you have GitHub Actions workflow files in the .github/workflows directory, JetBrains Rider will suggest completing its options based on the github-workflow.json schema automatically loaded from schemastore.org:
You can manage loading JSON schemas using the Languages & Frameworks | Schemas and DTDs | Remote JSON Schemas page of the Settings/Preferences dialog (Ctrl+Alt+S) .
If necessary, you can specify a path to the required schema file in Languages & Frameworks | Schemas and DTDs | JSON Schema Mappings.
Select a JSON schema for a file
You can specify a custom schema for a particular file.
Click the schema switcher in the status bar.
In the list that opens, select one of the suggested schemas or click New Schema Mapping…. This will open the JSON Schema Mappings settings where you can specify a local or remote schema for your file.
Get properties from a schema
If JetBrains Rider detects a schema for your YAML file, you can quickly insert all of its properties into that file using a dedicated action, removing the need for manual typing.
If a schema contains required properties, and you want to insert only these particular properties, press Alt+Enter (Show Context Actions) anywhere in a file and select Add missing properties.
If you want to insert all properties available in the schema, press Alt+Enter (Show Context Actions) anywhere in a file and select Fill in all properties from JSON schema.
Use $schema keyword
You can also refer to a schema right in the file itself.
At the top of the file, enter
# $schema:
.Start typing the name of a schema file. You'll get completion for the names of schemas loaded from schemastore.org.
If you want to use a local schema file, specify the path to it relative to the file where you want to use the schema, for example,
# $schema: ./my-schema.json
. This will enable the same coding assistance that you would have when you use a remote schema, including inspections, completion, and property filling actions.
Copying keys
JetBrains Rider provides the ability to copy a full path to a specific option specified in the YAML file. You can do this in two ways:
Place a caret to the required key and press Ctrl+Alt+Shift+C.
Hover over the required key, right-click it and select Copy Reference.
For example, on the image above, default.server.port
will be copied.