Skip to content

Commit

Permalink
FormatWriter: remove any trailing scaladoc space
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 29, 2025
1 parent 812cba5 commit 4b5b3c6
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ class FormatWriter(formatOps: FormatOps) {
replaceRedundantBraces(result)
}

new FormatLocations(result, if (useCRLF > 0) "\r\n" else "\n", if (useCRLF > 0) " \t\r\n" else "\n")
new FormatLocations(
result,
if (useCRLF > 0) "\r\n" else "\n",
if (useCRLF > 0) " \t\r\n" else "\n",
)
}

private def replaceRedundantBraces(locations: Array[FormatLocation]): Unit = {
Expand Down Expand Up @@ -395,7 +399,11 @@ class FormatWriter(formatOps: FormatOps) {
}
}

class FormatLocations(val locations: Array[FormatLocation], val eol: String, val eolDoc: String) {
class FormatLocations(
val locations: Array[FormatLocation],
val eol: String,
val eolDoc: String,
) {

val tokenAligns: Map[Int, Int] = alignmentTokens

Expand All @@ -415,7 +423,7 @@ class FormatWriter(formatOps: FormatOps) {
else eol * (1 + extra)

private[internal] def startNewLine(indent: String)(implicit
sb: StringBuilder,
sb: StringBuilder,
) = sb.append(eol).append(indent)

private[internal] def startNewLineDoc(indent: String)(implicit
Expand Down Expand Up @@ -909,7 +917,7 @@ class FormatWriter(formatOps: FormatOps) {
appendBreak()
case t: Scaladoc.Tag =>
sb.append(t.tag.tag)
t.label.foreach(x => sb.append(' ').append(x.syntax))
t.label.foreach(x => sb.append(' ').append(x.text))
if (t.desc.isEmpty) appendBreak()
else {
val tagIndent = getIndentation(2 + termIndent.length)
Expand Down Expand Up @@ -954,13 +962,13 @@ class FormatWriter(formatOps: FormatOps) {
val wf = new WordFormatter(appendBreak, termIndent, likeNonText)
val wordIter = text.parts.iterator.buffered
val words = wordIter.map { info =>
val text = info.part.syntax
val text = info.part.text
wordIter.headOption match {
case Some(next) if next.attachedToPrevious =>
val partsb = new StringBuilder()
partsb.append(text)
while ({ // poor man's do-while
partsb.append(wordIter.next().part.syntax)
partsb.append(wordIter.next().part.text)
wordIter.headOption.exists(_.attachedToPrevious)
}) {}
partsb.result()
Expand Down Expand Up @@ -1966,4 +1974,13 @@ object FormatWriter {
def isEmptyDocstring(text: String): Boolean = emptyDocstring.matcher(text)
.matches()

implicit class ImplicitScaladocTextPart(private val obj: Scaladoc.TextPart)
extends AnyVal {
def text: String = {
val syntax = obj.syntax // XXX: java 11 has .stripTrailing
val nonws = syntax.lastIndexWhere(!_.isWhitespace)
if (nonws < 0) syntax else syntax.substring(0, nonws + 1)
}
}

}

0 comments on commit 4b5b3c6

Please sign in to comment.