The ToString function removes the YAML document end marker if present in the document being parsed
ferrarimarco opened this issue · 0 comments
Describe the bug
The ToString
function removes the YAML document end marker (...
) if it's present in the document for which the ToString
function is called.
I see that there's an option called directivesEndMarker
that does the following, according to docs):
Whether the document should always include a directives-end marker
---
at its start, even if it includes no directives.
But that doesn't prevent the ToString function to strip the YAML document end marker. It also has a surprising (at least to me) name, because the ---
is the YAML document start, not the end.
I encountered this issue while investigating microsoft/compose-language-service#93.
To Reproduce
Create the following YAML file:
---
services:
test-service-1:
...
Load it, and call the ToString function on the resulting object, as done here:
const options: ToStringOptions = {
indent: params.options.tabSize,
indentSeq: true,
simpleKeys: true, // todo?
nullStr: '',
lineWidth: 0,
};
const range = Range.create(
params.document.textDocument.positionAt(0),
params.document.textDocument.positionAt(params.document.textDocument.getText().length)
);
const formatted = params.document.yamlDocument.value.toString(options);
This results in:
---
services:
test-service-1:
Expected behaviour
The ToString
shouldn't strip the YAML document end marker if present in the document being formatted or, at least, make this behavior configurable with an option.
Versions (please complete the following information):
- Environment: https://github.com/microsoft/compose-language-service
yaml
: "^2.0.0-10"
Additional context
Add any other context about the problem here.
/cc @bwateratmsft