Fix resolution of * on String

This commit is contained in:
Adrien Piquerez 2024-02-07 11:47:22 +01:00
parent 4b59b56785
commit e18ddb1666
5 changed files with 7 additions and 13 deletions

View File

@ -377,6 +377,7 @@ trait ParserMain {
implicit def literalRichCharParser(c: Char): RichParser[Char] = richParser(c)
implicit def literalRichStringParser(s: String): RichParser[String] = richParser(s)
extension (s: String) def *(n: Int): String = augmentString(s).*(n)
/**
* Construct a parser that is valid, but has no valid result. This is used as a way to provide a

View File

@ -8,8 +8,6 @@
package sbt.internal.util
package complete
import scala.collection.StringOps
object JLineTest {
import DefaultParsers._
@ -155,12 +153,12 @@ object ParserExample {
val an = repeat(a, min = n, max = n)
val ann = aqn ~ an
def r = apply(ann)(new StringOps("a") * (n * 2)).resultEmpty
def r = apply(ann)("a" * (n * 2)).resultEmpty
println(r.isValid)
}
def run2(n: Int): Unit = {
val ab = "ab".?.*
val r = apply(ab)(new StringOps("a") * n).resultEmpty
val r = apply(ab)("a" * n).resultEmpty
println(r)
}
}

View File

@ -9,7 +9,6 @@ package sbt
import java.io.File
import java.util.regex.{ Pattern, PatternSyntaxException }
import scala.collection.immutable.StringOps
import sbt.internal.util.AttributeKey
import sbt.internal.util.complete.Parser
@ -43,7 +42,7 @@ object CommandUtil {
for ((a, b) <- in) yield pre + fill(a, width) + sep + b
}
def fill(s: String, size: Int): String = s + StringOps(" ") * math.max(size - s.length, 0)
def fill(s: String, size: Int): String = s + " " * math.max(size - s.length, 0)
def withAttribute[T](s: State, key: AttributeKey[T], ifMissing: String)(f: T => State): State =
s get key match {

View File

@ -13,13 +13,12 @@ import sbt.internal.util.complete.Parser
object MultiParserSpec {
val parser: Parser[Seq[String]] = BasicCommands.multiParserImpl(None)
implicit class StringOps(val s: String) {
extension (s: String)
def parse: Seq[String] = Parser.parse(s, parser) match {
case Right(x) => x
case Left(x) => sys.error(s)
}
def parseEither: Either[String, Seq[String]] = Parser.parse(s, parser)
}
}
import sbt.MultiParserSpec._
class MultiParserSpec extends AnyFlatSpec {

View File

@ -26,7 +26,6 @@ import sbt.util.{ Level, Logger }
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable.StringOps
import scala.concurrent.duration._
import scala.util.control.NonFatal
@ -506,9 +505,7 @@ object Watch {
val opts = distinctOptions(options).sortBy(_.input)
val alignmentLength = opts.map(_.display.length).max + 1
val formatted =
opts.map(o =>
s"${o.display}${StringOps(" ") * (alignmentLength - o.display.length)}: ${o.description}"
)
opts.map(o => s"${o.display}${" " * (alignmentLength - o.display.length)}: ${o.description}")
s"Options:\n${formatted.mkString(" ", "\n ", "")}"
}
private def distinctOptions(options: Seq[InputOption]): Seq[InputOption] = {
@ -539,7 +536,7 @@ object Watch {
{
val countStr = s"$count. "
Some(s"$countStr${waitMessage(project, commands)
.mkString(s"\n${StringOps(" ") * countStr.length}")}")
.mkString(s"\n${" " * countStr.length}")}")
}
}.label("Watched.defaultStartWatch")