Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't add extra newlines when there aren't extra sections in doc markdown #14734

Merged
merged 1 commit into from Mar 22, 2022

Conversation

ckipp01
Copy link
Member

@ckipp01 ckipp01 commented Mar 21, 2022

Currently if you have a simple scaladoc and you use renderAsMarkdown
(which Metals does) to render markdown for hovers, there are extra
newlines added that aren't necessary. Normally you can't tell as it
seems some editors just trim off the extra newlines, but you can see
in certain editors and in the REPL as well.

Notice how it removes two lines

scala> :doc CanEqual
Companion object containing a few universally known `CanEqual` instances.
  CanEqual instances involving primitive types or the Null type are handled directly in
  the compiler (see Implicits.synthesizedCanEqual), so they are not included here.

-
-

This just ensures that we add the extra two newlines only when we know
we have more sections coming.

fixes scalameta/metals#3740

@ckipp01 ckipp01 requested a review from tgodzik March 21, 2022 15:39
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@michelou michelou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckipp01 I suggest the following change to lines 68ff :

    if sections.nonEmpty then
      buf.append(System.lineSeparator + System.lineSeparator)
      sections.foreach { section =>
        buf.append(section)
        buf.append(System.lineSeparator)
      }
    buf.toString

… markdown

Currently if you have a simple scaladoc and you use `renderAsMarkdown`
(which Metals does) to render markdown for hovers, there are extra
newlines added that aren't necessary. Normally you can't tell as it
seems some editors just trim off the extra newlines, but you can see
in certain editors and in the REPL as well.

_Notice how it removes two lines_
```diff
scala> :doc CanEqual
Companion object containing a few universally known `CanEqual` instances.
  CanEqual instances involving primitive types or the Null type are handled directly in
  the compiler (see Implicits.synthesizedCanEqual), so they are not included here.

-
-
```

This just ensures that we add the extra two newlines only when we know
we have more sections coming.

fixes scalameta/metals#3740
@ckipp01
Copy link
Member Author

ckipp01 commented Mar 21, 2022

@ckipp01 I suggest the following change to lines 68ff :

    if sections.nonEmpty then
      buf.append(System.lineSeparator + System.lineSeparator)
      sections.foreach { section =>
        buf.append(section)
        buf.append(System.lineSeparator)
      }
    buf.toString

Ah, good idea. Applied.

@tgodzik tgodzik merged commit b5f34a5 into scala:main Mar 22, 2022
@ckipp01 ckipp01 deleted the docCommentMarkdown branch March 22, 2022 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Too many newlines in hover when showing synthetics with Scala 3
3 participants