Skip to content

Commit

Permalink
Reformat with scalafmt 3.5.9
Browse files Browse the repository at this point in the history
Executed command: scalafmt --non-interactive
  • Loading branch information
scala-center-steward[bot] committed May 9, 2024
1 parent 66c4803 commit 8dbae48
Show file tree
Hide file tree
Showing 115 changed files with 3,134 additions and 3,292 deletions.
31 changes: 15 additions & 16 deletions api/src/main/scala/com.olegych.scastie.api/Outputs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ package com.olegych.scastie.api
import play.api.libs.json._

object ReleaseOptions {
implicit val formatReleaseOptions: OFormat[ReleaseOptions] =
Json.format[ReleaseOptions]
implicit val formatReleaseOptions: OFormat[ReleaseOptions] = Json.format[ReleaseOptions]
}

case class ReleaseOptions(groupId: String, versions: List[String], version: String)

// case class MavenReference(groupId: String, artifactId: String, version: String)

object Outputs {
implicit val formatOutputs: OFormat[Outputs] =
Json.format[Outputs]
implicit val formatOutputs: OFormat[Outputs] = Json.format[Outputs]

def default: Outputs = Outputs(
consoleOutputs = Vector(),
Expand All @@ -22,27 +20,28 @@ object Outputs {
runtimeError = None,
sbtError = false
)

}

case class Outputs(
consoleOutputs: Vector[ConsoleOutput],
compilationInfos: Set[Problem],
instrumentations: Set[Instrumentation],
runtimeError: Option[RuntimeError],
sbtError: Boolean
consoleOutputs: Vector[ConsoleOutput],
compilationInfos: Set[Problem],
instrumentations: Set[Instrumentation],
runtimeError: Option[RuntimeError],
sbtError: Boolean
) {

def console: String = consoleOutputs.map(_.show).mkString("\n")

def isClearable: Boolean =
consoleOutputs.nonEmpty ||
compilationInfos.nonEmpty ||
instrumentations.nonEmpty ||
runtimeError.isDefined
def isClearable: Boolean = consoleOutputs.nonEmpty ||
compilationInfos.nonEmpty ||
instrumentations.nonEmpty ||
runtimeError.isDefined

}

object Position {
implicit val formatPosition: OFormat[Position] =
Json.format[Position]
implicit val formatPosition: OFormat[Position] = Json.format[Position]
}

case class Position(start: Int, end: Int)
36 changes: 16 additions & 20 deletions api/src/main/scala/com.olegych.scastie.api/RuntimeError.scala
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
package com.olegych.scastie.api

import java.io.{PrintWriter, StringWriter}

import play.api.libs.json._

case class RuntimeError(
message: String,
line: Option[Int],
fullStack: String
message: String,
line: Option[Int],
fullStack: String
)

object RuntimeError {
implicit val formatRuntimeError: OFormat[RuntimeError] =
Json.format[RuntimeError]
implicit val formatRuntimeError: OFormat[RuntimeError] = Json.format[RuntimeError]

def wrap[T](in: => T): Either[Option[RuntimeError], T] = {
try {
Right(in)
} catch {
case ex: Exception =>
Left(RuntimeError.fromThrowable(ex, fromScala = false))
case ex: Exception => Left(RuntimeError.fromThrowable(ex, fromScala = false))
}
}

def fromThrowable(t: Throwable, fromScala: Boolean = true): Option[RuntimeError] = {
def search(e: Throwable) = {
e.getStackTrace
.find(
trace =>
if (fromScala)
trace.getFileName == "main.scala" && trace.getLineNumber != -1
else true
.find(trace =>
if (fromScala) trace.getFileName == "main.scala" && trace.getLineNumber != -1
else true
)
.map(v => (e, Some(v.getLineNumber)))
}
Expand All @@ -41,20 +38,19 @@ object RuntimeError {
else s
}

loop(t).map {
case (err, line) =>
val errors = new StringWriter()
t.printStackTrace(new PrintWriter(errors))
val fullStack = errors.toString
loop(t).map { case (err, line) =>
val errors = new StringWriter()
t.printStackTrace(new PrintWriter(errors))
val fullStack = errors.toString

RuntimeError(err.toString, line, fullStack)
RuntimeError(err.toString, line, fullStack)
}
}

}

object RuntimeErrorWrap {
implicit val formatRuntimeErrorWrap: OFormat[RuntimeErrorWrap] =
Json.format[RuntimeErrorWrap]
implicit val formatRuntimeErrorWrap: OFormat[RuntimeErrorWrap] = Json.format[RuntimeErrorWrap]
}

case class RuntimeErrorWrap(error: Option[RuntimeError])
21 changes: 9 additions & 12 deletions api/src/main/scala/com.olegych.scastie.api/ScalaJsResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ package com.olegych.scastie.api
import play.api.libs.json._

case class ScalaJsResult(
in: Either[Option[RuntimeError], List[Instrumentation]]
in: Either[Option[RuntimeError], List[Instrumentation]]
)

object ScalaJsResult {
private case class Error(er: Option[RuntimeError])
private case class Instrumentations(instrs: List[Instrumentation])

implicit object ScalaJsResultFormat extends Format[ScalaJsResult] {
private val formatLeft = Json.format[Error]
private val formatLeft = Json.format[Error]
private val formatRight = Json.format[Instrumentations]

def writes(result: ScalaJsResult): JsValue = {
result.in match {
case Left(err) =>
formatLeft.writes(Error(err)) ++ JsObject(Seq("tpe" -> JsString("Left")))
case Right(instrs) =>
formatRight.writes(Instrumentations(instrs)) ++ JsObject(Seq("tpe" -> JsString("Right")))
case Left(err) => formatLeft.writes(Error(err)) ++ JsObject(Seq("tpe" -> JsString("Left")))
case Right(instrs) => formatRight.writes(Instrumentations(instrs)) ++ JsObject(Seq("tpe" -> JsString("Right")))
}
}

Expand All @@ -28,12 +26,9 @@ object ScalaJsResult {
case obj: JsObject =>
val vs = obj.value
vs.get("tpe").orElse(vs.get("$type")) match {
case Some(JsString(tpe)) =>
tpe match {
case "Left" =>
formatLeft.reads(json).map(v => ScalaJsResult(Left(v.er)))
case "Right" =>
formatRight
case Some(JsString(tpe)) => tpe match {
case "Left" => formatLeft.reads(json).map(v => ScalaJsResult(Left(v.er)))
case "Right" => formatRight
.reads(json)
.map(v => ScalaJsResult(Right(v.instrs)))
case _ => JsError(Seq())
Expand All @@ -43,5 +38,7 @@ object ScalaJsResult {
case _ => JsError(Seq())
}
}

}

}
20 changes: 10 additions & 10 deletions api/src/main/scala/com.olegych.scastie.api/ScalaVersions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package com.olegych.scastie.api
import com.olegych.scastie.buildinfo.BuildInfo

object ScalaVersions {

def suggestedScalaVersions(tpe: ScalaTargetType): List[String] = {
val versions = tpe match {
case ScalaTargetType.Scala3 => List(BuildInfo.stableLTS, BuildInfo.stableNext)
case ScalaTargetType.JS => List(BuildInfo.stableLTS, BuildInfo.stableNext, BuildInfo.latest213, BuildInfo.latest212)
case _ => List(BuildInfo.latest213, BuildInfo.latest212)
case ScalaTargetType.JS =>
List(BuildInfo.stableLTS, BuildInfo.stableNext, BuildInfo.latest213, BuildInfo.latest212)
case _ => List(BuildInfo.latest213, BuildInfo.latest212)
}
versions.distinct
}

def allVersions(tpe: ScalaTargetType): List[String] = {
val versions = tpe match {
case ScalaTargetType.Scala3 =>
List(
case ScalaTargetType.Scala3 => List(
BuildInfo.latestNext,
BuildInfo.stableNext,
BuildInfo.latestLTS,
Expand All @@ -34,10 +35,10 @@ object ScalaVersions {
"3.0.1",
"3.0.0"
)
case ScalaTargetType.JS =>
allVersions(ScalaTargetType.Scala3) ++ allVersions(ScalaTargetType.Scala2).filter(v => v.startsWith("2.12") || v.startsWith("2.13"))
case _ =>
List(
case ScalaTargetType.JS => allVersions(ScalaTargetType.Scala3) ++ allVersions(ScalaTargetType.Scala2).filter(v =>
v.startsWith("2.12") || v.startsWith("2.13")
)
case _ => List(
BuildInfo.latest213,
"2.13.13",
"2.13.12",
Expand Down Expand Up @@ -95,6 +96,5 @@ object ScalaVersions {
versions.distinct
}

def find(tpe: ScalaTargetType, sv: String): String =
allVersions(tpe).find(_.startsWith(sv)).getOrElse(sv)
def find(tpe: ScalaTargetType, sv: String): String = allVersions(tpe).find(_.startsWith(sv)).getOrElse(sv)
}
18 changes: 8 additions & 10 deletions api/src/main/scala/com.olegych.scastie.api/SnippetId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,36 @@ case class User(login: String, name: Option[String], avatar_url: String) {
}

object SnippetUserPart {
implicit val formatSnippetUserPart: OFormat[SnippetUserPart] =
Json.format[SnippetUserPart]
implicit val formatSnippetUserPart: OFormat[SnippetUserPart] = Json.format[SnippetUserPart]
}

case class SnippetUserPart(login: String, update: Int = 0)

object SnippetId {
implicit val formatSnippetId: OFormat[SnippetId] =
Json.format[SnippetId]
implicit val formatSnippetId: OFormat[SnippetId] = Json.format[SnippetId]
}

case class SnippetId(base64UUID: String, user: Option[SnippetUserPart]) {

def isOwnedBy(user2: Option[User]): Boolean = {
(user, user2) match {
case (Some(SnippetUserPart(snippetLogin, _)), Some(User(userLogin, _, _))) =>
snippetLogin == userLogin
case _ => false
case (Some(SnippetUserPart(snippetLogin, _)), Some(User(userLogin, _, _))) => snippetLogin == userLogin
case _ => false
}
}

override def toString: String = url

def url: String = {
this match {
case SnippetId(uuid, None) => uuid
case SnippetId(uuid, Some(SnippetUserPart(login, update))) =>
s"$login/$uuid/$update"
case SnippetId(uuid, None) => uuid
case SnippetId(uuid, Some(SnippetUserPart(login, update))) => s"$login/$uuid/$update"
}
}

def scalaJsUrl(end: String): String = {
val middle = url
s"/api/${Shared.scalaJsHttpPathPrefix}/$middle/$end"
}

}
65 changes: 33 additions & 32 deletions api/src/main/scala/com.olegych.scastie.api/SnippetProgress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,45 @@ package com.olegych.scastie.api
import play.api.libs.json._

object SnippetProgress {
def default: SnippetProgress =
SnippetProgress(
ts = None,
id = None,
snippetId = None,
userOutput = None,
sbtOutput = None,
compilationInfos = Nil,
instrumentations = Nil,
runtimeError = None,
scalaJsContent = None,
scalaJsSourceMapContent = None,
isDone = true,
isTimeout = false,
isSbtError = false,
isForcedProgramMode = false
)

def default: SnippetProgress = SnippetProgress(
ts = None,
id = None,
snippetId = None,
userOutput = None,
sbtOutput = None,
compilationInfos = Nil,
instrumentations = Nil,
runtimeError = None,
scalaJsContent = None,
scalaJsSourceMapContent = None,
isDone = true,
isTimeout = false,
isSbtError = false,
isForcedProgramMode = false
)

implicit val formatSnippetProgress: OFormat[SnippetProgress] = Json.format[SnippetProgress]
}

case class SnippetProgress(
ts: Option[Long],
id: Option[Long],
snippetId: Option[SnippetId],
userOutput: Option[ProcessOutput],
sbtOutput: Option[ProcessOutput],
compilationInfos: List[Problem],
instrumentations: List[Instrumentation],
runtimeError: Option[RuntimeError],
scalaJsContent: Option[String],
scalaJsSourceMapContent: Option[String],
isDone: Boolean,
isTimeout: Boolean,
isSbtError: Boolean,
isForcedProgramMode: Boolean
ts: Option[Long],
id: Option[Long],
snippetId: Option[SnippetId],
userOutput: Option[ProcessOutput],
sbtOutput: Option[ProcessOutput],
compilationInfos: List[Problem],
instrumentations: List[Instrumentation],
runtimeError: Option[RuntimeError],
scalaJsContent: Option[String],
scalaJsSourceMapContent: Option[String],
isDone: Boolean,
isTimeout: Boolean,
isSbtError: Boolean,
isForcedProgramMode: Boolean
) {
def isFailure: Boolean = isTimeout || isSbtError || runtimeError.nonEmpty || compilationInfos.exists(_.severity == Error)
def isFailure: Boolean =
isTimeout || isSbtError || runtimeError.nonEmpty || compilationInfos.exists(_.severity == Error)

override def toString: String = Json.toJsObject(this).toString()
}
4 changes: 1 addition & 3 deletions api/src/main/scala/com.olegych.scastie.api/TaskId.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.olegych.scastie.api

import play.api.libs.json._

import play.api.libs.json.OFormat

object TaskId {
implicit val formatSbtRunTaskId: OFormat[TaskId] =
Json.format[TaskId]
implicit val formatSbtRunTaskId: OFormat[TaskId] = Json.format[TaskId]
}

case class TaskId(snippetId: SnippetId)
Loading

0 comments on commit 8dbae48

Please sign in to comment.