Skip to content

Commit

Permalink
Reformat with scalafmt 3.8.3
Browse files Browse the repository at this point in the history
Executed command: scalafmt --non-interactive
  • Loading branch information
scala-center-steward[bot] committed Aug 6, 2024
1 parent 790621d commit 9f8e60b
Show file tree
Hide file tree
Showing 158 changed files with 4,666 additions and 4,848 deletions.
100 changes: 50 additions & 50 deletions api/src/main/scala/com.olegych.scastie.api/ApiModels.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,37 @@ case class SbtRunnerConnect(hostname: String, port: Int)
case object ActorConnected

object SnippetSummary {
implicit val formatSnippetSummary: OFormat[SnippetSummary] =
Json.format[SnippetSummary]
implicit val formatSnippetSummary: OFormat[SnippetSummary] = Json.format[SnippetSummary]
}

case class SnippetSummary(
snippetId: SnippetId,
summary: String,
time: Long
snippetId: SnippetId,
summary: String,
time: Long
)

object FormatRequest {
implicit val formatFormatRequest: OFormat[FormatRequest] =
Json.format[FormatRequest]
implicit val formatFormatRequest: OFormat[FormatRequest] = Json.format[FormatRequest]
}

case class FormatRequest(
code: String,
isWorksheetMode: Boolean,
scalaTarget: ScalaTarget
code: String,
isWorksheetMode: Boolean,
scalaTarget: ScalaTarget
)

object FormatResponse {

implicit object FormatResponseFormat extends Format[FormatResponse] {

def writes(response: FormatResponse): JsValue = {
response.result match {
case Left(error) =>
JsObject(
case Left(error) => JsObject(
Seq(
"Left" -> JsString(error)
)
)
case Right(formatedCode) =>
JsObject(
case Right(formatedCode) => JsObject(
Seq(
"Right" -> JsString(formatedCode)
)
Expand All @@ -51,51 +49,55 @@ object FormatResponse {

def reads(json: JsValue): JsResult[FormatResponse] = {
json match {
case JsObject(v) =>
v.toList match {
case List(("Left", JsString(error))) =>
JsSuccess(FormatResponse(Left(error)))
case JsObject(v) => v.toList match {
case List(("Left", JsString(error))) => JsSuccess(FormatResponse(Left(error)))

case List(("Right", JsString(formatedCode))) =>
JsSuccess(FormatResponse(Right(formatedCode)))
case List(("Right", JsString(formatedCode))) => JsSuccess(FormatResponse(Right(formatedCode)))

case _ =>
JsError(Seq())
case _ => JsError(Seq())
}

case _ =>
JsError(Seq())
case _ => JsError(Seq())
}
}

}
}

}

object EitherFormat {
import play.api.libs.functional.syntax._

implicit object JsEither {

implicit def eitherReads[A, B](implicit A: Reads[A], B: Reads[B]): Reads[Either[A, B]] = {
implicit def eitherReads[A, B](
implicit A: Reads[A],
B: Reads[B]
): Reads[Either[A, B]] = {
(JsPath \ "Left" \ "value").read[A].map(Left(_)) or
(JsPath \ "Right" \ "value").read[B].map(Right(_))
}

implicit def eitherWrites[A, B](implicit A: Writes[A], B: Writes[B]): Writes[Either[A, B]] = Writes[Either[A, B]] {
implicit def eitherWrites[A, B](
implicit A: Writes[A],
B: Writes[B]
): Writes[Either[A, B]] = Writes[Either[A, B]] {
case Left(value) => Json.obj("Left" -> Json.toJson(value))
case Right(value) => Json.obj("Right" -> Json.toJson(value))
}
}
}

}

}

case class FormatResponse(
result: Either[String, String]
result: Either[String, String]
)

object FetchResult {
implicit val formatFetchResult: OFormat[FetchResult] = Json.format[FetchResult]
def create(inputs: Inputs, progresses: List[SnippetProgress]) = FetchResult(inputs, progresses.sortBy(p => (p.id, p.ts)))
def create(inputs: Inputs, progresses: List[SnippetProgress]) =
FetchResult(inputs, progresses.sortBy(p => (p.id, p.ts)))
}

case class FetchResult private (inputs: Inputs, progresses: List[SnippetProgress])
Expand All @@ -110,19 +112,17 @@ case class FetchScalaSource(snippetId: SnippetId)
case class FetchResultScalaSource(content: String)

object ScalaDependency {
implicit val formatScalaDependency: OFormat[ScalaDependency] =
Json.format[ScalaDependency]
implicit val formatScalaDependency: OFormat[ScalaDependency] = Json.format[ScalaDependency]
}

case class ScalaDependency(
groupId: String,
artifact: String,
target: ScalaTarget,
version: String
groupId: String,
artifact: String,
target: ScalaTarget,
version: String
) {
def matches(sd: ScalaDependency): Boolean =
sd.groupId == this.groupId &&
sd.artifact == this.artifact
def matches(sd: ScalaDependency): Boolean = sd.groupId == this.groupId &&
sd.artifact == this.artifact

override def toString: String = target.renderSbt(this)
}
Expand All @@ -139,7 +139,7 @@ sealed trait FailureType {
val msg: String
}

case class NoResult(msg: String) extends FailureType
case class NoResult(msg: String) extends FailureType
case class PresentationCompilerFailure(msg: String) extends FailureType

object FailureType {
Expand All @@ -151,7 +151,8 @@ object NoResult {
}

object PresentationCompilerFailure {
implicit val presentationCompilerFailureFormat: OFormat[PresentationCompilerFailure] = Json.format[PresentationCompilerFailure]
implicit val presentationCompilerFailureFormat: OFormat[PresentationCompilerFailure] =
Json.format[PresentationCompilerFailure]
}

object ScastieOffsetParams {
Expand Down Expand Up @@ -181,7 +182,6 @@ case class CompletionItemDTO(
symbol: Option[String]
)


case class HoverDTO(from: Int, to: Int, content: String)

case class CompletionsDTO(items: Set[CompletionItemDTO])
Expand All @@ -195,7 +195,8 @@ object InsertInstructions {
}

object AdditionalInsertInstructions {
implicit val additionalInsertInstructionsFormat: OFormat[AdditionalInsertInstructions] = Json.format[AdditionalInsertInstructions]
implicit val additionalInsertInstructionsFormat: OFormat[AdditionalInsertInstructions] =
Json.format[AdditionalInsertInstructions]
}

object ScalaCompletionList {
Expand All @@ -219,15 +220,14 @@ object HoverDTO {
}

object Project {
implicit val formatProject: OFormat[Project] =
Json.format[Project]
implicit val formatProject: OFormat[Project] = Json.format[Project]
}

case class Project(
organization: String,
repository: String,
logo: Option[String],
artifacts: List[String]
organization: String,
repository: String,
logo: Option[String],
artifacts: List[String]
)

// Keep websocket connection
Expand Down
25 changes: 14 additions & 11 deletions api/src/main/scala/com.olegych.scastie.api/CompilerInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package com.olegych.scastie.api
import play.api.libs.json._

object Severity {

implicit object SeverityFormat extends Format[Severity] {
def writes(severity: Severity): JsValue =
severity match {
case Info => JsString("Info")
case Warning => JsString("Warning")
case Error => JsString("Error")
}

def writes(severity: Severity): JsValue = severity match {
case Info => JsString("Info")
case Warning => JsString("Warning")
case Error => JsString("Error")
}

def reads(json: JsValue): JsResult[Severity] = {
json match {
Expand All @@ -19,20 +20,22 @@ object Severity {
case _ => JsError(Seq())
}
}

}

}

sealed trait Severity
case object Info extends Severity
case object Info extends Severity
case object Warning extends Severity
case object Error extends Severity
case object Error extends Severity

object Problem {
implicit val formatProblem: OFormat[Problem] = Json.format[Problem]
}

case class Problem(
severity: Severity,
line: Option[Int],
message: String
severity: Severity,
line: Option[Int],
message: String
)
22 changes: 11 additions & 11 deletions api/src/main/scala/com.olegych.scastie.api/ConsoleOutput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sealed trait ConsoleOutput {
}

object ConsoleOutput {

case class SbtOutput(output: ProcessOutput) extends ConsoleOutput {
def show: String = s"sbt: ${output.line}"
}
Expand All @@ -22,13 +23,12 @@ object ConsoleOutput {

implicit object ConsoleOutputFormat extends Format[ConsoleOutput] {
val formatSbtOutput: OFormat[SbtOutput] = Json.format[SbtOutput]
private val formatUserOutput = Json.format[UserOutput]
private val formatScastieOutput = Json.format[ScastieOutput]
private val formatUserOutput = Json.format[UserOutput]
private val formatScastieOutput = Json.format[ScastieOutput]

def writes(output: ConsoleOutput): JsValue = {
output match {
case sbtOutput: SbtOutput =>
formatSbtOutput.writes(sbtOutput) ++ JsObject(Seq("tpe" -> JsString("SbtOutput")))
case sbtOutput: SbtOutput => formatSbtOutput.writes(sbtOutput) ++ JsObject(Seq("tpe" -> JsString("SbtOutput")))
case userOutput: UserOutput =>
formatUserOutput.writes(userOutput) ++ JsObject(Seq("tpe" -> JsString("UserOutput")))
case scastieOutput: ScastieOutput =>
Expand All @@ -41,18 +41,18 @@ object ConsoleOutput {
case obj: JsObject =>
val vs = obj.value
vs.get("tpe").orElse(vs.get("$type")) match {
case Some(tpe) =>
tpe match {
case JsString("SbtOutput") => formatSbtOutput.reads(json)
case JsString("UserOutput") => formatUserOutput.reads(json)
case JsString("ScastieOutput") =>
formatScastieOutput.reads(json)
case _ => JsError(Seq())
case Some(tpe) => tpe match {
case JsString("SbtOutput") => formatSbtOutput.reads(json)
case JsString("UserOutput") => formatUserOutput.reads(json)
case JsString("ScastieOutput") => formatScastieOutput.reads(json)
case _ => JsError(Seq())
}
case None => JsError(Seq())
}
case _ => JsError(Seq())
}
}

}

}
Loading

0 comments on commit 9f8e60b

Please sign in to comment.