Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# scalafmt v3.9.4
bb0334a03360ca7e5a0261ce105ba97cfe5ad791
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ jobs:
- name: Run tests
run: |
nix-shell --command "sbt -DSnippetsContainerTest.mongo=true cachedCiTest"
- name: Check formatting
run: |
nix-shell --command "sbt scalafmtCheckAll"
9 changes: 5 additions & 4 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.8.2
version = 3.9.4

style = default
maxColumn = 120
Expand All @@ -25,7 +25,7 @@ project.excludeFilters = [
storage/src/test/resources
demo/
]
align.preset = more
align.preset = some

rewrite.rules = [Imports]
rewrite.imports.sort = original
Expand All @@ -38,8 +38,9 @@ newlines.topLevelStatements = [before, after]
newlines.topLevelStatementsMinBreaks = 2
newlines.implicitParamListModifierForce = [before]

continuationIndent.defnSite = 2
continuationIndent.extendSite = 2
indent.defnSite = 2
indent.extendSite = 2
indent.ctorSite = 4

rewrite.imports.expand = false
rewrite.trailingCommas.style = "never"
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ open `http://localhost:9000`

## Scalafmt

Make sure to run `bin/scalafmt` to format your code.
Make sure to run `sbt scalafmtAll` to format your code.

You can install a pre-commit hook with `bin/hooks.sh`

Expand Down
82 changes: 41 additions & 41 deletions api/src/main/scala/com.olegych.scastie.api/ApiModels.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ 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(
Expand All @@ -20,8 +19,7 @@ case class SnippetSummary(
)

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

case class FormatRequest(
Expand All @@ -31,17 +29,17 @@ case class FormatRequest(
)

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]
)

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,8 +112,7 @@ 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(
Expand All @@ -120,9 +121,8 @@ case class ScalaDependency(
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 Down Expand Up @@ -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 All @@ -172,16 +173,15 @@ case class EditRange(startLine: Int, startChar: Int, endLine: Int, endChar: Int)
case class ScalaCompletionList(items: Set[CompletionItemDTO], isIncomplete: Boolean)

case class CompletionItemDTO(
label: String,
detail: String,
tpe: String,
order: Option[Int],
instructions: InsertInstructions,
additionalInsertInstructions: List[AdditionalInsertInstructions],
symbol: Option[String]
label: String,
detail: String,
tpe: String,
order: Option[Int],
instructions: InsertInstructions,
additionalInsertInstructions: List[AdditionalInsertInstructions],
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,8 +220,7 @@ object HoverDTO {
}

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

case class Project(
Expand Down
15 changes: 9 additions & 6 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,7 +20,9 @@ object Severity {
case _ => JsError(Seq())
}
}

}

}

sealed trait Severity
Expand Down
18 changes: 9 additions & 9 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 @@ -27,8 +28,7 @@ object ConsoleOutput {

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
Loading