Skip to content

Conversation

@kitbellew
Copy link
Collaborator

Now that scalameta in 4.3.13 supports parsing of docstrings, let's use that and format.

Fixes #1387.
Fixes #1887.

@kitbellew kitbellew requested review from olafurpg and poslegm May 28, 2020 02:54
@kitbellew
Copy link
Collaborator Author

interesting coincidence on 1x87 pattern, that #1987 is addressing #1887 and #1387.

Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

This is exciting! A few more test cases that I think would be nice to cover.

  • code formatted with backticks (single line and multiline). Even if it’s not official scaladoc markup syntax I’ve seen it used several places and it renders as expected in some cases.
  • quoted strings (single and double), whether they get line wrapped or not we should document the behavior in the tests.
  • URLs followed by a white space and period. Just make sure not to remove the space.
  • HTML markup, white space inside HTML is significant so we should consider leaving it unchanged. Otherwise we may want to consider writing a full blown XML pretty printer.

Copy link
Collaborator Author

@kitbellew kitbellew left a comment

Choose a reason for hiding this comment

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

  • code formatted with backticks (single line and multiline). Even if it’s not official scaladoc markup syntax I’ve seen it used several places and it renders as expected in some cases.
  • quoted strings (single and double), whether they get line wrapped or not we should document the behavior in the tests.
  • URLs followed by a white space and period. Just make sure not to remove the space.
  • HTML markup, white space inside HTML is significant so we should consider leaving it unchanged. Otherwise we may want to consider writing a full blown XML pretty printer.

will do.

kitbellew added 3 commits May 28, 2020 21:27
Create a class and move the existing method there. We will subsequently
add methods to format and wrap docstrings.
@kitbellew
Copy link
Collaborator Author

kitbellew commented May 29, 2020

  • code formatted with backticks (single line and multiline). Even if it’s not official scaladoc markup syntax I’ve seen it used several places and it renders as expected in some cases.

Added a test for single backquotes.

In order to support triple backquotes, we need to modify the parser in scalameta; however, I am not sure how valid or useful that would be, as Intellij doesn't support them, and they don't seem to be supported in any scaladoc documentation (https://docs.scala-lang.org/overviews/scaladoc/for-library-authors.html#markup, http://keithpinson.github.io/Scaladoc-HOWTO/api/docSample/syntax.html)

  • quoted strings (single and double), whether they get line wrapped or not we should document the behavior in the tests.

Added both; there's no special handling for now, they are wrapped as any other space-separated words.

  • URLs followed by a white space and period. Just make sure not to remove the space.

Added; no special handling, space separates the period into a separate word.

  • HTML markup, white space inside HTML is significant so we should consider leaving it unchanged. Otherwise we may want to consider writing a full blown XML pretty printer.

Added a test but I doubt this is what you had in mind. To support, we need to extend the scaladoc parser in scalameta; there's XmlParser there already but it's not as simple as just using it.

Ideally, if we are to support html, we'd have to parse <ul><li> as list blocks/items, <p>/<br> as paragraph break, <pre> as code, <a href="x">y</a> as [[x y]]. Also, somehow figure out which markup is embedded in text and which has to be split into a separate paragraph or at least surrounded with newlines.

I'd address this in a subsequent version, as that's highly non-trivial.

Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

I agree XML parsing is non-trivial and it's not clear whether it's worth the investment. Just having tests to document the current behavior is a good start.

It might be worth mentioning in the docs that HTML tags are formatted just like normal text, which may produce unexpected output for tables and other large HTML elements.

Copy link
Collaborator Author

@kitbellew kitbellew left a comment

Choose a reason for hiding this comment

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

It might be worth mentioning in the docs that HTML tags are formatted just like normal text, which may produce unexpected output for tables and other large HTML elements.

i have some warning to that effect, please see below; should it be revised?

> This functionality is generally limited to
> [standard scaladoc elements](https://docs.scala-lang.org/overviews/scaladoc/for-library-authors.html)
> and might lead to undesirable results in corner cases;
> for instance, the scaladoc parser doesn't have proper support of embedded HTML.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@olafurpg would you like to amend this statement to say it will be treated as normal text?

Copy link
Member

Choose a reason for hiding this comment

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

This looks good 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

perfect, i will merge.

separately, i will add table support to scalameta and then propagate it here. does this sound reasonable: https://www.scala-lang.org/blog/2018/10/04/scaladoc-tables.html

@NihalJain
Copy link

Hi even after taking latest release i am still seeing issue #1387? Do I need to something more?
Ref scalafmt.conf: https://github.com/apache/hbase-connectors/blob/4b9553c400e3307c224b90238dd1b6f57438284a/dev-support/.scalafmt.conf

@kitbellew
Copy link
Collaborator Author

Hi even after taking latest release i am still seeing issue #1387? Do I need to something more? Ref scalafmt.conf: https://github.com/apache/hbase-connectors/blob/4b9553c400e3307c224b90238dd1b6f57438284a/dev-support/.scalafmt.conf

please submit an issue providing all of the information, including a reproducible example.

@NihalJain
Copy link

Hi even after taking latest release i am still seeing issue #1387? Do I need to something more? Ref scalafmt.conf: https://github.com/apache/hbase-connectors/blob/4b9553c400e3307c224b90238dd1b6f57438284a/dev-support/.scalafmt.conf

please submit an issue providing all of the information, including a reproducible example.

Thanks for replying. Sure will raise one soon.

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.

Scalafmt Doesn't Wrap Lines in Comments Newline after scaladoc annotation

3 participants