redhat-developer / vscode-yaml

YAML support for VS Code with built-in kubernetes syntax support
MIT License
650 stars 221 forks source link

Formatting document should not destroy comments #75

Closed teohhanhui closed 5 years ago

teohhanhui commented 6 years ago

If yaml.format.enable is true, using the "Format Document" function destroys YAML comments.

JPinkney commented 6 years ago

This is an issue with the underlying parser. Currently there is not a parser (that I can find) that supports comment nodes. if one becomes available then I would happily switch the formatter to use that to preserve the comments.

teohhanhui commented 6 years ago

We should follow this issue then: https://github.com/mulesoft-labs/yaml-ast-parser/issues/27

caub commented 6 years ago

@JPinkney do you think the parser can be updated to https://github.com/eemeli/yaml?, that's what the issue above leads to, it supports fully comments

JPinkney commented 6 years ago

Only the formatter needs to be updated to use that parser instead. If we do that then a better formatter can be built ontop of that.

GuidoS commented 6 years ago

Can you share a link to the formatter?

JPinkney commented 6 years ago

The current one? Its just this

JPinkney commented 5 years ago

Hi! we've replaced the formatter with a new one that doesn't strip comments!

frezbo commented 5 years ago

@JPinkney I still see comments getting removed, any thoughts?

JPinkney commented 5 years ago

Which version are you on and can you post an example

frezbo commented 5 years ago

@JPinkney I'm on redhat.vscode-yaml@0.1.0 . The comments in YAML get removed when calling Format Document

JPinkney commented 5 years ago

Is there any particular case that the comment gets removed?

Formatting

# First Comment
hello: world

#Second Comment
cwd: /hello
scripts: #Third Comment
  postinstall: test #Fourth Comment
  #Fifth comment

doesn't remove any comments for me. Do you have any other YAML related extensions installed?

frezbo commented 5 years ago

@JPinkney thanks for helping me out, had another YAML formatter installed. :+1:

JPinkney commented 5 years ago

No worries! I'm glad to see that we could get the issue resolved :)