microsoft / microsoft/vscode

YAML indentation rules do not work

Open
#330,394 3 comments 0 reactions 1 assignee Claimed by @aiday-mar View on GitHub
bug editor-autoindent
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Does this issue occur when all extensions are disabled?: Yes

- VS Code Version: 1.132.1
- OS Version: Windows_NT x64 10.0.19045

Steps to Reproduce:

There are a number of problems with the `indentationRules` for YAML.
https://github.com/microsoft/vscode/blob/b10759526092db723a7217e7627ae309d74719f4/extensions/yaml/language-configuration.json#L31-L34

### 1. Starting an object does not indent

1. Type `foo:`
2. Press Enter

According to the `increaseIndentPattern`, this should increase the indent for the next line. Instead, the next line starts at the same indentation as the previous line.

No Indent After Property - VS Code Default

If I create my own extension with exactly the same `language-configuration.json`, this does work:

Indent After Property - Custom Extension

### 2. Anchors are not handled

The rule attempts to allow an anchor to follow a property name and colon, but it looks like it has been copied verbatim from an XML language declaration because it uses `(&\\w+)?` instead of `(&\\w+)?`.

1. Type `foo: &anchor`
2. Press Enter

The next line should be indented, but it starts at the same indentation as the previous line.

Since VS Code doesn't seem to use the indentation rules (see problem 1), I can demonstrate this with my own extension that uses the same `language-configuration.json`.

No Indent After Anchor

If you change `&` to just `&`, it fixes it:

Indent After Anchor Fixed

### 3. No Indent After Block Scalar

The indentation rules do not indent after starting a block scalar. When you start a block scalar using either `|` or `>`, the next line needs to be indented, but the indentation rules don't take this into account.

1. Type `foo: |`
2. Press Enter

The next line should be indented, it it starts at the same indentation as the previous line.

Image

Unlike the other problems, the indentation rules do not attempt to handle this, but I think it should be a simple addition.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.