use `given` instead of `implicit val`

This commit is contained in:
xuwei-k 2024-11-17 08:28:38 +09:00 committed by kenji yoshida
parent c572453a35
commit c5b7038f3a
40 changed files with 94 additions and 101 deletions

View File

@ -17,7 +17,7 @@ import sbt.internal.inc.PlainVirtualFileConverter
object NewFormatSpec extends AbstractSpec {
val converter = PlainVirtualFileConverter.converter
implicit val splitter: SplitExpressions.SplitExpression = EvaluateConfigurations.splitExpressions
given splitter: SplitExpressions.SplitExpression = EvaluateConfigurations.splitExpressions
test("New Format should handle lines") {
val rootPath = getClass.getResource("/new-format").getPath

View File

@ -12,10 +12,10 @@ import java.util.concurrent.Callable
trait GlobalLockFormat { self: BasicJsonProtocol =>
import GlobalLockFormats._
implicit lazy val globalLockIsoString: IsoString[GlobalLock] =
given globalLockIsoString: IsoString[GlobalLock] =
IsoString.iso(_ => "<lock>", _ => NoGlobalLock)
implicit lazy val GlobalLockFormat: JsonFormat[GlobalLock] = isoStringFormat(using
given GlobalLockFormat: JsonFormat[GlobalLock] = isoStringFormat(using
globalLockIsoString
)
}

View File

@ -9,8 +9,8 @@ import sbt.util.Logger.Null
* This is mostly for making IvyConfiguration serializable to JSON.
*/
trait LoggerFormat { self: BasicJsonProtocol =>
implicit lazy val xsbtiLoggerIsoString: IsoString[Logger] =
given xsbtiLoggerIsoString: IsoString[Logger] =
IsoString.iso(_ => "<logger>", _ => Null)
implicit lazy val LoggerFormat: JsonFormat[Logger] = isoStringFormat(using implicitly)
given LoggerFormat: JsonFormat[Logger] = isoStringFormat(using implicitly)
}

View File

@ -5,7 +5,7 @@ import sjsonnew._
import sbt.librarymanagement.LogicalClock
trait LogicalClockFormats { self: BasicJsonProtocol =>
implicit lazy val LogicalClockFormat: JsonFormat[LogicalClock] =
given LogicalClockFormat: JsonFormat[LogicalClock] =
projectFormat[LogicalClock, String](
cl => cl.toString,
str => LogicalClock(str)

View File

@ -4,7 +4,7 @@ import sjsonnew._
import scala.xml._
trait NodeSeqFormat { self: BasicJsonProtocol =>
implicit lazy val NodeSeqFormat: JsonFormat[NodeSeq] = projectFormat[NodeSeq, String](
given NodeSeqFormat: JsonFormat[NodeSeq] = projectFormat[NodeSeq, String](
xml => <binary>{xml}</binary>.toString,
str => XML.loadString(str).child
)

View File

@ -6,7 +6,7 @@ package sbt.librarymanagement
import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait ConfigRefFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val ConfigRefFormat: JsonFormat[sbt.librarymanagement.ConfigRef] =
given ConfigRefFormat: JsonFormat[sbt.librarymanagement.ConfigRef] =
new JsonFormat[sbt.librarymanagement.ConfigRef] {
override def read[J](
__jsOpt: Option[J],

View File

@ -8,7 +8,7 @@ import _root_.sjsonnew.{ deserializationError, Builder, JsonFormat, Unbuilder }
trait ConfigurationFormats {
self: sbt.librarymanagement.ConfigurationFormats & sjsonnew.BasicJsonProtocol =>
implicit lazy val ConfigurationFormat: JsonFormat[sbt.librarymanagement.Configuration] =
given ConfigurationFormat: JsonFormat[sbt.librarymanagement.Configuration] =
new JsonFormat[sbt.librarymanagement.Configuration] {
override def read[J](
jsOpt: Option[J],

View File

@ -249,7 +249,7 @@ object For2_13Use3 {
}
trait DisabledFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val DisabledFormat: JsonFormat[sbt.librarymanagement.Disabled] =
given DisabledFormat: JsonFormat[sbt.librarymanagement.Disabled] =
new JsonFormat[sbt.librarymanagement.Disabled] {
override def read[J](
jsOpt: Option[J],
@ -272,7 +272,7 @@ trait DisabledFormats { self: sjsonnew.BasicJsonProtocol =>
}
}
implicit lazy val DisabledObjectFormat: JsonFormat[sbt.librarymanagement.Disabled.type] =
given DisabledObjectFormat: JsonFormat[sbt.librarymanagement.Disabled.type] =
new JsonFormat[sbt.librarymanagement.Disabled.type] {
override def read[J](
jsOpt: Option[J],
@ -297,7 +297,7 @@ trait DisabledFormats { self: sjsonnew.BasicJsonProtocol =>
}
trait BinaryFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val BinaryFormat: JsonFormat[sbt.librarymanagement.Binary] =
given BinaryFormat: JsonFormat[sbt.librarymanagement.Binary] =
new JsonFormat[sbt.librarymanagement.Binary] {
override def read[J](
jsOpt: Option[J],
@ -324,7 +324,7 @@ trait BinaryFormats { self: sjsonnew.BasicJsonProtocol =>
}
trait ConstantFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val ConstantFormat: JsonFormat[sbt.librarymanagement.Constant] =
given ConstantFormat: JsonFormat[sbt.librarymanagement.Constant] =
new JsonFormat[sbt.librarymanagement.Constant] {
override def read[J](
jsOpt: Option[J],
@ -349,7 +349,7 @@ trait ConstantFormats { self: sjsonnew.BasicJsonProtocol =>
}
trait PatchFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val PatchFormat: JsonFormat[sbt.librarymanagement.Patch] =
given PatchFormat: JsonFormat[sbt.librarymanagement.Patch] =
new JsonFormat[sbt.librarymanagement.Patch] {
override def read[J](
jsOpt: Option[J],
@ -374,7 +374,7 @@ trait PatchFormats { self: sjsonnew.BasicJsonProtocol =>
}
trait FullFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val FullFormat: JsonFormat[sbt.librarymanagement.Full] =
given FullFormat: JsonFormat[sbt.librarymanagement.Full] =
new JsonFormat[sbt.librarymanagement.Full] {
override def read[J](
jsOpt: Option[J],
@ -401,7 +401,7 @@ trait FullFormats { self: sjsonnew.BasicJsonProtocol =>
}
trait For3Use2_13Formats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val For3Use2_13Format: JsonFormat[sbt.librarymanagement.For3Use2_13] =
given For3Use2_13Format: JsonFormat[sbt.librarymanagement.For3Use2_13] =
new JsonFormat[sbt.librarymanagement.For3Use2_13] {
override def read[J](
jsOpt: Option[J],
@ -428,7 +428,7 @@ trait For3Use2_13Formats { self: sjsonnew.BasicJsonProtocol =>
}
trait For2_13Use3Formats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val For2_13Use3Format: JsonFormat[sbt.librarymanagement.For2_13Use3] =
given For2_13Use3Format: JsonFormat[sbt.librarymanagement.For2_13Use3] =
new JsonFormat[sbt.librarymanagement.For2_13Use3] {
override def read[J](
jsOpt: Option[J],
@ -459,7 +459,7 @@ trait CrossVersionFormats {
sbt.librarymanagement.BinaryFormats & sbt.librarymanagement.ConstantFormats &
sbt.librarymanagement.PatchFormats & sbt.librarymanagement.FullFormats &
sbt.librarymanagement.For3Use2_13Formats & sbt.librarymanagement.For2_13Use3Formats =>
implicit lazy val CrossVersionFormat: JsonFormat[CrossVersion] = {
given CrossVersionFormat: JsonFormat[CrossVersion] = {
val format = flatUnionFormat8[
CrossVersion,
Disabled,

View File

@ -213,7 +213,7 @@ final class EvictionPair private[sbt] (
}
object EvictionPair {
implicit val evictionPairLines: ShowLines[EvictionPair] = ShowLines { (a: EvictionPair) =>
given evictionPairLines: ShowLines[EvictionPair] = ShowLines { (a: EvictionPair) =>
val seen: mutable.Set[ModuleID] = mutable.Set()
val callers: List[String] = (a.evicteds.toList ::: a.winner.toList) flatMap { r =>
val rev = r.module.revision

View File

@ -55,7 +55,7 @@ object UnresolvedWarning {
case Some(RangePosition(path, LineRange(start, end))) => s" ($path#L$start-$end)"
case _ => ""
}
implicit val unresolvedWarningLines: ShowLines[UnresolvedWarning] = ShowLines { a =>
given unresolvedWarningLines: ShowLines[UnresolvedWarning] = ShowLines { a =>
val withExtra = a.resolveException.failed.filter(_.extraDependencyAttributes.nonEmpty)
val buffer = mutable.ListBuffer[String]()
if (withExtra.nonEmpty) {

View File

@ -408,8 +408,7 @@ final class IvySbt(
)
// Redefine to use a subset of properties, that are serialisable
override implicit lazy val InlineIvyConfigurationFormat
: JsonFormat[InlineIvyConfiguration] = {
override given InlineIvyConfigurationFormat: JsonFormat[InlineIvyConfiguration] = {
def hlToInlineIvy(i: InlineIvyHL): InlineIvyConfiguration = {
val (
paths,
@ -431,8 +430,7 @@ final class IvySbt(
}
// Redefine to use a subset of properties, that are serialisable
override implicit lazy val ExternalIvyConfigurationFormat
: JsonFormat[ExternalIvyConfiguration] = {
override given ExternalIvyConfigurationFormat: JsonFormat[ExternalIvyConfiguration] = {
def hlToExternalIvy(e: ExternalIvyHL): ExternalIvyConfiguration = {
val (baseDirectory, _) = e
ExternalIvyConfiguration(
@ -448,7 +446,7 @@ final class IvySbt(
}
// Redefine to switch to unionFormat
override implicit lazy val IvyConfigurationFormat: JsonFormat[IvyConfiguration] =
override given IvyConfigurationFormat: JsonFormat[IvyConfiguration] =
unionFormat2[IvyConfiguration, InlineIvyConfiguration, ExternalIvyConfiguration]
object NullLogger extends sbt.internal.util.BasicLogger {
@ -461,7 +459,7 @@ final class IvySbt(
}
def extraInputHash: Long = {
import AltLibraryManagementCodec._
import AltLibraryManagementCodec.given
Hasher.hash(owner.configuration) match {
case Success(keyHash) => keyHash.toLong
case Failure(_) => 0L

View File

@ -21,7 +21,7 @@ trait UpdateOptionsFormat {
sbt.librarymanagement.PasswordAuthenticationFormats &
sbt.librarymanagement.KeyFileAuthenticationFormats =>
/* This is necessary to serialize/deserialize `directResolvers`. */
private implicit val moduleIdJsonKeyFormat: sjsonnew.JsonKeyFormat[ModuleID] = {
private given moduleIdJsonKeyFormat: sjsonnew.JsonKeyFormat[ModuleID] = {
new sjsonnew.JsonKeyFormat[ModuleID] {
import sjsonnew.support.scalajson.unsafe._
val moduleIdFormat: JsonFormat[ModuleID] = implicitly[JsonFormat[ModuleID]]
@ -32,7 +32,7 @@ trait UpdateOptionsFormat {
}
}
implicit lazy val UpdateOptionsFormat: JsonFormat[UpdateOptions] =
given UpdateOptionsFormat: JsonFormat[UpdateOptions] =
projectFormat(
(uo: UpdateOptions) =>
(

View File

@ -6,7 +6,7 @@ import java.io.File
import sbt.librarymanagement._
import sjsonnew.shaded.scalajson.ast.unsafe._
import sjsonnew._, support.scalajson.unsafe._
import LibraryManagementCodec._
import LibraryManagementCodec.given
import verify.BasicTestSuite
object DMSerializationSpec extends BasicTestSuite {
@ -105,6 +105,6 @@ object DMSerializationSpec extends BasicTestSuite {
f(a, obj)
}
implicit val isoString: IsoString[JValue] =
given isoString: IsoString[JValue] =
IsoString.iso(CompactPrinter.apply, Parser.parseUnsafe)
}

View File

@ -55,13 +55,13 @@ class CacheIvyTest extends Properties("CacheIvy") {
eq(out, m) :| s"Expected: ${str(m)}" :| s"Got: ${str(out)}"
}
implicit val arbConfigRef: Arbitrary[ConfigRef] = Arbitrary(
given arbConfigRef: Arbitrary[ConfigRef] = Arbitrary(
for {
n <- Gen.alphaStr
} yield ConfigRef(n)
)
implicit val arbExclusionRule: Arbitrary[InclExclRule] = Arbitrary(
given arbExclusionRule: Arbitrary[InclExclRule] = Arbitrary(
for {
o <- Gen.alphaStr
n <- Gen.alphaStr
@ -71,18 +71,18 @@ class CacheIvyTest extends Properties("CacheIvy") {
} yield InclExclRule(o, n, a, cs.toVector, v)
)
implicit val arbCrossVersion: Arbitrary[CrossVersion] = Arbitrary {
given arbCrossVersion: Arbitrary[CrossVersion] = Arbitrary {
// Actual functions don't matter, just Disabled vs Binary vs Full
Gen.oneOf(Disabled(), Binary(), Full())
}
implicit val arbArtifact: Arbitrary[Artifact] = Arbitrary {
given arbArtifact: Arbitrary[Artifact] = Arbitrary {
for {
(n, t, e, cls) <- arbitrary[(String, String, String, String)]
} yield Artifact(n, t, e, cls) // keep it simple
}
implicit val arbModuleID: Arbitrary[ModuleID] = Arbitrary {
given arbModuleID: Arbitrary[ModuleID] = Arbitrary {
for {
o <- Gen.identifier
n <- Gen.identifier

View File

@ -79,15 +79,15 @@ object RootProject {
def apply(base: File): RootProject = RootProject(IO toURI base)
}
object Reference {
implicit val resolvedReferenceOrdering: Ordering[ResolvedReference] = {
given resolvedReferenceOrdering: Ordering[ResolvedReference] = {
case (ba: BuildRef, bb: BuildRef) => buildRefOrdering.compare(ba, bb)
case (pa: ProjectRef, pb: ProjectRef) => projectRefOrdering.compare(pa, pb)
case (_: BuildRef, _: ProjectRef) => -1
case (_: ProjectRef, _: BuildRef) => 1
}
implicit val buildRefOrdering: Ordering[BuildRef] = (a, b) => a.build.compareTo(b.build)
given buildRefOrdering: Ordering[BuildRef] = (a, b) => a.build.compareTo(b.build)
implicit val projectRefOrdering: Ordering[ProjectRef] = (a, b) => {
given projectRefOrdering: Ordering[ProjectRef] = (a, b) => {
val bc = a.build.compareTo(b.build)
if bc == 0 then a.project.compareTo(b.project) else bc
}

View File

@ -269,8 +269,8 @@ private[sbt] object Continuous extends DeprecatedContinuous {
dynamicInputs: mutable.Set[DynamicInput],
context: LoggerContext
): Callbacks = {
implicit val extracted: Extracted = Project.extract(s)
implicit val logger: Logger =
given extracted: Extracted = Project.extract(s)
given logger: Logger =
context.logger(channel.name + "-watch", None, None)
validateCommands(s, commands)
val configs = getAllConfigs(s, commands, dynamicInputs)

View File

@ -21,7 +21,7 @@ private[sbt] final case class DynamicInput(
)
private[sbt] object DynamicInput {
implicit object ordering extends Ordering[DynamicInput] {
private implicit val globOrdering: Ordering[Glob] = Glob.ordering
private given globOrdering: Ordering[Glob] = Glob.ordering
private implicit object fileStamperOrdering extends Ordering[FileStamper] {
override def compare(left: FileStamper, right: FileStamper): Int = left match {
case FileStamper.Hash =>

View File

@ -83,7 +83,7 @@ object FileChangesMacro:
val ts: Scope = $taskScope
val changes = rescope[Seq[(NioPath, FileStamp)] => FileChanges](ts, $changeKey).value
val current = rescope[Seq[NioPath]](ts, $currentKey).value
import sbt.nio.FileStamp.Formats.*
import sbt.nio.FileStamp.Formats.given
val previous =
Previous.runtimeInEnclosingTask(rescope[Seq[(NioPath, FileStamp)]](ts, $mapKey)).value
previous.map(changes).getOrElse(FileChanges.noPrevious(current))

View File

@ -25,7 +25,7 @@ import scala.concurrent.duration.FiniteDuration
import scala.annotation.nowarn
private[sbt] object LibraryManagement {
implicit val linter: sbt.dsl.LinterLevel.Ignore.type = sbt.dsl.LinterLevel.Ignore
given linter: sbt.dsl.LinterLevel.Ignore.type = sbt.dsl.LinterLevel.Ignore
private type UpdateInputs = (Long, ModuleSettings, UpdateConfiguration)
@ -382,7 +382,7 @@ private[sbt] object LibraryManagement {
def withExcludes(out: File, classifiers: Seq[String], lock: xsbti.GlobalLock)(
f: Map[ModuleID, Vector[ConfigRef]] => UpdateReport
): UpdateReport = {
import sbt.librarymanagement.LibraryManagementCodec._
import sbt.librarymanagement.LibraryManagementCodec.given
import sbt.util.FileBasedStore
val exclName = "exclude_classifiers"
val file = out / exclName
@ -391,7 +391,7 @@ private[sbt] object LibraryManagement {
out / (exclName + ".lock"),
new Callable[UpdateReport] {
def call = {
implicit val midJsonKeyFmt: sjsonnew.JsonKeyFormat[ModuleID] = moduleIdJsonKeyFormat
given midJsonKeyFmt: sjsonnew.JsonKeyFormat[ModuleID] = moduleIdJsonKeyFormat
val excludes =
store
.read[Map[ModuleID, Vector[ConfigRef]]](

View File

@ -313,7 +313,7 @@ private[sbt] object Definition {
"Problem with processing analyses.",
None,
)
import JsonRPCProtocol._
import JsonRPCProtocol.given
send(commandSource, requestId)(rsp)
}
()

View File

@ -263,7 +263,7 @@ final class NetworkChannel(
pendingRequests -= request.id
jsonRpcRespondError(request.id, err)
case _ =>
import sbt.internal.protocol.codec.JsonRPCProtocol._
import sbt.internal.protocol.codec.JsonRPCProtocol.given
val msg =
s"unmatched json error for requestId $execId: ${CompactPrinter(Converter.toJsonUnsafe(err))}"
log.debug(msg)

View File

@ -115,16 +115,16 @@ object FileStamp {
case FileStamp.LastModified(_) => Digest.sha256Hash(path)
object Formats {
implicit val seqPathJsonFormatter: JsonFormat[Seq[Path]] =
given seqPathJsonFormatter: JsonFormat[Seq[Path]] =
asStringArray(_.toString, Paths.get(_))
implicit val seqFileJsonFormatter: JsonFormat[Seq[File]] =
given seqFileJsonFormatter: JsonFormat[Seq[File]] =
asStringArray(_.toString, new File(_))
implicit val seqVirtualFileRefJsonFormatter: JsonFormat[Seq[VirtualFileRef]] =
given seqVirtualFileRefJsonFormatter: JsonFormat[Seq[VirtualFileRef]] =
asStringArray(_.id, VirtualFileRef.of)
implicit val fileJsonFormatter: JsonFormat[File] = fromSeqJsonFormat[File]
implicit val pathJsonFormatter: JsonFormat[Path] = fromSeqJsonFormat[Path]
implicit val virtualFileRefJsonFormatter: JsonFormat[VirtualFileRef] =
given fileJsonFormatter: JsonFormat[File] = fromSeqJsonFormat[File]
given pathJsonFormatter: JsonFormat[Path] = fromSeqJsonFormat[Path]
given virtualFileRefJsonFormatter: JsonFormat[VirtualFileRef] =
fromSeqJsonFormat[VirtualFileRef]
private def asStringArray[T](toStr: T => String, fromStr: String => T): JsonFormat[Seq[T]] =
@ -158,7 +158,7 @@ object FileStamp {
seqJsonFormat.write(obj :: Nil, builder)
}
implicit val seqPathFileStampJsonFormatter: JsonFormat[Seq[(Path, FileStamp)]] =
given seqPathFileStampJsonFormatter: JsonFormat[Seq[(Path, FileStamp)]] =
new JsonFormat[Seq[(Path, FileStamp)]] {
override def write[J](obj: Seq[(Path, FileStamp)], builder: Builder[J]): Unit = {
val (hashes, lastModifiedTimes) = obj.partition(_._2.isInstanceOf[Hash])

View File

@ -18,7 +18,7 @@ import sbt.internal.Clean.ToSeqPath
import sbt.internal.Continuous.FileStampRepository
import sbt.internal.util.KeyTag
import sbt.internal.{ Clean, Continuous, DynamicInput, WatchTransitiveDependencies }
import sbt.nio.FileStamp.Formats._
import sbt.nio.FileStamp.Formats.given
import sbt.nio.FileStamper.{ Hash, LastModified }
import sbt.nio.Keys._
import sbt.nio.file.{ AllPass, FileAttributes, Glob, RecursiveGlob }

View File

@ -22,7 +22,7 @@ class FileStampJsonSpec extends AnyFlatSpec {
Paths.get("foo") -> FileStamp.hash("bar"),
Paths.get("bar") -> FileStamp.hash("buzz")
)
implicit val formatter: JsonFormat[Seq[(Path, FileStamp.Hash)]] =
given formatter: JsonFormat[Seq[(Path, FileStamp.Hash)]] =
Formats.seqPathHashJsonFormatter
val json = Converter.toJsonUnsafe(hashes)
val deserialized = Converter.fromJsonUnsafe(json)
@ -33,7 +33,7 @@ class FileStampJsonSpec extends AnyFlatSpec {
Paths.get("foo") -> FileStamp.LastModified(1234),
Paths.get("bar") -> FileStamp.LastModified(5678)
)
implicit val formatter: JsonFormat[Seq[(Path, FileStamp.LastModified)]] =
given formatter: JsonFormat[Seq[(Path, FileStamp.LastModified)]] =
Formats.seqPathLastModifiedJsonFormatter
val json = Converter.toJsonUnsafe(lastModifiedTimes)
val deserialized = Converter.fromJsonUnsafe(json)

View File

@ -13,7 +13,7 @@ import sjsonnew.shaded.scalajson.ast.unsafe.JValue
trait JsonRpcNotificationMessageFormats {
self: sbt.internal.util.codec.JValueFormats & sjsonnew.BasicJsonProtocol =>
implicit lazy val JsonRpcNotificationMessageFormat
given JsonRpcNotificationMessageFormat
: JsonFormat[sbt.internal.protocol.JsonRpcNotificationMessage] =
new JsonFormat[sbt.internal.protocol.JsonRpcNotificationMessage] {
override def read[J](

View File

@ -13,8 +13,7 @@ import sjsonnew.{ Builder, DeserializationException, JsonFormat, Unbuilder, dese
trait JsonRpcRequestMessageFormats {
self: sbt.internal.util.codec.JValueFormats & sjsonnew.BasicJsonProtocol =>
implicit lazy val JsonRpcRequestMessageFormat
: JsonFormat[sbt.internal.protocol.JsonRpcRequestMessage] =
given JsonRpcRequestMessageFormat: JsonFormat[sbt.internal.protocol.JsonRpcRequestMessage] =
new JsonFormat[sbt.internal.protocol.JsonRpcRequestMessage] {
override def read[J](
jsOpt: Option[J],

View File

@ -13,8 +13,7 @@ import sjsonnew.shaded.scalajson.ast.unsafe.JValue
trait JsonRpcResponseErrorFormats {
self: sbt.internal.util.codec.JValueFormats & sjsonnew.BasicJsonProtocol =>
implicit lazy val JsonRpcResponseErrorFormat
: JsonFormat[sbt.internal.protocol.JsonRpcResponseError] =
given JsonRpcResponseErrorFormat: JsonFormat[sbt.internal.protocol.JsonRpcResponseError] =
new JsonFormat[sbt.internal.protocol.JsonRpcResponseError] {
override def read[J](
jsOpt: Option[J],

View File

@ -20,8 +20,7 @@ import sjsonnew.shaded.scalajson.ast.unsafe._
trait JsonRpcResponseMessageFormats {
self: sbt.internal.util.codec.JValueFormats &
sbt.internal.protocol.codec.JsonRpcResponseErrorFormats & sjsonnew.BasicJsonProtocol =>
implicit lazy val JsonRpcResponseMessageFormat
: JsonFormat[sbt.internal.protocol.JsonRpcResponseMessage] =
given JsonRpcResponseMessageFormat: JsonFormat[sbt.internal.protocol.JsonRpcResponseMessage] =
new JsonFormat[sbt.internal.protocol.JsonRpcResponseMessage] {
override def read[J](
jsOpt: Option[J],

View File

@ -104,13 +104,13 @@ object Serialization {
/** This formats the message according to JSON-RPC. https://www.jsonrpc.org/specification */
private[sbt] def serializeResponseMessage(message: JsonRpcResponseMessage): Array[Byte] = {
import sbt.internal.protocol.codec.JsonRPCProtocol._
import sbt.internal.protocol.codec.JsonRPCProtocol.given
serializeResponse(message)
}
/** This formats the message according to JSON-RPC. https://www.jsonrpc.org/specification */
private[sbt] def serializeRequestMessage(message: JsonRpcRequestMessage): Array[Byte] = {
import sbt.internal.protocol.codec.JsonRPCProtocol._
import sbt.internal.protocol.codec.JsonRPCProtocol.given
serializeResponse(message)
}
@ -118,7 +118,7 @@ object Serialization {
private[sbt] def serializeNotificationMessage(
message: JsonRpcNotificationMessage,
): Array[Byte] = {
import sbt.internal.protocol.codec.JsonRPCProtocol._
import sbt.internal.protocol.codec.JsonRPCProtocol.given
serializeResponse(message)
}
@ -215,7 +215,7 @@ object Serialization {
val buffer = ByteBuffer.wrap(bytes.toArray)
Parser.parseFromByteBuffer(buffer) match {
case Success(json @ JObject(fields)) =>
import sbt.internal.protocol.codec.JsonRPCProtocol._
import sbt.internal.protocol.codec.JsonRPCProtocol.given
if ((fields find { _.field == "method" }).isDefined) {
if ((fields find { _.field == "id" }).isDefined)
Converter.fromJson[JsonRpcRequestMessage](json) match {

View File

@ -49,12 +49,12 @@ package object sbt
* of FileChangesMacro.TaskOps is ever made which is why it is ok to use `???`.
*/
// implicit def taskToTaskOpts[T](t: TaskKey[T]): FileChangesMacro.TaskOps[T] = ???
implicit val fileStampJsonFormatter: JsonFormat[Seq[(NioPath, FileStamp)]] =
given fileStampJsonFormatter: JsonFormat[Seq[(NioPath, FileStamp)]] =
FileStamp.Formats.seqPathFileStampJsonFormatter
implicit val pathJsonFormatter: JsonFormat[Seq[NioPath]] = FileStamp.Formats.seqPathJsonFormatter
implicit val fileJsonFormatter: JsonFormat[Seq[File]] = FileStamp.Formats.seqFileJsonFormatter
implicit val singlePathJsonFormatter: JsonFormat[NioPath] = FileStamp.Formats.pathJsonFormatter
implicit val singleFileJsonFormatter: JsonFormat[File] = FileStamp.Formats.fileJsonFormatter
given pathJsonFormatter: JsonFormat[Seq[NioPath]] = FileStamp.Formats.seqPathJsonFormatter
given fileJsonFormatter: JsonFormat[Seq[File]] = FileStamp.Formats.seqFileJsonFormatter
given singlePathJsonFormatter: JsonFormat[NioPath] = FileStamp.Formats.pathJsonFormatter
given singleFileJsonFormatter: JsonFormat[File] = FileStamp.Formats.fileJsonFormatter
// others
object CompileOrder {

View File

@ -11,7 +11,7 @@ import sbt.internal.bsp.*
import sbt.internal.langserver.ErrorCodes
import sbt.IO
import sbt.internal.protocol.JsonRpcRequestMessage
import sbt.internal.protocol.codec.JsonRPCProtocol.*
import sbt.internal.protocol.codec.JsonRPCProtocol.given
import sjsonnew.JsonWriter
import sjsonnew.support.scalajson.unsafe.{ CompactPrinter, Converter }
@ -24,7 +24,7 @@ import scala.concurrent.duration.*
// starts svr using server-test/buildserver and perform custom server tests
class BuildServerTest extends AbstractServerTest {
import sbt.internal.bsp.codec.JsonProtocol._
import sbt.internal.bsp.codec.JsonProtocol.given
override val testDirectory: String = "buildserver"
private val idGen: AtomicInteger = new AtomicInteger(0)

View File

@ -13,7 +13,7 @@ import sbt.testing.Status
import _root_.sjsonnew.{ deserializationError, Builder, JsonFormat, Unbuilder }
trait StatusFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val StatusFormat: JsonFormat[Status] = new JsonFormat[Status] {
given StatusFormat: JsonFormat[Status] = new JsonFormat[Status] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): Status = {
jsOpt match {
case Some(js) =>

View File

@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger
object TestLogger {
import sbt.protocol.testing.codec.JsonProtocol._
implicit val testStringEventShowLines: ShowLines[TestStringEvent] =
given testStringEventShowLines: ShowLines[TestStringEvent] =
ShowLines[TestStringEvent]({ case a: TestStringEvent =>
List(a.value)
})
@ -74,11 +74,11 @@ object TestLogger {
global.registerStringCodec[TestStringEvent]
def showNoLines[A] = ShowLines[A](_ => Nil)
implicit val showNoLinesTestInitEvent = showNoLines[TestInitEvent]
implicit val showNoLinesStartTestGroupEvent = showNoLines[StartTestGroupEvent]
implicit val showNoLinesTestItemEvent = showNoLines[TestItemEvent]
implicit val showNoLinesEndTestGroupEvent = showNoLines[EndTestGroupEvent]
implicit val showNoLinesTestCompleteEvent = showNoLines[TestCompleteEvent]
given ShowLines[TestInitEvent] = showNoLines[TestInitEvent]
given ShowLines[StartTestGroupEvent] = showNoLines[StartTestGroupEvent]
given ShowLines[TestItemEvent] = showNoLines[TestItemEvent]
given ShowLines[EndTestGroupEvent] = showNoLines[EndTestGroupEvent]
given ShowLines[TestCompleteEvent] = showNoLines[TestCompleteEvent]
global.registerStringCodec[TestInitEvent]
global.registerStringCodec[StartTestGroupEvent]
global.registerStringCodec[TestItemEvent]

View File

@ -17,6 +17,6 @@ trait ByteBufferFormats { self: BasicJsonProtocol =>
def strToByteBuffer(s: String): ByteBuffer =
ByteBuffer.wrap(BUtil.fromHex(s))
implicit lazy val byteBufferIsoString: IsoString[ByteBuffer] =
given byteBufferIsoString: IsoString[ByteBuffer] =
IsoString.iso(byteBufferToStr, strToByteBuffer)
}

View File

@ -24,6 +24,6 @@ trait HashedVirtualFileRefFormats { self: BasicJsonProtocol =>
case _ => throw new RuntimeException(s"invalid HashedVirtualFileRefIsoString $s")
}
implicit lazy val hashedVirtualFileRefIsoString: IsoString[HashedVirtualFileRef] =
given hashedVirtualFileRefIsoString: IsoString[HashedVirtualFileRef] =
IsoString.iso(hashedVirtualFileRefToStr, strToHashedVirtualFileRef)
}

View File

@ -26,6 +26,6 @@ trait BasicCacheImplicits extends HashedVirtualFileRefFormats { self: BasicJsonP
def singleton[T](t: T): SingletonCache[T] =
SingletonCache.basicSingletonCache(using asSingleton(t))
implicit lazy val virtualFileRefIsoString: IsoString[VirtualFileRef] =
given virtualFileRefIsoString: IsoString[VirtualFileRef] =
IsoString.iso(_.id, VirtualFileRef.of)
}

View File

@ -25,8 +25,7 @@ abstract class CacheStore extends Input with Output {
}
object CacheStore {
@deprecated("Create your own IsoString[JValue]", "1.4")
implicit lazy val jvalueIsoString: IsoString[JValue] =
@deprecated("Create your own IsoString[JValue]", "1.4") given jvalueIsoString: IsoString[JValue] =
IsoString.iso(CompactPrinter.apply, Parser.parseUnsafe)
/** Returns file-based CacheStore using standard JSON converter. */
@ -50,8 +49,7 @@ abstract class CacheStoreFactory {
}
object CacheStoreFactory {
@deprecated("Create your own IsoString[JValue]", "1.4")
implicit lazy val jvalueIsoString: IsoString[JValue] =
@deprecated("Create your own IsoString[JValue]", "1.4") given jvalueIsoString: IsoString[JValue] =
IsoString.iso(CompactPrinter.apply, Parser.parseUnsafe)
/** Returns directory-based CacheStoreFactory using standard JSON converter. */

View File

@ -28,16 +28,16 @@ sealed trait PlainFileInfo extends FileInfo { def exists: Boolean }
sealed trait HashModifiedFileInfo extends HashFileInfo with ModifiedFileInfo
object HashFileInfo {
implicit val format: JsonFormat[HashFileInfo] = FileInfo.hash.format
given format: JsonFormat[HashFileInfo] = FileInfo.hash.format
}
object ModifiedFileInfo {
implicit val format: JsonFormat[ModifiedFileInfo] = FileInfo.lastModified.format
given format: JsonFormat[ModifiedFileInfo] = FileInfo.lastModified.format
}
object PlainFileInfo {
implicit val format: JsonFormat[PlainFileInfo] = FileInfo.exists.format
given format: JsonFormat[PlainFileInfo] = FileInfo.exists.format
}
object HashModifiedFileInfo {
implicit val format: JsonFormat[HashModifiedFileInfo] = FileInfo.full.format
given format: JsonFormat[HashModifiedFileInfo] = FileInfo.full.format
}
private final case class PlainFile(file: File, exists: Boolean) extends PlainFileInfo
@ -79,7 +79,7 @@ object FileInfo {
* Stores byte arrays as hex encoded strings, but falls back to reading an array of integers,
* which is how it used to be stored, if that fails.
*/
implicit val byteArrayFormat: JsonFormat[Array[Byte]] = new JsonFormat[Array[Byte]] {
given byteArrayFormat: JsonFormat[Array[Byte]] = new JsonFormat[Array[Byte]] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): Array[Byte] = {
jsOpt match {
case Some(js) =>
@ -115,7 +115,7 @@ object FileInfo {
object full extends Style {
type F = HashModifiedFileInfo
implicit val format: JsonFormat[HashModifiedFileInfo] = new JsonFormat[HashModifiedFileInfo] {
given format: JsonFormat[HashModifiedFileInfo] = new JsonFormat[HashModifiedFileInfo] {
def write[J](obj: HashModifiedFileInfo, builder: Builder[J]) = {
builder.beginObject()
builder.addField("file", obj.file.toString)
@ -145,7 +145,7 @@ object FileInfo {
object hash extends Style {
type F = HashFileInfo
implicit val format: JsonFormat[HashFileInfo] = new JsonFormat[HashFileInfo] {
given format: JsonFormat[HashFileInfo] = new JsonFormat[HashFileInfo] {
def write[J](obj: HashFileInfo, builder: Builder[J]) = {
builder.beginObject()
builder.addField("file", obj.file.toString)
@ -177,7 +177,7 @@ object FileInfo {
object lastModified extends Style {
type F = ModifiedFileInfo
implicit val format: JsonFormat[ModifiedFileInfo] = new JsonFormat[ModifiedFileInfo] {
given format: JsonFormat[ModifiedFileInfo] = new JsonFormat[ModifiedFileInfo] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): ModifiedFileInfo =
jsOpt match {
case Some(js) =>
@ -229,7 +229,7 @@ object FileInfo {
object exists extends Style {
type F = PlainFileInfo
implicit val format: JsonFormat[PlainFileInfo] = new JsonFormat[PlainFileInfo] {
given format: JsonFormat[PlainFileInfo] = new JsonFormat[PlainFileInfo] {
def write[J](obj: PlainFileInfo, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("file", obj.file.toString)

View File

@ -20,7 +20,7 @@ class SingletonCacheSpec extends AnyFlatSpec {
case class ComplexType(val x: Int, y: String, z: List[Int])
object ComplexType {
implicit val format: JsonFormat[ComplexType] =
given format: JsonFormat[ComplexType] =
new JsonFormat[ComplexType] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): ComplexType = {
jsOpt match {

View File

@ -61,7 +61,7 @@ class TrackedSpec extends AnyFlatSpec {
"inputChangedW" should "not require the input to have a JsonReader instance" in {
case class Input(v: Int)
implicit val writer = new JsonWriter[Input] {
given JsonWriter[Input] = new JsonWriter[Input] {
override def write[J](obj: Input, builder: Builder[J]): Unit = builder.writeInt(obj.v)
}
@ -139,7 +139,7 @@ class TrackedSpec extends AnyFlatSpec {
"outputChangedW" should "not require the input to have a JsonReader instance" in {
case class Input(v: Int)
implicit val writer = new JsonWriter[Input] {
given JsonWriter[Input] = new JsonWriter[Input] {
override def write[J](obj: Input, builder: Builder[J]): Unit = builder.writeInt(obj.v)
}