scalameta / mdoc

Typechecked markdown documentation for Scala
https://scalameta.org/mdoc/
Apache License 2.0
394 stars 80 forks source link

bugfix: Remove additional whitespace from summary #872

Closed tgodzik closed 1 month ago

tgodzik commented 2 months ago

The recent changes caused the spaces to no longer be removed properly due to the fact that we no longer operate on an actual value when printing one line summary.

I tried solving this multiple ways but:

The easiest approach was to just replace newline with space and then deduplicate whitespace to save space on the oneline summary. This also makes it consistent across Scala 2 and 3

keynmol commented 2 months ago

@tgodzik I'm struggling to figure out

Do you have a screenshot perhaps of something broken and/or working well?

tgodzik commented 2 months ago

What problem was the original code solving

When evaluating mutable collections we would always get the last result for everything, because values were evaluated only when printing. I switched to printing them right away to always get the current result.

What broke with recent release

Printing one line stopped removing additional spaces, so if the printed value had indentation it would all stay in the oneline summary and be quite unreadable.

What is the result you expect visually

One line summary should be as compact as possible without losing the visibility, so I decided to just squash any whitespace into a single space.

Do you have a screenshot perhaps of something broken and/or working well?

This broke in Metals https://github.com/scalameta/metals/pull/6523 (and I think it's the only place the one line summary is being used)

image

tgodzik commented 1 month ago

@keynmol what do you think? Or do you see a possibility to improve this approach?