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

Scalameta: upgrade to 4.4.32 (scaladoc fixes) #3054

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._

object Dependencies {
val metaconfigV = "0.9.15"
val scalametaV = "4.4.31"
val scalametaV = "4.4.32"
val scalacheckV = "1.15.4"
val coursier = "1.0.3"
val munitV = "0.7.29"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ class FormatWriter(formatOps: FormatOps) {
}
val paras = doc.para.iterator
paras.foreach { para =>
para.term.foreach {
para.terms.foreach {
formatTerm(_, margin, sbNonEmpty = sb.length != sbLen)
}
if (paras.hasNext) appendBreak()
Expand Down Expand Up @@ -931,18 +931,10 @@ class FormatWriter(formatOps: FormatOps) {
case t: Scaladoc.Tag =>
sb.append(t.tag.tag)
t.label.foreach(x => sb.append(' ').append(x.syntax))
t.desc match {
case Some(x: Scaladoc.Text) if t.tag.tag == "@usecase" =>
// scaladoc parser doesn't allow newlines in @usecase
val words = x.part.iterator.map(_.syntax)
words.foreach(sb.append(' ').append(_))
appendBreak()
case Some(x: Scaladoc.Text) =>
appendBreak()
val tagMargin = getIndentation(2 + termIndent.length)
sb.append(tagMargin)
formatTextAfterMargin(x, tagMargin)
case _ => appendBreak()
appendBreak()
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this not break for @usecase ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it will not, @dos65 and i changed tags with a label and no description to behave like usecase and take the entire line rather than single word.

if (t.desc.nonEmpty) {
val tagIndent = getIndentation(2 + termIndent.length)
t.desc.foreach(formatTerm(_, tagIndent, sbNonEmpty = true))
}
case t: Scaladoc.ListBlock =>
// outputs margin space and appends new line, too
Expand Down Expand Up @@ -980,7 +972,7 @@ class FormatWriter(formatOps: FormatOps) {
}

val wf = new WordFormatter(appendBreak, termIndent, prefixFirstWord)
val words = text.part.iterator.map(_.syntax)
val words = text.parts.iterator.map(_.syntax)
wf(words, termIndent.length, true, false)
appendBreak()
}
Expand Down Expand Up @@ -1052,7 +1044,7 @@ class FormatWriter(formatOps: FormatOps) {
)(block: Scaladoc.ListBlock): Unit = {
val prefix = block.prefix
val itemIndent = getIndentation(listIndent.length + prefix.length + 1)
block.item.foreach { x =>
block.items.foreach { x =>
sb.append(listIndent).append(prefix).append(' ')
formatListTerm(itemIndent)(x)
}
Expand All @@ -1062,19 +1054,19 @@ class FormatWriter(formatOps: FormatOps) {
itemIndent: String
)(item: Scaladoc.ListItem): Unit = {
formatTextAfterMargin(item.text, itemIndent)
item.nested.foreach(formatListBlock(itemIndent))
item.terms.foreach(formatTerm(_, itemIndent, sbNonEmpty = true))
}

private def formatTable(
table: Scaladoc.Table,
termIndent: String
): Unit = {
val rows = table.row.view :+ table.header
val rows = table.rows.view :+ table.header
val align = table.align
val maxCols = rows.map(_.col.length).max
val maxCols = rows.map(_.cols.length).max
val colsRange = 0 until maxCols
val maxLengths = colsRange.map { x =>
rows.collect { case r if r.col.length > x => r.col(x).length }.max
rows.collect { case r if r.cols.length > x => r.cols(x).length }.max
}

@inline def beforeAll: Unit = sb.append(termIndent)
Expand All @@ -1090,7 +1082,7 @@ class FormatWriter(formatOps: FormatOps) {

def formatRow(useMargin: Boolean)(row: Scaladoc.Table.Row): Unit =
formatCols(useMargin) { col =>
val cell = if (col < row.col.length) row.col(col) else ""
val cell = if (col < row.cols.length) row.cols(col) else ""
val pad = maxLengths(col) - cell.length
val lpad = getAlign(col).leftPad(pad)
sb.append(getIndentation(1 + lpad))
Expand All @@ -1101,7 +1093,7 @@ class FormatWriter(formatOps: FormatOps) {
formatCols(true) { col =>
sb.append(getAlign(col).syntax(maxLengths(col)))
}
table.row.foreach(formatRow(true))
table.rows.foreach(formatRow(true))
}

private def formatNoWrap: Unit = {
Expand Down
228 changes: 126 additions & 102 deletions scalafmt-tests/src/test/resources/test/JavaDoc.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1036,20 +1036,26 @@ object a {

/**
* 1. foo
* {{{
* {{{
* embedded code
* }}}
* - foo1
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* foo2
* {{{
* }}}
* - foo1
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* - foo2
* {{{
* embedded code
* }}}
* \``` code foo2 ``` ```
* code foo1 ``` ``` code
* foo ```
* }}}
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo
* ```
* 1. bar
*/
}
Expand Down Expand Up @@ -1087,20 +1093,26 @@ object a {
object a {

/** 1. foo
* {{{
* {{{
* embedded code
* }}}
* - foo1
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* foo2
* {{{
* }}}
* - foo1
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* - foo2
* {{{
* embedded code
* }}}
* \``` code foo2 ``` ```
* code foo1 ``` ``` code
* foo ```
* }}}
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo
* ```
* 1. bar
*/
}
Expand Down Expand Up @@ -1139,20 +1151,26 @@ object a {

/**
* 1. foo
* {{{
* {{{
* embedded code
* }}}
* - foo1
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* foo2
* {{{
* }}}
* - foo1
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* - foo2
* {{{
* embedded code
* }}}
* \``` code foo2 ``` ```
* code foo1 ``` ``` code
* foo ```
* }}}
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo
* ```
* 1. bar
*/
}
Expand Down Expand Up @@ -1199,28 +1217,30 @@ object a {

/**
* @param foo
* {{{
* {{{
* embedded code
* }}}
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* {{{
* }}}
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* {{{
* embedded code
* }}}
* \``` code foo5 ``` ```
* code foo4 ``` ``` code
* foo3 ```
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo0
* ```
* foo
* }}}
* \``` code foo5 ``` ```
* code foo4 ```
* ```
* code foo3
* ```
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo0
* ```
* foo
* @inheritdoc
*/
}
Expand Down Expand Up @@ -1266,28 +1286,30 @@ object a {
object a {

/** @param foo
* {{{
* {{{
* embedded code
* }}}
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* {{{
* }}}
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* {{{
* embedded code
* }}}
* \``` code foo5 ``` ```
* code foo4 ``` ``` code
* foo3 ```
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo0
* ```
* foo
* }}}
* \``` code foo5 ``` ```
* code foo4 ```
* ```
* code foo3
* ```
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo0
* ```
* foo
* @inheritdoc
*/
}
Expand Down Expand Up @@ -1333,28 +1355,30 @@ object a {
object a {

/** @param foo
* {{{
* {{{
* embedded code
* }}}
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* {{{
* }}}
* | hdr1 | hdr22 |
* |:-----|------:|
* | r1 1 | r1 2 |
* {{{
* embedded code
* }}}
* \``` code foo5 ``` ```
* code foo4 ``` ``` code
* foo3 ```
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo0
* ```
* foo
* }}}
* \``` code foo5 ``` ```
* code foo4 ```
* ```
* code foo3
* ```
* ```
* code foo2
* ```
* ```
* code foo1
* ```
* ```
* code foo0
* ```
* foo
* @inheritdoc
*/
}
Expand Down Expand Up @@ -2438,10 +2462,10 @@ object a {
* to help clarify.
*
* @example
* {{{
* {{{
* {"errors":["error1", "error2", "error3"]}
* {"errors":[{"code":"1","message":"error1"},{"code":"2","message":"error2"},{"code":"3","message":"error3"}]}
* }}}
* }}}
*/
}
<<< SM#2444 tag with markdown code block
Expand All @@ -2467,10 +2491,10 @@ object a {
* to help clarify.
*
* @example
* ```scala
* {"errors":["error1", "error2", "error3"]}
* {"errors":[{"code":"1","message":"error1"},{"code":"2","message":"error2"},{"code":"3","message":"error3"}]}
* ```
* ```scala
* {"errors":["error1", "error2", "error3"]}
* {"errors":[{"code":"1","message":"error1"},{"code":"2","message":"error2"},{"code":"3","message":"error3"}]}
* ```
*/
}
<<< indents within markdown code block, Asterisk
Expand Down