redhat-developer / vscode-yaml

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

Can not fold YAML map comment #763

Open Takakiriy opened 2 years ago

Takakiriy commented 2 years ago

Describe the bug

When I try to fold a map with a comment in the YAML extension enabled, I get the problem that I can't fold it.

Expected Behavior

This is an unfolded text example.

good_unfold

This is a text that is folded above example.

good_fold

Current Behavior

This is an unfolded text example.

bad_unfold

This is a text that is folded above example.

bad_fold

Steps to Reproduce

  1. open a YAML file

Environment

Related Issue

gorkem commented 2 years ago

We do not have a good way to know if a comment block is intended to be folded with which pair. For instance, in the example given, we only expect #d to be folded with c because it was indented. Perhaps indentations of the comments are how we recognize folding boundaries.

siegenthalerroger commented 3 months ago

Seconding this feature request and @gorkem 's analysis that it's not trivial to identify when comments belong to a folding range or not. However as stated I believe that the indentation of the leading # is what you'd want to use to guide the folding range. When selecting some indented key-value it places keeps the indentation intact so the "add line comment" commands would function correctly with the folding ranges computed as suggested.

Takakiriy commented 3 months ago

In the old VSCode default specifications, the folding range was determined by indentation, so if the indentation is deeper, I think it is better to judge that it belongs to the element above.

timothee-bacri commented 1 month ago

FYI, Notepad++ has done this in a similar way to @gorkem's suggestion. In case it helps, here are more details on their method:

a:
  b:
    - c

  d:

e:

becomes commented as

# a:
  # b:
    # - c

  # d:

# e:

and the lines with a: and b: can fold everything under (until the next key) to become respectively

# a:
# e:

and

# a:
  # b:
  # d:

# e:

Meanwhile, the default comments in VSCode seem to be applied to the level of the least indented line.

a:
#   b:
#     - c

#   d:

# e: