Format Document chokes on comments
It happens when there are comments in the .yml file. The issue happens on this line:
emitter.Emit(parser.Current);
...in this file https://github.com/aaubry/YamlDotNet.Editor/blob/master/YamlDotNetEditor/CommandHandlers/FormatDocumentCommandHandler.cs#L55
So the error happens in the YamlDotNet NuGet package somewhere that can't be fixed from the extension itself.
Repro steps
In a YAML file containing this:
# version format
version: 1.0.{build}
Now invoke the Format Document command (Ctrl+K+D) and you get the error.
The problem must be that the parser is configured to return comments, but comments are not officially part of the YAML document and the emitter does not supports them.
So perhaps the fix for now is to remove the support for Format Document then?
Not necessarily. Since the parser has support to return comments, it would make sense to support them in the emitter. I added support for comments because it was necessary for this extension, but at the time I did not need to emit comments, so I forgot to add them to the emitter. I will take a look to the code to see what would be required.