vscode-yaml: Array item properties are created with the wrong indent
I have a JSON schema which contains an array property. The array item type is an object with properties. The desired layout is like this:
install:
- helm:
name: foo
- helm:
name: bar
When I add the array using tab-completion, RH YAML correctly inserts a starting array element with the correct indentation:
in<HIT TAB TO AUTOCOMPLETE>
=>
install:
- helm:
name: <CURSOR POSITIONED HERE> # This is correct
But when I add a second array element by tab-completing the name, it does not indent the sub-properties:
install:
- helm:
name: foo
- he<HIT TAB TO AUTOCOMPLETE>
=>
install:
- helm:
name: foo
- helm:
name: <CURSOR HERE> # Note name is *NOT* indented from its parent
Furthermore, our real scenario is that the array can contain multiple different kinds of item (which is why we have the helm
parent name rather than just an array of tuples). So our JSON schema specifies "items": { "anyOf": [ { "$ref": "...helm..." }, { "$ref": "...exec..." }, ... ] }
. In this case, even with only a single option in the “anyOf”, no element is auto inserted (correctly, as RH YAML could not know which of the anyOf options to take), and the user must explicitly insert the first array element, which is then indented incorrectly
# With the anyOf variant of the JSON Schema
in<HIT TAB FOR AUTOCOMPLETION>
=>
install:
- <CURSOR HERE> # This is okay
=>
install:
- he<HIT TAB FOR AUTOCOMPLETION>
=>
install:
- helm:
name: <CURSOR HERE> # Incorrect indentation
Here is the simplified JSON Schema which I used to reproduce the issue:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"installStep": {
"properties": {
"helm": {
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
],
"type": "object"
}
},
"required": [
"helm"
],
"type": "object"
}
},
"properties": {
"install": {
"items": {
"anyOf": [
{
"$ref": "#/definitions/installStep"
}
]
},
"type": "array"
}
},
"type": "object"
}
Note that this is the ‘anyOf’ schema to show the second part of the issue (which is our real environment). To reproduce the first part of the issue, remove the anyOf
from around the $ref
in the items
schema (or I can send you that schema too).
Please let me know if you need any more information.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 27 (20 by maintainers)
Commits related to this issue
- Fix issue: Array item properties are created with the wrong indent #https://github.com/redhat-developer/vscode-yaml/issues/192 Signed-off-by: andxu <andxu@microsoft.com> — committed to andxu/yaml-language-server by andxu 5 years ago
- Fix issue: Array item properties are created with the wrong indent #h… (#172) * Fix issue: Array item properties are created with the wrong indent #https://github.com/redhat-developer/vscode-yaml/iss... — committed to redhat-developer/yaml-language-server by andxu 5 years ago
- #192: handle less-specified initialization — committed to bleach31/vscode-yaml by bollwyvl 5 years ago
once the yaml LS is published at npm, I will update the vscode-yaml here.