From efb204a7979077b6ffd1cc8eab5c4e3120a87b7c Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Wed, 5 Jan 2022 08:43:05 -0800 Subject: [PATCH] Scalameta: upgrade to 4.4.32 (scaladoc fixes) --- project/Dependencies.scala | 2 +- .../org/scalafmt/internal/FormatWriter.scala | 34 +-- .../src/test/resources/test/JavaDoc.stat | 228 ++++++++++-------- 3 files changed, 140 insertions(+), 124 deletions(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index c92ab966ff..fea3755708 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -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" diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala index 89ed1c6856..9eaca8340a 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala @@ -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() @@ -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() + 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 @@ -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() } @@ -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) } @@ -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) @@ -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)) @@ -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 = { diff --git a/scalafmt-tests/src/test/resources/test/JavaDoc.stat b/scalafmt-tests/src/test/resources/test/JavaDoc.stat index bfec2ea224..df7bd7e2b5 100644 --- a/scalafmt-tests/src/test/resources/test/JavaDoc.stat +++ b/scalafmt-tests/src/test/resources/test/JavaDoc.stat @@ -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 */ } @@ -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 */ } @@ -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 */ } @@ -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 */ } @@ -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 */ } @@ -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 */ } @@ -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 @@ -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