From 5d245eb9c8ed7d5fbd105ea8ab2bfdb492919745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 4 Oct 2023 16:01:14 +0200 Subject: [PATCH 01/15] WIP: scala 3 --- build.sbt | 9 ++++++--- .../src/main/scala/playground/smithyql/AST.scala | 3 ++- .../scala/playground/DynamicServiceProxy.scala | 16 +++------------- .../scala/playground/OperationCompiler.scala | 4 ++-- .../smithyutil/AddDynamicRefinements.scala | 6 +++--- .../scala/playground/std/StdlibRuntime.scala | 8 +++++++- project/plugins.sbt | 2 +- smithy-build.json | 2 +- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/build.sbt b/build.sbt index ceb6c40d..cd23a40a 100644 --- a/build.sbt +++ b/build.sbt @@ -34,8 +34,8 @@ ThisBuild / versionScheme := Some("early-semver") Global / onChangedBuildSource := ReloadOnSourceChanges -ThisBuild / scalaVersion := "2.13.11" -ThisBuild / crossScalaVersions := Seq("2.13.11") +ThisBuild / scalaVersion := "3.3.1" +ThisBuild / crossScalaVersions := Seq("3.3.1") // For coursier's "latest.integration" ThisBuild / dynverSeparator := "-" @@ -156,7 +156,10 @@ lazy val lsp = module("lsp") "io.circe" %% "circe-core" % "0.14.6", "org.http4s" %% "http4s-ember-client" % "0.23.23", "org.http4s" %% "http4s-ember-server" % "0.23.23" % Test, - "io.get-coursier" %% "coursier" % "2.1.7", + ("io.get-coursier" % "coursier" % "2.1.7") + .cross(CrossVersion.for3Use2_13) + .exclude("org.scala-lang.modules", "scala-collection-compat_2.13") + .exclude("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_2.13"), "org.typelevel" %% "cats-tagless-core" % "0.15.0", ), buildInfoPackage := "playground.lsp.buildinfo", diff --git a/modules/ast/src/main/scala/playground/smithyql/AST.scala b/modules/ast/src/main/scala/playground/smithyql/AST.scala index 3adc2baf..bcb96e89 100644 --- a/modules/ast/src/main/scala/playground/smithyql/AST.scala +++ b/modules/ast/src/main/scala/playground/smithyql/AST.scala @@ -166,7 +166,8 @@ object QualifiedIdentifier { implicit val show: Show[QualifiedIdentifier] = Show.fromToString - implicit val ord: Order[QualifiedIdentifier] = Order.by(unapply(_).get) + // todo: dotty claims infinite loop + implicit val ord: Order[QualifiedIdentifier] = Order.by(unapply(_)) } diff --git a/modules/core/src/main/scala/playground/DynamicServiceProxy.scala b/modules/core/src/main/scala/playground/DynamicServiceProxy.scala index d03bb6fc..2e4a76bc 100644 --- a/modules/core/src/main/scala/playground/DynamicServiceProxy.scala +++ b/modules/core/src/main/scala/playground/DynamicServiceProxy.scala @@ -26,8 +26,6 @@ class DynamicServiceProxy[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _]]( ): FunctorInterpreter[Op, F] = { val grp = serviceStatic.endpoints.groupBy(_.id).fmap(_.head) - type Proxy[I, E, O, SE, EO] = I => F[O] - def makeProxy[A, B]( schemaIn: Schema[A], schemaOut: Schema[B], @@ -39,7 +37,7 @@ class DynamicServiceProxy[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _]]( } val endpointMapping = - new smithy4s.kinds.PolyFunction5[Endpoint[Op, *, *, *, *, *], Proxy] { + new service.FunctorEndpointCompiler[F] { private val trans = serviceStatic.toPolyFunction(interp) private def applyWithStatic[I, E, O, SI, SO, STI, STE, STO, STSI, STSO]( @@ -77,16 +75,8 @@ class DynamicServiceProxy[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _]]( endpoint: Endpoint[Op, I, E, O, SI, SO] ): I => F[O] = applyWithStatic(endpoint, grp(endpoint.id)) } - .precomputeBy(service.endpoints, _.name) - - new FunctorInterpreter[Op, F] { - def apply[I, E, O, SI, SO]( - op: Op[I, E, O, SI, SO] - ): F[O] = { - val (input, endpoint) = service.endpoint(op) - endpointMapping(endpoint)(input) - } - } + + service.functorInterpreter(endpointMapping) } private final implicit class PolyFunction5Ops[F[_, _, _, _, _], G[_, _, _, _, _]]( diff --git a/modules/core/src/main/scala/playground/OperationCompiler.scala b/modules/core/src/main/scala/playground/OperationCompiler.scala index 4048d388..6b63b4ad 100644 --- a/modules/core/src/main/scala/playground/OperationCompiler.scala +++ b/modules/core/src/main/scala/playground/OperationCompiler.scala @@ -150,7 +150,7 @@ private class ServiceCompiler[Alg[_[_, _, _, _, _]]]( ) extends OperationCompiler[IorNel[CompilationError, *]] { private def compileEndpoint[In, Err, Out]( - e: Endpoint[service.Operation, In, Err, Out, _, _] + e: Endpoint[service.Operation, In, Err, Out, SE, _] ): QueryCompiler[CompiledInput] = { val inputCompiler = e.input.compile(QueryCompilerVisitor.full) val outputEncoder = NodeEncoder.derive(e.output) @@ -165,7 +165,7 @@ private class ServiceCompiler[Alg[_[_, _, _, _, _]]]( type E = Err type O = Out - val op: _Op[_, Err, Out, _, _] = e.wrap(compiled) + val op: _Op[_I, E, O, SE, SO] = e.wrap(compiled) val writeOutput: NodeEncoder[Out] = outputEncoder val writeError: Option[NodeEncoder[Err]] = errorEncoder val catchError: Throwable => Option[Err] = e.Error.unapply(_).map(_._2) diff --git a/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala b/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala index fb5de0bc..0263bd85 100644 --- a/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala +++ b/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala @@ -50,8 +50,8 @@ object AddDynamicRefinements extends (Schema ~> Schema) { def apply[A]( schema: Schema[A] - ): Schema[A] = - schema match { + ): Schema[A] = ??? + /* schema match { case PrimitiveSchema(_, _, tag) => tag match { case PString => schema.reifyHint[api.Length].reifyHint[api.Pattern] @@ -76,6 +76,6 @@ object AddDynamicRefinements extends (Schema ~> Schema) { case s: StructSchema[_] => s case l: LazySchema[_] => l case u: UnionSchema[_] => u - } + } */ } diff --git a/modules/core/src/main/scala/playground/std/StdlibRuntime.scala b/modules/core/src/main/scala/playground/std/StdlibRuntime.scala index c59b2470..5c0e05e4 100644 --- a/modules/core/src/main/scala/playground/std/StdlibRuntime.scala +++ b/modules/core/src/main/scala/playground/std/StdlibRuntime.scala @@ -21,8 +21,14 @@ object StdlibRuntime { val random: Random[F] = new playground.std.Random[F] { + def nextUUID( - ): F[NextUUIDOutput] = UUIDGen[F].randomUUID.map(_.toString).map(NextUUIDOutput(_)) + ): F[NextUUIDOutput] = UUIDGen[F] + .randomUUID + .map(_.toString) + .map(playground.std.UUID(_)) + .map(NextUUIDOutput(_)) + } val clock: Clock[F] = diff --git a/project/plugins.sbt b/project/plugins.sbt index b6cbc9ac..fcbfc8ed 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,7 +3,7 @@ ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11") addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.3") -addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % "0.17.11") +addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % "0.17.19") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.1") diff --git a/smithy-build.json b/smithy-build.json index 1bdb8712..17c40f9b 100644 --- a/smithy-build.json +++ b/smithy-build.json @@ -2,7 +2,7 @@ "imports": ["modules/core/src/test/smithy"], "mavenDependencies": [ "com.disneystreaming.alloy:alloy-core:0.2.7", - "com.disneystreaming.smithy4s:smithy4s-protocol:0.17.6", + "com.disneystreaming.smithy4s:smithy4s-protocol:0.17.19", "software.amazon.smithy:smithy-aws-traits:1.34.0" ] } From ccff2e4eaccd529f7a57b0cc32d50eb4c5afac9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 11 Oct 2023 00:51:05 +0200 Subject: [PATCH 02/15] Pass tests --- .github/workflows/ci.yml | 2 +- .scalafmt.conf | 2 +- build.sbt | 13 +++- .../main/scala/playground/smithyql/AST.scala | 6 +- .../main/scala/playground/FileCompiler.scala | 1 - .../main/scala/playground/FileRunner.scala | 1 - .../scala/playground/OperationCompiler.scala | 24 +++--- .../scala/playground/PreludeCompiler.scala | 1 - .../smithyutil/AddDynamicRefinements.scala | 74 +++++++++++++------ .../src/test/scala/playground/Diffs.scala | 29 +++++--- .../MultiServiceResolverTests.scala | 4 +- .../playground/PreludeCompilerTests.scala | 2 +- .../playground/smithyql/AtPositionTests.scala | 2 +- .../smithyql/CompilationTests.scala | 2 +- .../smithyql/format/FormattingTests.scala | 2 +- .../playground/language/CommandProvider.scala | 48 ++++++------ .../language/CodeLensProviderTests.scala | 2 +- .../language/CompletionItemTests.scala | 2 +- .../language/CompletionProviderTests.scala | 2 +- .../playground/language/CompletionTests.scala | 2 +- .../language/DiagnosticProviderTests.scala | 2 +- .../scala/playground/language/Diffs.scala | 13 +++- .../DocumentSymbolProviderTests.scala | 2 +- ...ageServerIntegrationTestSharedServer.scala | 32 ++------ .../LanguageServerIntegrationTests.scala | 52 ++++++++++++- .../playground/lsp/harness/TestClient.scala | 1 + .../smithyql/parser/v2/scanner.scala | 2 +- .../playground/smithyql/parser/Codecs.scala | 28 +++++-- .../playground/smithyql/parser/Diffs.scala | 6 +- .../parser/generative/ListParserTests.scala | 5 +- .../generative/PreludeParserTests.scala | 4 +- .../parser/generative/QueryParserTests.scala | 4 +- .../generative/SourceFileParserTests.scala | 4 +- .../parser/generative/StructParserTests.scala | 4 +- .../generative/UseServiceParserTests.scala | 4 +- .../smithyql/parser/v2/ScannerSuite.scala | 2 +- .../smithyql/parser/v2/ScannerTests.scala | 2 +- .../playground/smithyql/WithSource.scala | 4 +- .../scala/playground/smithyql/Diffs.scala | 39 +++++++--- 39 files changed, 273 insertions(+), 158 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 668103b8..0a276ea5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: build: name: "Build" runs-on: ubuntu-20.04 - timeout-minutes: 30 + timeout-minutes: 10 steps: - uses: actions/checkout@v3.5.3 diff --git a/.scalafmt.conf b/.scalafmt.conf index 92af2b24..0fd839aa 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -runner.dialect=scala213source3 +runner.dialect=scala3 version = 3.7.2 maxColumn = 100 align.preset = some diff --git a/build.sbt b/build.sbt index 2fa39da6..cdd6fe34 100644 --- a/build.sbt +++ b/build.sbt @@ -54,7 +54,17 @@ val commonSettings = Seq( compilerPlugins, scalacOptions -= "-Xfatal-warnings", scalacOptions -= "-Vtype-diffs", + scalacOptions -= "-language:existentials", + // https://github.com/lampepfl/dotty/issues/18674 + Test / scalacOptions -= "-Wunused:implicits", + Test / scalacOptions -= "-Wunused:explicits", + Test / scalacOptions -= "-Wunused:imports", + Test / scalacOptions -= "-Wunused:locals", + Test / scalacOptions -= "-Wunused:params", + Test / scalacOptions -= "-Wunused:privates", + // scalacOptions += "-Wnonunit-statement", + scalacOptions += "-no-indent", scalacOptions ++= Seq("-Xsource:3.0"), Test / scalacOptions += "-Wconf:cat=deprecation:silent,msg=Specify both message and version:silent", scalacOptions ++= Seq("-release", "11"), @@ -73,8 +83,7 @@ lazy val pluginCore = module("plugin-core").settings( libraryDependencies ++= Seq( "com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value ), - // mimaPreviousArtifacts := Set(organization.value %% name.value % "0.3.0"), - mimaPreviousArtifacts := Set.empty, + mimaPreviousArtifacts := Set(organization.value %% name.value % "0.7.0"), ) lazy val pluginSample = module("plugin-sample") diff --git a/modules/ast/src/main/scala/playground/smithyql/AST.scala b/modules/ast/src/main/scala/playground/smithyql/AST.scala index bcb96e89..a50687da 100644 --- a/modules/ast/src/main/scala/playground/smithyql/AST.scala +++ b/modules/ast/src/main/scala/playground/smithyql/AST.scala @@ -166,9 +166,7 @@ object QualifiedIdentifier { implicit val show: Show[QualifiedIdentifier] = Show.fromToString - // todo: dotty claims infinite loop - implicit val ord: Order[QualifiedIdentifier] = Order.by(unapply(_)) - + implicit val ord: Order[QualifiedIdentifier] = Order.by(Tuple.fromProductTyped) } // the keywords of the clause are captured in the Prelude's useClauses list. @@ -241,7 +239,7 @@ final case class Binding[F[_]]( final case class Identifier( text: String -) extends AnyVal +) object Struct { diff --git a/modules/core/src/main/scala/playground/FileCompiler.scala b/modules/core/src/main/scala/playground/FileCompiler.scala index 105b45c9..8e2afaa0 100644 --- a/modules/core/src/main/scala/playground/FileCompiler.scala +++ b/modules/core/src/main/scala/playground/FileCompiler.scala @@ -1,7 +1,6 @@ package playground import cats.Parallel -import cats.effect.implicits._ import cats.implicits._ import cats.~> import playground._ diff --git a/modules/core/src/main/scala/playground/FileRunner.scala b/modules/core/src/main/scala/playground/FileRunner.scala index 35738bb7..acf5bb9d 100644 --- a/modules/core/src/main/scala/playground/FileRunner.scala +++ b/modules/core/src/main/scala/playground/FileRunner.scala @@ -1,7 +1,6 @@ package playground import cats.data.NonEmptyList -import cats.effect.implicits._ import cats.implicits._ import playground._ import playground.smithyql.SourceFile diff --git a/modules/core/src/main/scala/playground/OperationCompiler.scala b/modules/core/src/main/scala/playground/OperationCompiler.scala index 1a4b39d5..e5157782 100644 --- a/modules/core/src/main/scala/playground/OperationCompiler.scala +++ b/modules/core/src/main/scala/playground/OperationCompiler.scala @@ -14,6 +14,7 @@ import playground.smithyql.Query import playground.smithyql.WithSource import smithy.api import smithy4s.Endpoint +import smithy4s.Hints import smithy4s.Service import smithy4s.dynamic.DynamicSchemaIndex import smithyql.syntax._ @@ -22,12 +23,15 @@ import util.chaining._ trait CompiledInput { type _Op[_, _, _, _, _] + type I type E type O + type SI + type SO def catchError: Throwable => Option[E] def writeError: Option[NodeEncoder[E]] def writeOutput: NodeEncoder[O] - def op: _Op[_, E, O, _, _] + def op: _Op[I, E, O, SI, SO] } object CompiledInput { @@ -149,8 +153,8 @@ private class ServiceCompiler[Alg[_[_, _, _, _, _]]]( service: Service[Alg] ) extends OperationCompiler[IorNel[CompilationError, *]] { - private def compileEndpoint[In, Err, Out]( - e: Endpoint[service.Operation, In, Err, Out, SE, _] + private def compileEndpoint[In, Err, Out, SIn, SOut]( + e: Endpoint[service.Operation, In, Err, Out, SIn, SOut] ): QueryCompiler[CompiledInput] = { val inputCompiler = e.input.compile(QueryCompilerVisitor.full) val outputEncoder = NodeEncoder.derive(e.output) @@ -162,10 +166,13 @@ private class ServiceCompiler[Alg[_[_, _, _, _, _]]]( .map { compiled => new CompiledInput { type _Op[_I, _E, _O, _SE, _SO] = service.Operation[_I, _E, _O, _SE, _SO] + type I = In type E = Err type O = Out + type SI = SIn + type SO = SOut - val op: _Op[_I, E, O, SE, SO] = e.wrap(compiled) + val op: _Op[I, E, O, SI, SO] = e.wrap(compiled) val writeOutput: NodeEncoder[Out] = outputEncoder val writeError: Option[NodeEncoder[Err]] = errorEncoder val catchError: Throwable => Option[Err] = e.Error.unapply(_).map(_._2) @@ -174,12 +181,12 @@ private class ServiceCompiler[Alg[_[_, _, _, _, _]]]( } // https://github.com/kubukoz/smithy-playground/issues/154 - // map of endpoint names to (endpoint, input compiler) + // map of endpoint names to (endpoint hints, input compiler) private val endpoints = service .endpoints .toList .groupByNel(_.name) - .map(_.map(_.head).map(e => (e, compileEndpoint(e)))) + .map(_.map(_.head).map(e => (e.hints, compileEndpoint(e)))) // Checks the explicit service reference (if any). // Note that the reference should be valid thanks to MultiServiceResolver's checks. @@ -201,10 +208,9 @@ private class ServiceCompiler[Alg[_[_, _, _, _, _]]]( private def deprecatedOperationCheck( q: Query[WithSource], - endpoint: Endpoint[service.Operation, _, _, _, _, _], + endpointHints: Hints, ): IorNel[CompilationError, Unit] = - endpoint - .hints + endpointHints .get(api.Deprecated) .map { info => CompilationError.deprecation( diff --git a/modules/core/src/main/scala/playground/PreludeCompiler.scala b/modules/core/src/main/scala/playground/PreludeCompiler.scala index b98e6e61..ae1a23dc 100644 --- a/modules/core/src/main/scala/playground/PreludeCompiler.scala +++ b/modules/core/src/main/scala/playground/PreludeCompiler.scala @@ -3,7 +3,6 @@ package playground import cats.Applicative import cats.Parallel import cats.data.NonEmptyList -import cats.effect.implicits._ import cats.implicits._ import cats.mtl.Chronicle import cats.mtl.implicits._ diff --git a/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala b/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala index 1329f8ff..6388bc47 100644 --- a/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala +++ b/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala @@ -11,6 +11,8 @@ import smithy4s.schema.Schema import smithy4s.schema.Schema._ import smithy4s.~> +import RefinementProvider.given + /** Reifies refinement hints into the schema. * * Notably, this does NOT recurse! In order to traverse an entire schema recursively, this has to @@ -32,7 +34,7 @@ object AddDynamicRefinements extends (Schema ~> Schema) { ) { def reifyHint[B]( - implicit rp: RefinementProvider[B, A, _] + using rp: RefinementProvider.Simple[B, A] ): Schema[A] = schema.hints.get(rp.tag).fold(schema)(schema.validated(_)(void(rp))) } @@ -41,34 +43,60 @@ object AddDynamicRefinements extends (Schema ~> Schema) { schema: Schema.CollectionSchema[C, A] ): Schema[C[A]] = schema.tag match { - case ListTag => schema.reifyHint(RefinementProvider.iterableLengthConstraint[List, A]) - case VectorTag => schema.reifyHint(RefinementProvider.iterableLengthConstraint[Vector, A]) - case SetTag => schema.reifyHint(RefinementProvider.iterableLengthConstraint[Set, A]) - case IndexedSeqTag => - schema.reifyHint(RefinementProvider.iterableLengthConstraint[IndexedSeq, A]) + case ListTag => schema.reifyHint[api.Length] + case VectorTag => schema.reifyHint[api.Length] + case SetTag => schema.reifyHint[api.Length] + case IndexedSeqTag => schema.reifyHint[api.Length] } def apply[A]( schema: Schema[A] - ): Schema[A] = ??? - /* schema match { - case PrimitiveSchema(_, _, tag) => - tag match { - case PString => schema.reifyHint[api.Length].reifyHint[api.Pattern] - case PByte => schema.reifyHint[api.Range] - case PShort => schema.reifyHint[api.Range] - case PInt => schema.reifyHint[api.Range] - case PLong => schema.reifyHint[api.Range] - case PFloat => schema.reifyHint[api.Range] - case PDouble => schema.reifyHint[api.Range] - case PBigInt => schema.reifyHint[api.Range] - case PBigDecimal => schema.reifyHint[api.Range] - case PBlob => schema.reifyHint[api.Length] + ): Schema[A] = + schema match { + case p: PrimitiveSchema[?] => + p.tag match { + case PString => + schema + .reifyHint[api.Length] + .reifyHint[api.Pattern] + case PByte => + schema.reifyHint[api.Range]( + using RefinementProvider.numericRangeConstraints[Byte] + ) + case PShort => + schema.reifyHint[api.Range]( + using RefinementProvider.numericRangeConstraints[Short] + ) + case PInt => + schema.reifyHint[api.Range]( + using RefinementProvider.numericRangeConstraints[Int] + ) + case PLong => + schema.reifyHint[api.Range]( + using RefinementProvider.numericRangeConstraints[Long] + ) + case PFloat => + schema.reifyHint[api.Range]( + using RefinementProvider.numericRangeConstraints[Float] + ) + case PDouble => + schema.reifyHint[api.Range]( + using RefinementProvider.numericRangeConstraints[Double] + ) + case PBigInt => + schema.reifyHint[api.Range]( + using RefinementProvider.numericRangeConstraints[BigInt] + ) + case PBigDecimal => + schema.reifyHint[api.Range]( + using RefinementProvider.numericRangeConstraints[BigDecimal] + ) + case PBlob => schema.reifyHint[api.Length] case PTimestamp | PDocument | PBoolean | PUUID => schema } - case c: CollectionSchema[_, _] => collection(c) - case m: MapSchema[_, _] => m.reifyHint[api.Length] + case c @ CollectionSchema(_, _, _, _) => collection(c) + case m: MapSchema[_, _] => m.reifyHint[api.Length] // explicitly handling each remaining case, in order to get a "mising match" warning if the schema model changes case b: BijectionSchema[_, _] => b case r: RefinementSchema[_, _] => r @@ -77,6 +105,6 @@ object AddDynamicRefinements extends (Schema ~> Schema) { case l: LazySchema[_] => l case u: UnionSchema[_] => u case n: OptionSchema[_] => n - } */ + } } diff --git a/modules/core/src/test/scala/playground/Diffs.scala b/modules/core/src/test/scala/playground/Diffs.scala index da60e236..b6bd9da8 100644 --- a/modules/core/src/test/scala/playground/Diffs.scala +++ b/modules/core/src/test/scala/playground/Diffs.scala @@ -2,22 +2,31 @@ package playground import cats.data.Ior import playground.smithyql.ContextRange +import playground.smithyql.Diffs.given import playground.smithyql.NodeContext +import smithy.api.TimestampFormat import smithy4s.Blob +import smithy4s.ShapeId import scala.annotation.nowarn object Diffs { import com.softwaremill.diffx._ import com.softwaremill.diffx.cats._ - import com.softwaremill.diffx.generic.auto._ - implicit val diffNodeContext: Diff[NodeContext] = Diff.derivedDiff - implicit val diffContextRange: Diff[ContextRange] = Diff.derivedDiff - implicit val diffDiagnosticDetails: Diff[CompilationErrorDetails] = Diff.derivedDiff - implicit val diffDiagnostic: Diff[CompilationError] = Diff.derivedDiff + given Diff[ShapeId] = Diff.derived - implicit val diffUnit: Diff[Unit] = + given Diff[NodeContext.PathEntry] = Diff.derived + given Diff[NodeContext] = Diff[List[NodeContext.PathEntry]].contramap(_.toList) + given Diff[ContextRange] = Diff.derived + given Diff[TimestampFormat] = Diff.derived + given Diff[DiagnosticTag] = Diff.derived + given Diff[DiagnosticSeverity] = Diff.derived + given Diff[DeprecatedInfo] = Diff.derived + given Diff[CompilationErrorDetails] = Diff.derived + given Diff[CompilationError] = Diff.derived + + given Diff[Unit] = ( _, _, @@ -25,9 +34,9 @@ object Diffs { ) => IdenticalValue("unit") @nowarn("cat=unused") - implicit def diffForIor[E: Diff, A: Diff]: Diff[Ior[E, A]] = Diff.derivedDiff + given [E: Diff, A: Diff]: Diff[Ior[E, A]] = Diff.derived - implicit val diffByteArray: Diff[Blob] = Diff[String].contramap(_.toString()) - implicit val diffDocument: Diff[smithy4s.Document] = Diff.derivedDiff - implicit val diffTimestamp: Diff[smithy4s.Timestamp] = Diff[String].contramap(_.toString()) + given Diff[Blob] = Diff[String].contramap(_.toUTF8String) + given Diff[smithy4s.Document] = Diff.derived + given Diff[smithy4s.Timestamp] = Diff[String].contramap(_.toString()) } diff --git a/modules/core/src/test/scala/playground/MultiServiceResolverTests.scala b/modules/core/src/test/scala/playground/MultiServiceResolverTests.scala index 016ae2ab..1d0ea8f3 100644 --- a/modules/core/src/test/scala/playground/MultiServiceResolverTests.scala +++ b/modules/core/src/test/scala/playground/MultiServiceResolverTests.scala @@ -3,8 +3,8 @@ package playground import cats.Id import cats.implicits._ import com.softwaremill.diffx.cats._ -import playground.Diffs._ -import playground.smithyql.Diffs._ +import playground.Diffs.given +import playground.smithyql.Diffs.given import playground.smithyql.OperationName import playground.smithyql.Prelude import playground.smithyql.QualifiedIdentifier diff --git a/modules/core/src/test/scala/playground/PreludeCompilerTests.scala b/modules/core/src/test/scala/playground/PreludeCompilerTests.scala index 4b0a7896..47404c87 100644 --- a/modules/core/src/test/scala/playground/PreludeCompilerTests.scala +++ b/modules/core/src/test/scala/playground/PreludeCompilerTests.scala @@ -14,7 +14,7 @@ import playground.smithyql.parser.SourceParser import weaver._ import Assertions._ -import Diffs._ +import Diffs.given object PreludeCompilerTests extends FunSuite { diff --git a/modules/core/src/test/scala/playground/smithyql/AtPositionTests.scala b/modules/core/src/test/scala/playground/smithyql/AtPositionTests.scala index ef34be43..ac19583a 100644 --- a/modules/core/src/test/scala/playground/smithyql/AtPositionTests.scala +++ b/modules/core/src/test/scala/playground/smithyql/AtPositionTests.scala @@ -1,7 +1,7 @@ package playground.smithyql import playground.Assertions._ -import playground.Diffs._ +import playground.Diffs.given import playground.smithyql.parser.SourceParser import weaver._ diff --git a/modules/core/src/test/scala/playground/smithyql/CompilationTests.scala b/modules/core/src/test/scala/playground/smithyql/CompilationTests.scala index 3a1d880a..d5fadb80 100644 --- a/modules/core/src/test/scala/playground/smithyql/CompilationTests.scala +++ b/modules/core/src/test/scala/playground/smithyql/CompilationTests.scala @@ -34,7 +34,7 @@ import playground.CompiledInput import playground.DeprecatedInfo import playground.DiagnosticSeverity import playground.DiagnosticTag -import playground.Diffs._ +import playground.Diffs.given import playground.DynamicModel import playground.OperationCompiler import playground.PreludeCompiler diff --git a/modules/formatter/src/test/scala/playground/smithyql/format/FormattingTests.scala b/modules/formatter/src/test/scala/playground/smithyql/format/FormattingTests.scala index 7c819b78..06689558 100644 --- a/modules/formatter/src/test/scala/playground/smithyql/format/FormattingTests.scala +++ b/modules/formatter/src/test/scala/playground/smithyql/format/FormattingTests.scala @@ -11,7 +11,7 @@ import util.chaining._ import weaver._ import weaver.scalacheck.Checkers -import Diffs._ +import Diffs.given object FormattingTests extends SimpleIOSuite with Checkers { diff --git a/modules/language-support/src/main/scala/playground/language/CommandProvider.scala b/modules/language-support/src/main/scala/playground/language/CommandProvider.scala index 06411661..d18ed786 100644 --- a/modules/language-support/src/main/scala/playground/language/CommandProvider.scala +++ b/modules/language-support/src/main/scala/playground/language/CommandProvider.scala @@ -1,5 +1,6 @@ package playground.language +import cats.Applicative import cats.Id import cats.MonadThrow import cats.data.NonEmptyList @@ -28,33 +29,13 @@ trait CommandProvider[F[_]] { object CommandProvider { - def instance[F[_]: MonadThrow: TextDocumentProvider: CommandResultReporter]( + def instance[F[_]: MonadThrow: TextDocumentProvider]( compiler: FileCompiler[F], runner: FileRunner.Resolver[F], + )( + using reporter: CommandResultReporter[F] ): CommandProvider[F] = new CommandProvider[F] { - private val reporter = CommandResultReporter[F] - - private case class RunnerBuildErrors( - issues: NonEmptyList[OperationRunner.Issue.Squashed] - ) extends Exception { - - def report: F[Unit] = { - val (protocolIssues, otherIssues) = issues.toList.partitionMap { - case p: OperationRunner.Issue.Squashed.ProtocolIssues => p.asLeft - - case p: OperationRunner.Issue.Squashed.OtherIssues => p.asRight - } - - CommandResultReporter[F] - .onUnsupportedProtocol - .whenA(protocolIssues.nonEmpty) *> - otherIssues.traverse_ { case OperationRunner.Issue.Squashed.OtherIssues(others) => - CommandResultReporter[F].onIssues(others) - } - } - - } private case class QueryError( e: Throwable, @@ -134,4 +115,25 @@ object CommandProvider { } + private case class RunnerBuildErrors( + issues: NonEmptyList[OperationRunner.Issue.Squashed] + ) extends Exception { + + def report[F[_]: CommandResultReporter: Applicative]: F[Unit] = { + val (protocolIssues, otherIssues) = issues.toList.partitionMap { + case p: OperationRunner.Issue.Squashed.ProtocolIssues => p.asLeft + + case p: OperationRunner.Issue.Squashed.OtherIssues => p.asRight + } + + CommandResultReporter[F] + .onUnsupportedProtocol + .whenA(protocolIssues.nonEmpty) *> + otherIssues.traverse_ { case OperationRunner.Issue.Squashed.OtherIssues(others) => + CommandResultReporter[F].onIssues(others) + } + } + + } + } diff --git a/modules/language-support/src/test/scala/playground/language/CodeLensProviderTests.scala b/modules/language-support/src/test/scala/playground/language/CodeLensProviderTests.scala index e60c3970..a7fcb820 100644 --- a/modules/language-support/src/test/scala/playground/language/CodeLensProviderTests.scala +++ b/modules/language-support/src/test/scala/playground/language/CodeLensProviderTests.scala @@ -12,7 +12,7 @@ import playground.OperationRunner import playground.PreludeCompiler import playground.ServiceIndex import playground.ServiceUtils._ -import playground.language.Diffs._ +import playground.language.Diffs.given import playground.smithyql.StringRangeUtils._ import playground.std.RandomGen import weaver._ diff --git a/modules/language-support/src/test/scala/playground/language/CompletionItemTests.scala b/modules/language-support/src/test/scala/playground/language/CompletionItemTests.scala index bd40a413..89453aeb 100644 --- a/modules/language-support/src/test/scala/playground/language/CompletionItemTests.scala +++ b/modules/language-support/src/test/scala/playground/language/CompletionItemTests.scala @@ -11,7 +11,7 @@ import playground.std.ClockOperation import smithy4s.schema.Schema import weaver._ -import Diffs._ +import Diffs.given object CompletionItemTests extends FunSuite { test("CompletionItem.fromField: required field") { diff --git a/modules/language-support/src/test/scala/playground/language/CompletionProviderTests.scala b/modules/language-support/src/test/scala/playground/language/CompletionProviderTests.scala index 53c4fdc7..c2b8b5a5 100644 --- a/modules/language-support/src/test/scala/playground/language/CompletionProviderTests.scala +++ b/modules/language-support/src/test/scala/playground/language/CompletionProviderTests.scala @@ -4,7 +4,7 @@ import demo.smithy.DemoServiceGen import demo.smithy.DeprecatedServiceGen import playground.Assertions._ import playground.ServiceUtils._ -import playground.language.Diffs._ +import playground.language.Diffs.given import playground.smithyql.Position import playground.smithyql.QualifiedIdentifier import playground.smithyql.StringRangeUtils._ diff --git a/modules/language-support/src/test/scala/playground/language/CompletionTests.scala b/modules/language-support/src/test/scala/playground/language/CompletionTests.scala index 2a4b5d84..a6818de0 100644 --- a/modules/language-support/src/test/scala/playground/language/CompletionTests.scala +++ b/modules/language-support/src/test/scala/playground/language/CompletionTests.scala @@ -16,7 +16,7 @@ import demo.smithy.PrivacyTier import demo.smithy.SampleSparseList import demo.smithy.SampleSparseMap import playground.Assertions._ -import playground.language.Diffs._ +import playground.language.Diffs.given import playground.smithyql.NodeContext import playground.smithyql.NodeContext.PathEntry._ import smithy.api.TimestampFormat diff --git a/modules/language-support/src/test/scala/playground/language/DiagnosticProviderTests.scala b/modules/language-support/src/test/scala/playground/language/DiagnosticProviderTests.scala index d3e791f2..293a320e 100644 --- a/modules/language-support/src/test/scala/playground/language/DiagnosticProviderTests.scala +++ b/modules/language-support/src/test/scala/playground/language/DiagnosticProviderTests.scala @@ -19,7 +19,7 @@ import playground.CompilationError import playground.CompilationErrorDetails import playground.CompilationFailed import playground.DiagnosticSeverity -import playground.Diffs._ +import playground.Diffs.given import playground.FileCompiler import playground.FileRunner import playground.OperationCompiler diff --git a/modules/language-support/src/test/scala/playground/language/Diffs.scala b/modules/language-support/src/test/scala/playground/language/Diffs.scala index a06d1cec..ee6bc615 100644 --- a/modules/language-support/src/test/scala/playground/language/Diffs.scala +++ b/modules/language-support/src/test/scala/playground/language/Diffs.scala @@ -1,10 +1,15 @@ package playground.language import com.softwaremill.diffx.Diff +import playground.smithyql.Diffs.given object Diffs { - import com.softwaremill.diffx.generic.auto._ - implicit val diffCompletionItem: Diff[CompletionItem] = Diff.derivedDiff - implicit lazy val diffDocumentSymbol: Diff[DocumentSymbol] = Diff.derivedDiff - implicit lazy val diffCodeLens: Diff[CodeLens] = Diff.derivedDiff + given Diff[CompletionItemKind] = Diff.derived + given Diff[TextEdit] = Diff.derived + given Diff[InsertText] = Diff.derived + given Diff[CompletionItem] = Diff.derived + given Diff[SymbolKind] = Diff.derived + given Diff[DocumentSymbol] = Diff.derived + given Diff[Command] = Diff.derived + given Diff[CodeLens] = Diff.derived } diff --git a/modules/language-support/src/test/scala/playground/language/DocumentSymbolProviderTests.scala b/modules/language-support/src/test/scala/playground/language/DocumentSymbolProviderTests.scala index 08868c1b..ff2f02e4 100644 --- a/modules/language-support/src/test/scala/playground/language/DocumentSymbolProviderTests.scala +++ b/modules/language-support/src/test/scala/playground/language/DocumentSymbolProviderTests.scala @@ -1,7 +1,7 @@ package playground.language import playground.Assertions._ -import playground.language.Diffs._ +import playground.language.Diffs.given import playground.smithyql.Position import playground.smithyql.SourceRange import weaver._ diff --git a/modules/lsp/src/test/scala/playground/lsp/LanguageServerIntegrationTestSharedServer.scala b/modules/lsp/src/test/scala/playground/lsp/LanguageServerIntegrationTestSharedServer.scala index b0f4a819..9641a8da 100644 --- a/modules/lsp/src/test/scala/playground/lsp/LanguageServerIntegrationTestSharedServer.scala +++ b/modules/lsp/src/test/scala/playground/lsp/LanguageServerIntegrationTestSharedServer.scala @@ -29,33 +29,13 @@ object LanguageServerIntegrationTestSharedServer extends IOSuite with LanguageServerIntegrationTests { + override protected def checkStartupLogs: Boolean = true + type Res = Fixture def sharedResource: Resource[IO, Res] = makeServer(testWorkspacesBase / "default") - test("server init produces logs consistent with the workspace folder") { f => - val initLogs = List( - TestClient - .MessageLog( - MessageType.Info, - s"Hello from Smithy Playground v${BuildInfo.version}", - ), - TestClient.MessageLog( - MessageType.Info, - "Loaded Smithy Playground server with 2 imports, 2 dependencies and 0 plugins", - ), - ) - - // logs produced during an implicit initialization in the resource setup - f.client.getEvents.map { events => - assert.same( - events, - initLogs, - ) - } - } - - test("completions").apply { f => + test("completions") { f => f.server .completion( new CompletionParams( @@ -94,7 +74,7 @@ object LanguageServerIntegrationTestSharedServer report.getRelatedFullDocumentDiagnosticReport().getItems().asScala.toList assert(diagnosticItems.size == 1) && - assert(diagnosticItems.head.getSeverity() == DiagnosticSeverity.Error) && + assert.same(diagnosticItems.head.getSeverity(), DiagnosticSeverity.Error) && assert(diagnosticItems.head.getMessage.contains("Parsing failure")) } } @@ -312,7 +292,9 @@ object LanguageServerIntegrationTestSharedServer .map { events => assert.eql(events.length, 4) && assert.same(events(0), TestClient.OutputPanelShow) && - assert(events(1).asInstanceOf[TestClient.OutputLog].text.contains("Calling GetWeather")) && + assert( + events(1).asInstanceOf[TestClient.OutputLog].text.contains("Calling GetWeather") + ) && assert(events(2).asInstanceOf[TestClient.OutputLog].text.contains("// HTTP/1.1 GET")) && assert( events(3) diff --git a/modules/lsp/src/test/scala/playground/lsp/harness/LanguageServerIntegrationTests.scala b/modules/lsp/src/test/scala/playground/lsp/harness/LanguageServerIntegrationTests.scala index fd6b0607..6df452c3 100644 --- a/modules/lsp/src/test/scala/playground/lsp/harness/LanguageServerIntegrationTests.scala +++ b/modules/lsp/src/test/scala/playground/lsp/harness/LanguageServerIntegrationTests.scala @@ -1,18 +1,24 @@ package playground.lsp.harness import cats.effect.IO +import cats.effect.IOLocal import cats.effect.Resource +import cats.implicits._ import org.eclipse.lsp4j.InitializeParams +import org.eclipse.lsp4j.MessageType import org.eclipse.lsp4j.WorkspaceFolder import playground.language.Uri import playground.lsp.LanguageServer import playground.lsp.MainServer +import playground.lsp.buildinfo.BuildInfo import scala.jdk.CollectionConverters._ import scala.util.chaining._ trait LanguageServerIntegrationTests { + protected def checkStartupLogs: Boolean = false + case class Fixture( server: LanguageServer[IO], client: TestClient[IO], @@ -34,16 +40,56 @@ trait LanguageServerIntegrationTests { ): Resource[IO, Fixture] = TestClient.forIO.toResource.flatMap { implicit client => MainServer .makeServer[IO] - .evalTap(_.initialize(initParams(workspaceDir))) - .map { server => - Fixture( + .evalMap { server => + val result = Fixture( server = server, client = client, workspaceDir = workspaceDir, ) + + server.initialize(initParams(workspaceDir)) *> + assertStartupEvents(client) + .as(result) } } + /* + * Note - this should've been a test (and used to). + * For some reason, it no longer worked because logs produced by the initialize call were suddenly being lost after resource initialization. + * The underlying cause for event loss was broken IOLocal propagation in the event of lifting resources to fs2 streams + * (resulting in the resource being acquired step-by-step with multiple fibers). + * + * If the underlying issue is solved, this can again be turned into a test. + */ + private def assertStartupEvents( + client: TestClient[IO] + ): IO[Unit] = client + .getEvents + .flatMap { events => + val initLogs = List( + TestClient + .MessageLog( + MessageType.Info, + s"Hello from Smithy Playground v${BuildInfo.version}", + ), + TestClient.MessageLog( + MessageType.Info, + "Loaded Smithy Playground server with 2 imports, 2 dependencies and 0 plugins", + ), + ) + IO { + require( + events.size == 2, + "Events emitted at startup should've had size 2, it was " + events.size + " instead", + ) + require( + events == initLogs, + "Events were not as expected, got: " + events, + ) + } + } + .whenA(checkStartupLogs) + def testWorkspacesBase: Uri = Uri.fromUriString( getClass .getResource("/test-workspaces") diff --git a/modules/lsp/src/test/scala/playground/lsp/harness/TestClient.scala b/modules/lsp/src/test/scala/playground/lsp/harness/TestClient.scala index 12a26d6b..6198bbd8 100644 --- a/modules/lsp/src/test/scala/playground/lsp/harness/TestClient.scala +++ b/modules/lsp/src/test/scala/playground/lsp/harness/TestClient.scala @@ -12,6 +12,7 @@ import playground.lsp.LanguageClient trait TestClient[F[_]] extends LanguageClient[F] { def getEvents: F[List[TestClient.Event]] + def scoped: F ~> F def withConfiguration( diff --git a/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala b/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala index 19946228..49dd4c34 100644 --- a/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala +++ b/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala @@ -240,7 +240,7 @@ object Scanner { readAny .lift(()) .isDefined || - eatErrors(): Unit + eatErrors() // last-effort sanity check if (remaining == last) diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala b/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala index 06cdffb8..0ecd42e8 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala @@ -1,28 +1,40 @@ package playground.smithyql.parser import io.circe.Codec +import playground.smithyql.Binding +import playground.smithyql.Comment +import playground.smithyql.InputNode import playground.smithyql.Listed import playground.smithyql.Prelude +import playground.smithyql.QualifiedIdentifier import playground.smithyql.Query import playground.smithyql.SourceFile +import playground.smithyql.SourceRange +import playground.smithyql.Statement import playground.smithyql.Struct import playground.smithyql.UseClause import playground.smithyql.WithSource object Codecs { - import io.circe.generic.auto._ - import io.circe.generic.semiauto._ + given Codec[QualifiedIdentifier] = Codec.AsObject.derived + given Codec[Comment] = Codec.AsObject.derived + given Codec[SourceRange] = Codec.AsObject.derived + given [A: Codec]: Codec[WithSource[A]] = Codec.AsObject.derived - implicit val useClauseWithSourceCodec: Codec[UseClause[WithSource]] = deriveCodec + given Codec[UseClause[WithSource]] = Codec.AsObject.derived - implicit val listedWithSourceCodec: Codec[Listed[WithSource]] = deriveCodec + given Codec[InputNode[WithSource]] = Codec.AsObject.derived + given Codec[Listed[WithSource]] = Codec.AsObject.derived - implicit val structWithSourceCodec: Codec[Struct[WithSource]] = deriveCodec + given Codec[Binding[WithSource]] = Codec.AsObject.derived + given Codec[Struct.Fields[WithSource]] = Codec.AsObject.derived + given Codec[Struct[WithSource]] = Codec.AsObject.derived - implicit val queryWithSourceCodec: Codec[Query[WithSource]] = deriveCodec + given Codec[Query[WithSource]] = Codec.AsObject.derived - implicit val preludeWithSourceCodec: Codec[Prelude[WithSource]] = deriveCodec + given Codec[Prelude[WithSource]] = Codec.AsObject.derived - implicit val sourceFileWithSourceCodec: Codec[SourceFile[WithSource]] = deriveCodec + given Codec[Statement[WithSource]] = Codec.AsObject.derived + given Codec[SourceFile[WithSource]] = Codec.AsObject.derived } diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/Diffs.scala b/modules/parser/src/test/scala/playground/smithyql/parser/Diffs.scala index 090a1e9a..1367d882 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/Diffs.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/Diffs.scala @@ -1,9 +1,9 @@ package playground.smithyql.parser +import cats.parse.Parser import com.softwaremill.diffx.Diff object Diffs { - import com.softwaremill.diffx.generic.auto._ - - implicit val diffParsingFailure: Diff[ParsingFailure] = Diff.derivedDiff + given Diff[Parser.Error] = Diff.useEquals + given Diff[ParsingFailure] = Diff.derived } diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/ListParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/ListParserTests.scala index bbb62af6..ee541c6f 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/ListParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/ListParserTests.scala @@ -1,9 +1,10 @@ package playground.smithyql.parser.generative -import playground.smithyql.Diffs._ +import playground.smithyql.Diffs.given import playground.smithyql._ -import playground.smithyql.parser.Codecs._ +import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite +import playground.smithyql.parser.SourceParser object ListParserTests extends ParserSuite { loadParserTests[Listed]("listed", trimWhitespace = true) diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/PreludeParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/PreludeParserTests.scala index c34b5e54..455394ff 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/PreludeParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/PreludeParserTests.scala @@ -1,8 +1,8 @@ package playground.smithyql.parser.generative -import playground.smithyql.Diffs._ +import playground.smithyql.Diffs.given import playground.smithyql._ -import playground.smithyql.parser.Codecs._ +import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite object PreludeParserTests extends ParserSuite { diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/QueryParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/QueryParserTests.scala index 9b82eae4..f5fc330b 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/QueryParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/QueryParserTests.scala @@ -1,8 +1,8 @@ package playground.smithyql.parser.generative -import playground.smithyql.Diffs._ +import playground.smithyql.Diffs.given import playground.smithyql._ -import playground.smithyql.parser.Codecs._ +import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite object QueryParserTests extends ParserSuite { diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala index 6bb5190e..736e6dd1 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala @@ -1,8 +1,8 @@ package playground.smithyql.parser.generative -import playground.smithyql.Diffs._ +import playground.smithyql.Diffs.given import playground.smithyql._ -import playground.smithyql.parser.Codecs._ +import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite object SourceFileParserTests extends ParserSuite { diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/StructParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/StructParserTests.scala index a9ba9005..55a6e6d1 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/StructParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/StructParserTests.scala @@ -1,8 +1,8 @@ package playground.smithyql.parser.generative -import playground.smithyql.Diffs._ +import playground.smithyql.Diffs.given import playground.smithyql._ -import playground.smithyql.parser.Codecs._ +import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite object StructParserTests extends ParserSuite { diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/UseServiceParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/UseServiceParserTests.scala index ccb8aa67..6160468d 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/UseServiceParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/UseServiceParserTests.scala @@ -1,8 +1,8 @@ package playground.smithyql.parser.generative -import playground.smithyql.Diffs._ +import playground.smithyql.Diffs.given import playground.smithyql._ -import playground.smithyql.parser.Codecs._ +import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite object UseServiceParserTests extends ParserSuite { diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerSuite.scala b/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerSuite.scala index 4c78d373..94eb7381 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerSuite.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerSuite.scala @@ -9,7 +9,7 @@ import playground.smithyql.parser.v2.scanner.Scanner import playground.smithyql.parser.v2.scanner.Token import weaver._ -import Diffs._ +import Diffs.given import Scanner.scan trait ScannerSuite { self: IOSuite => diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerTests.scala index 7b746be0..9336e073 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerTests.scala @@ -10,7 +10,7 @@ import playground.smithyql.parser.v2.scanner.TokenKind._ import weaver._ import weaver.scalacheck.Checkers -import Diffs._ +import Diffs.given import Scanner.scan object ScannerTests extends SimpleIOSuite with Checkers with ScannerSuite { diff --git a/modules/source/src/main/scala/playground/smithyql/WithSource.scala b/modules/source/src/main/scala/playground/smithyql/WithSource.scala index 75a92c41..edec262e 100644 --- a/modules/source/src/main/scala/playground/smithyql/WithSource.scala +++ b/modules/source/src/main/scala/playground/smithyql/WithSource.scala @@ -9,13 +9,11 @@ import cats.implicits._ import cats.kernel.Eq import cats.kernel.Order import cats.~> -import playground.smithyql.InputNode -import playground.smithyql.Query // todo: multiline final case class Comment( text: String -) extends AnyVal +) object Comment { implicit val eq: Eq[Comment] = Eq.by(_.text) diff --git a/modules/source/src/test/scala/playground/smithyql/Diffs.scala b/modules/source/src/test/scala/playground/smithyql/Diffs.scala index 15a39f50..800398a3 100644 --- a/modules/source/src/test/scala/playground/smithyql/Diffs.scala +++ b/modules/source/src/test/scala/playground/smithyql/Diffs.scala @@ -1,27 +1,48 @@ package playground.smithyql +import cats.Id import com.softwaremill.diffx.Diff object Diffs { import com.softwaremill.diffx.cats._ import com.softwaremill.diffx.generic.auto._ - implicit val diffSourceRange: Diff[SourceRange] = Diff.derivedDiff + given Diff[Position] = Diff.derived - implicit val diffComment: Diff[Comment] = Diff.derivedDiff + given Diff[SourceRange] = Diff.derived - implicit val diffQualifiedIdentifier: Diff[QualifiedIdentifier] = Diff.derivedDiff + given Diff[Comment] = Diff.derived - implicit val diffUseClause: Diff[UseClause[WithSource]] = Diff.derivedDiff + given Diff[QualifiedIdentifier] = Diff.derived - implicit def diffListedWithSource: Diff[Listed[WithSource]] = Diff.derivedDiff + given [A: Diff]: Diff[WithSource[A]] = Diff.derived - implicit val diffStructWithSource: Diff[Struct[WithSource]] = Diff.derivedDiff + given Diff[UseClause[WithSource]] = Diff.derived - implicit val diffQueryWithSource: Diff[Query[WithSource]] = Diff.derivedDiff + given Diff[InputNode[WithSource]] = Diff.derived - implicit val diffPreludeWithSource: Diff[Prelude[WithSource]] = Diff.derivedDiff + given Diff[Listed[WithSource]] = Diff.derived - implicit val diffSourceFile: Diff[SourceFile[WithSource]] = Diff.derivedDiff + given Diff[NodeKind] = Diff.derived + given Diff[Identifier] = Diff.derived + + given Diff[Binding[WithSource]] = Diff.derived + + given Diff[Struct.Fields[WithSource]] = Diff.derived + + given Diff[Struct[WithSource]] = Diff.derived + + given Diff[OperationName[WithSource]] = Diff.derived + given opNameDiffId: Diff[OperationName[Id]] = Diff.derived + + given Diff[QueryOperationName[WithSource]] = Diff.derived + + given Diff[Query[WithSource]] = Diff.derived + + given Diff[Prelude[WithSource]] = Diff.derived + + given Diff[Statement[WithSource]] = Diff.derived + + given Diff[SourceFile[WithSource]] = Diff.derived } From a25469ba22c5943f6773188819ce82fb23c36d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 11 Oct 2023 00:58:07 +0200 Subject: [PATCH 03/15] disable mima --- build.sbt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index cdd6fe34..e29c5080 100644 --- a/build.sbt +++ b/build.sbt @@ -83,7 +83,8 @@ lazy val pluginCore = module("plugin-core").settings( libraryDependencies ++= Seq( "com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value ), - mimaPreviousArtifacts := Set(organization.value %% name.value % "0.7.0"), + // mimaPreviousArtifacts := Set(organization.value %% name.value % "0.7.0"), + mimaPreviousArtifacts := Set.empty, ) lazy val pluginSample = module("plugin-sample") From 1710cd40f22019725aa23fd26d0c1a3de7062f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 11 Oct 2023 01:03:53 +0200 Subject: [PATCH 04/15] Fix extension --- vscode-extension/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vscode-extension/package.json b/vscode-extension/package.json index 46cdadd8..e9698d94 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -77,7 +77,7 @@ "smithyql.server.artifact": { "type": "string", "description": "The coordinates to the language server artifact", - "default": "com.kubukoz.playground:lsp_2.13" + "default": "com.kubukoz.playground:lsp_3" }, "smithyql.server.version": { "type": "string", From 70c42f5e13339978dcdcfd22f390ada719800713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 00:58:12 +0100 Subject: [PATCH 05/15] fix tests --- ...ageServerIntegrationTestSharedServer.scala | 22 ------------------- .../LanguageServerIntegrationTests.scala | 3 ++- .../playground/smithyql/parser/Codecs.scala | 13 +++++++++-- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/modules/lsp/src/test/scala/playground/lsp/LanguageServerIntegrationTestSharedServer.scala b/modules/lsp/src/test/scala/playground/lsp/LanguageServerIntegrationTestSharedServer.scala index 05c00ee5..a85b39e2 100644 --- a/modules/lsp/src/test/scala/playground/lsp/LanguageServerIntegrationTestSharedServer.scala +++ b/modules/lsp/src/test/scala/playground/lsp/LanguageServerIntegrationTestSharedServer.scala @@ -35,28 +35,6 @@ object LanguageServerIntegrationTestSharedServer def sharedResource: Resource[IO, Res] = makeServer(testWorkspacesBase / "default") - test("server init produces logs consistent with the workspace folder") { f => - val initLogs = List( - TestClient - .MessageLog( - MessageType.Info, - s"Hello from Smithy Playground v${BuildInfo.version}", - ), - TestClient.MessageLog( - MessageType.Info, - "Loaded Smithy Playground server with 2 sources, 0 imports, 2 dependencies and 0 plugins", - ), - ) - - // logs produced during an implicit initialization in the resource setup - f.client.getEvents.map { events => - assert.same( - events, - initLogs, - ) - } - } - test("completions").apply { f => f.server .completion( diff --git a/modules/lsp/src/test/scala/playground/lsp/harness/LanguageServerIntegrationTests.scala b/modules/lsp/src/test/scala/playground/lsp/harness/LanguageServerIntegrationTests.scala index 7526b413..231ce510 100644 --- a/modules/lsp/src/test/scala/playground/lsp/harness/LanguageServerIntegrationTests.scala +++ b/modules/lsp/src/test/scala/playground/lsp/harness/LanguageServerIntegrationTests.scala @@ -11,6 +11,7 @@ import playground.language.Uri import playground.lsp.LanguageServer import playground.lsp.MainServer import playground.lsp.buildinfo.BuildInfo +import weaver.SourceLocation import scala.jdk.CollectionConverters.* import scala.util.chaining.* @@ -74,7 +75,7 @@ trait LanguageServerIntegrationTests { ), TestClient.MessageLog( MessageType.Info, - "Loaded Smithy Playground server with 2 imports, 2 dependencies and 0 plugins", + "Loaded Smithy Playground server with 2 sources, 0 imports, 2 dependencies and 0 plugins", ), ) IO { diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala b/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala index 1d9b2dd2..3e9fb4fc 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala @@ -1,6 +1,8 @@ package playground.smithyql.parser import io.circe.Codec +import io.circe.Decoder +import io.circe.Encoder import playground.smithyql.Binding import playground.smithyql.Comment import playground.smithyql.Diffs.given @@ -31,9 +33,16 @@ object Codecs { given Codec[UseClause[WithSource]] = Codec.AsObject.derived - // why list though? recursion limit? - given Codec[List[WithSource[InputNode[WithSource]]]] = Codec.AsObject.derived + given Codec[WithSource[InputNode[WithSource]]] = Codec.AsObject.derived + given Codec[InputNode[WithSource]] = Codec.AsObject.derived + + // strange thing - somehow doesn't get picked up automatically. + given Codec[List[WithSource[InputNode[WithSource]]]] = Codec.from( + Decoder.decodeList, + Encoder.encodeList, + ) + given Codec[Listed[WithSource]] = Codec.AsObject.derived given Codec[Binding[WithSource]] = Codec.AsObject.derived From a77c9c12484e0f87713040c87b244e2a2b722f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:01:36 +0100 Subject: [PATCH 06/15] scalafmt and so on --- .scalafix.conf | 15 -- .scalafmt.conf | 10 +- build.sbt | 2 - .../scala/playground/CompilationError.scala | 2 +- .../smithyql/CompilationTests.scala | 188 +++++++++++++----- .../scala/playground/lsp/ModelLoader.scala | 25 +-- .../lsp/PlaygroundLanguageServerAdapter.scala | 22 +- .../playground/smithyql/parser/Parsers.scala | 2 +- .../smithyql/parser/v2/scanner.scala | 6 - project/plugins.sbt | 1 - 10 files changed, 167 insertions(+), 106 deletions(-) delete mode 100644 .scalafix.conf diff --git a/.scalafix.conf b/.scalafix.conf deleted file mode 100644 index 52ce77eb..00000000 --- a/.scalafix.conf +++ /dev/null @@ -1,15 +0,0 @@ -rules = [ - NoAutoTupling, - DisableSyntax, - LeakingImplicitClassVal, - NoValInForComprehension, - RedundantSyntax, - RemoveUnused -] - -DisableSyntax.noVars = true -DisableSyntax.noNulls = true -DisableSyntax.noReturns = true -DisableSyntax.noWhileLoops = true - -OrganizeImports.targetDialect = Scala3 diff --git a/.scalafmt.conf b/.scalafmt.conf index 537363ff..2a7079ed 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,5 +1,9 @@ +version = 3.8.3 + runner.dialect=scala3 -version = 3.7.2 +runner.dialectOverride.allowSignificantIndentation = false +runner.dialectOverride.allowQuietSyntax = true + maxColumn = 100 align.preset = some @@ -17,6 +21,10 @@ assumeStandardLibraryStripMargin = true trailingCommas = "multiple" +project { + git = true +} + rewrite.rules = [ RedundantBraces, RedundantParens, diff --git a/build.sbt b/build.sbt index 71f89c1f..b778c6c6 100644 --- a/build.sbt +++ b/build.sbt @@ -72,8 +72,6 @@ val commonSettings = Seq( Test / scalacOptions += "-Wconf:cat=deprecation:silent,msg=Specify both message and version:silent", scalacOptions ++= Seq("-release", "11"), mimaFailOnNoPrevious := false, - semanticdbEnabled := true, - semanticdbVersion := scalafixSemanticdb.revision, ) def module( diff --git a/modules/core/src/main/scala/playground/CompilationError.scala b/modules/core/src/main/scala/playground/CompilationError.scala index 606d8487..f83391a9 100644 --- a/modules/core/src/main/scala/playground/CompilationError.scala +++ b/modules/core/src/main/scala/playground/CompilationError.scala @@ -112,7 +112,7 @@ sealed trait CompilationErrorDetails extends Product with Serializable { case DuplicateItem => "Duplicate item - some entries will be dropped to fit in a set shape." case AmbiguousService(workspaceServices) => """Couldn't determine service for this operation. Add a use clause, or use an explicit reference to specify the service you want to use. - |Available services:""".stripMargin + workspaceServices + |Available services:""".stripMargin + workspaceServices .sorted .map(UseClause[Id](_).mapK(WithSource.liftId)) .map(Formatter.useClauseFormatter.format(_, Int.MaxValue)) diff --git a/modules/core/src/test/scala/playground/smithyql/CompilationTests.scala b/modules/core/src/test/scala/playground/smithyql/CompilationTests.scala index 5f74eb7d..df270c1b 100644 --- a/modules/core/src/test/scala/playground/smithyql/CompilationTests.scala +++ b/modules/core/src/test/scala/playground/smithyql/CompilationTests.scala @@ -154,7 +154,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId(struct().mapK(WithSource.liftId)) - }(using Schema.unit).isRight + }( + using Schema.unit + ).isRight ) } @@ -162,7 +164,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId("test".mapK(WithSource.liftId)) - }(using Schema.unit).isLeft + }( + using Schema.unit + ).isLeft ) } @@ -170,7 +174,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId(struct("test" -> 42).mapK(WithSource.liftId)) - }(using Schema.unit).isBoth + }( + using Schema.unit + ).isBoth ) } @@ -178,7 +184,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId("foo".mapK(WithSource.liftId)) - }(using Schema.string) == Ior.right("foo") + }( + using Schema.string + ) == Ior.right("foo") ) } @@ -195,7 +203,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { val result = compile { WithSource.liftId("".mapK(WithSource.liftId)) - }(using dynamicStringSchema) + }( + using dynamicStringSchema + ) .leftMap(_.map(_.err.asInstanceOf[CompilationErrorDetails.RefinementFailure])) assert( @@ -208,7 +218,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { val result = compile { WithSource.liftId(struct("minLength" -> "").mapK(WithSource.liftId)) - }(using dynamicStringSchema) + }( + using dynamicStringSchema + ) .leftMap(_.map(_.err.asInstanceOf[CompilationErrorDetails.RefinementFailure])) assert( @@ -220,7 +232,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId(42.mapK(WithSource.liftId)) - }(using Schema.string) == Ior.left( + }( + using Schema.string + ) == Ior.left( NonEmptyChain.of( CompilationError.error( CompilationErrorDetails.TypeMismatch( @@ -238,7 +252,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(Long.MaxValue.mapK(WithSource.liftId)) - }(using Schema.long), + }( + using Schema.long + ), Ior.right(Long.MaxValue), ) } @@ -247,7 +263,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId((BigInt(Long.MaxValue) + 1).mapK(WithSource.liftId)) - }(using Schema.long).isLeft + }( + using Schema.long + ).isLeft ) } @@ -255,7 +273,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(42.mapK(WithSource.liftId)) - }(using Schema.int), + }( + using Schema.int + ), Ior.right(42), ) } @@ -264,7 +284,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId((Int.MaxValue.toLong + 1L).mapK(WithSource.liftId)) - }(using Schema.int).isLeft + }( + using Schema.int + ).isLeft ) } @@ -272,7 +294,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(IntLiteral("1e2").mapK(WithSource.liftId)) - }(using Schema.int), + }( + using Schema.int + ), Ior.right(100), ) } @@ -281,7 +305,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId(IntLiteral("10.1e0").mapK(WithSource.liftId)) - }(using Schema.int).isLeft + }( + using Schema.int + ).isLeft ) } @@ -300,7 +326,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId((Short.MaxValue + 1).mapK(WithSource.liftId)) - }(using Schema.short).isLeft + }( + using Schema.short + ).isLeft ) } @@ -308,7 +336,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(IntLiteral("1e2").mapK(WithSource.liftId)) - }(using Schema.short), + }( + using Schema.short + ), Ior.right(100.toShort), ) } @@ -317,7 +347,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(Byte.MaxValue.mapK(WithSource.liftId)) - }(using Schema.byte), + }( + using Schema.byte + ), Ior.right(127.toByte), ) } @@ -326,7 +358,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId((Byte.MaxValue + 1).mapK(WithSource.liftId)) - }(using Schema.byte).isLeft + }( + using Schema.byte + ).isLeft ) } @@ -334,7 +368,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(IntLiteral("1e2").mapK(WithSource.liftId)) - }(using Schema.byte), + }( + using Schema.byte + ), Ior.right(100.toByte), ) } @@ -343,7 +379,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert.same( compile { WithSource.liftId(Float.MaxValue.mapK(WithSource.liftId)) - }(using Schema.float), + }( + using Schema.float + ), Ior.right(Float.MaxValue), ) } @@ -352,7 +390,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId(Double.MaxValue.toString.mapK(WithSource.liftId)) - }(using Schema.float).isLeft + }( + using Schema.float + ).isLeft ) } @@ -360,7 +400,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(IntLiteral("0.1e0").mapK(WithSource.liftId)) - }(using Schema.float), + }( + using Schema.float + ), Ior.right(0.1f), ) } @@ -369,7 +411,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(Double.MaxValue.mapK(WithSource.liftId)) - }(using Schema.double), + }( + using Schema.double + ), Ior.right(Double.MaxValue), ) } @@ -378,7 +422,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId((BigDecimal(Double.MaxValue) + 1).mapK(WithSource.liftId)) - }(using Schema.double), + }( + using Schema.double + ), Ior.right(Double.MaxValue), ) } @@ -387,7 +433,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(IntLiteral("0.1e0").mapK(WithSource.liftId)) - }(using Schema.double), + }( + using Schema.double + ), Ior.right(0.1), ) } @@ -397,7 +445,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(bi.mapK(WithSource.liftId)) - }(using Schema.bigint), + }( + using Schema.bigint + ), Ior.right(bi), ) } @@ -407,7 +457,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId("40.50".mapK(WithSource.liftId)) - }(using Schema.bigint).isLeft + }( + using Schema.bigint + ).isLeft ) } @@ -415,7 +467,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(IntLiteral("1e2").mapK(WithSource.liftId)) - }(using Schema.bigint), + }( + using Schema.bigint + ), Ior.right(BigInt(100)), ) } @@ -425,7 +479,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(bd.mapK(WithSource.liftId)) - }(using Schema.bigdecimal), + }( + using Schema.bigdecimal + ), Ior.right(bd), ) } @@ -435,7 +491,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId("AAAA".mapK(WithSource.liftId)) - }(using Schema.bigdecimal).isLeft + }( + using Schema.bigdecimal + ).isLeft ) } @@ -443,7 +501,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(IntLiteral("1e2").mapK(WithSource.liftId)) - }(using Schema.bigdecimal), + }( + using Schema.bigdecimal + ), Ior.right(BigDecimal(100)), ) } @@ -452,7 +512,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(true.mapK(WithSource.liftId)) - }(using Schema.boolean), + }( + using Schema.boolean + ), Ior.right(true), ) } @@ -461,7 +523,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId(NullLiteral[WithSource]()) - }(using Schema.document), + }( + using Schema.document + ), Ior.right(Document.nullDoc), ) } @@ -470,7 +534,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId(NullLiteral[WithSource]()) - }(using Schema.string).isLeft + }( + using Schema.string + ).isLeft ) } @@ -478,7 +544,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assertNoDiff( compile { WithSource.liftId("dGVzdA==".mapK(WithSource.liftId)) - }(using Schema.bytes), + }( + using Schema.bytes + ), Ior.right(Blob("test".getBytes())), ) } @@ -487,7 +555,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile { WithSource.liftId("XYI519274n91lasdf/a'\'...,,".mapK(WithSource.liftId)) - }(using Schema.bytes).isLeft + }( + using Schema.bytes + ).isLeft ) } @@ -600,7 +670,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { WithSource.liftId { struct("name" -> "foo").mapK(WithSource.liftId) } - }(using dynamicSchemaFor[HasMixin]).void + }( + using dynamicSchemaFor[HasMixin] + ).void val expected = Ior.left( NonEmptyChain.of( @@ -740,7 +812,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { Ior.right(Document.obj("enumWithLength" -> Document.fromString("AB"))), compile( WithSource.liftId(struct("enumWithLength" -> "AB").mapK(WithSource.liftId)) - )(using dynamicSchemaFor[EnumStruct]), + )( + using dynamicSchemaFor[EnumStruct] + ), ) } @@ -748,7 +822,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile( WithSource.liftId(struct("enumWithLength" -> "ABC").mapK(WithSource.liftId)) - )(using dynamicSchemaFor[EnumStruct]).isLeft + )( + using dynamicSchemaFor[EnumStruct] + ).isLeft ) } @@ -757,7 +833,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { Ior.right(Document.obj("intEnumWithRange" -> Document.fromInt(2))), compile( WithSource.liftId(struct("intEnumWithRange" -> "QUEEN").mapK(WithSource.liftId)) - )(using dynamicSchemaFor[EnumStruct]), + )( + using dynamicSchemaFor[EnumStruct] + ), ) } @@ -765,7 +843,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile( WithSource.liftId(struct("intEnumWithRange" -> "KING").mapK(WithSource.liftId)) - )(using dynamicSchemaFor[EnumStruct]).isLeft + )( + using dynamicSchemaFor[EnumStruct] + ).isLeft ) } @@ -774,7 +854,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { Ior.right(Document.obj("enumWithPattern" -> Document.fromString("AB"))), compile( WithSource.liftId(struct("enumWithPattern" -> "AB").mapK(WithSource.liftId)) - )(using dynamicSchemaFor[EnumStruct]), + )( + using dynamicSchemaFor[EnumStruct] + ), ) } @@ -782,7 +864,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert( compile( WithSource.liftId(struct("enumWithPattern" -> "ABC").mapK(WithSource.liftId)) - )(using dynamicSchemaFor[EnumStruct]).isLeft + )( + using dynamicSchemaFor[EnumStruct] + ).isLeft ) } @@ -853,7 +937,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { assert.same( compile( WithSource.liftId(List[InputNode[Id]](1, NullLiteral(), 3).mapK(WithSource.liftId)) - )(using dynamicSchemaFor[SampleSparseList]).leftMap(_.map(_.err)), + )( + using dynamicSchemaFor[SampleSparseList] + ).leftMap(_.map(_.err)), Ior.right( Document.array( List( @@ -933,7 +1019,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { ) ) ) - )(using dynamicSchemaFor[IntSet]) + )( + using dynamicSchemaFor[IntSet] + ) assert( actual == Ior.both( @@ -984,7 +1072,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { item, ).mapK(WithSource.liftId) ) - )(using dynamicSchemaFor[FriendSet]) + )( + using dynamicSchemaFor[FriendSet] + ) .leftMap(_.map(_.err)) assertNoDiff( @@ -1049,7 +1139,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { test("anything to document matches") { forall((wast: QueryCompiler.WAST) => assert( - compile[Document](wast)(using Schema.document).isRight + compile[Document](wast)( + using Schema.document + ).isRight ) ) } @@ -1063,7 +1155,9 @@ object CompilationTests extends SimpleIOSuite with Checkers { struct("name" -> "aaa"), ).mapK(WithSource.liftId) ) - )(using Schema.document), + )( + using Schema.document + ), Ior.right( Document.array( Document.obj( diff --git a/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala b/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala index 8f431a80..cf456ab8 100644 --- a/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala +++ b/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala @@ -72,10 +72,7 @@ object ModelLoader { ): List[URL] = Using.resource( // Note: On JDK13+, the second parameter is redundant. - FileSystems.newFileSystem( - file.toPath(), - null: ClassLoader @SuppressWarnings(Array("scalafix:DisableSyntax.null")), - ) + FileSystems.newFileSystem(file.toPath(), null: ClassLoader) ) { jarFS => val manifestPath = jarFS.getPath("META-INF", "smithy", "manifest") @@ -99,23 +96,19 @@ object ModelLoader { private def addFileImports( imports: Iterable[File] - ): ModelAssembler => ModelAssembler = { - assembler => { - imports.foreach(f => assembler.addImport(f.toPath())) - assembler - } + ): ModelAssembler => ModelAssembler = { assembler => + imports.foreach(f => assembler.addImport(f.toPath())) + assembler } private def addPlaygroundModels( classLoader: ClassLoader - ): ModelAssembler => ModelAssembler = { - assembler => { - List( - "META-INF/smithy/std.smithy" - ).map(classLoader.getResource).foreach(assembler.addImport) + ): ModelAssembler => ModelAssembler = { assembler => + List( + "META-INF/smithy/std.smithy" + ).map(classLoader.getResource).foreach(assembler.addImport) - assembler - } + assembler } def resolveModelDependencies( diff --git a/modules/lsp/src/main/scala/playground/lsp/PlaygroundLanguageServerAdapter.scala b/modules/lsp/src/main/scala/playground/lsp/PlaygroundLanguageServerAdapter.scala index 5d5bf861..0695da52 100644 --- a/modules/lsp/src/main/scala/playground/lsp/PlaygroundLanguageServerAdapter.scala +++ b/modules/lsp/src/main/scala/playground/lsp/PlaygroundLanguageServerAdapter.scala @@ -36,9 +36,7 @@ final class PlaygroundLanguageServerAdapter[F[_]: Functor]( @JsonRequest("shutdown") def shutdown( - ): CompletableFuture[Object] = d.unsafeToCompletableFuture( - impl.shutdown.as(null: Object): @SuppressWarnings(Array("scalafix:DisableSyntax.null")) - ) + ): CompletableFuture[Object] = d.unsafeToCompletableFuture(impl.shutdown.as(null: Object)) @JsonNotification("textDocument/didChange") def didChange( @@ -99,12 +97,9 @@ final class PlaygroundLanguageServerAdapter[F[_]: Functor]( @JsonRequest("workspace/executeCommand") def executeCommand( params: ExecuteCommandParams - ): CompletableFuture[Object] = d - .unsafeToCompletableFuture( - impl - .executeCommand(params) - .as(null: Object): @SuppressWarnings(Array("scalafix:DisableSyntax.null")) - ) + ): CompletableFuture[Object] = d.unsafeToCompletableFuture( + impl.executeCommand(params).as(null: Object) + ) @JsonNotification("workspace/didChangeWatchedFiles") def didChangeWatchedFiles( @@ -123,15 +118,10 @@ final class PlaygroundLanguageServerAdapter[F[_]: Functor]( @JsonRequest("smithyql/runQuery") def runQuery( params: RunFileParams - ): CompletableFuture[Object] = d - .unsafeToCompletableFuture( - impl.runFile(params).as(null: Object): @SuppressWarnings(Array("scalafix:DisableSyntax.null")) - ) + ): CompletableFuture[Object] = d.unsafeToCompletableFuture(impl.runFile(params).as(null: Object)) @JsonRequest("exit") def exit( - ): CompletableFuture[Object] = d.unsafeToCompletableFuture( - impl.exit.as(null: Object): @SuppressWarnings(Array("scalafix:DisableSyntax.null")) - ) + ): CompletableFuture[Object] = d.unsafeToCompletableFuture(impl.exit.as(null: Object)) } diff --git a/modules/parser/src/main/scala/playground/smithyql/parser/Parsers.scala b/modules/parser/src/main/scala/playground/smithyql/parser/Parsers.scala index e6305336..1ac00fe7 100644 --- a/modules/parser/src/main/scala/playground/smithyql/parser/Parsers.scala +++ b/modules/parser/src/main/scala/playground/smithyql/parser/Parsers.scala @@ -170,7 +170,7 @@ object Parsers { ( // soft: allows backtracking if hash isn't present (for operation names) - segments.soft ~ (tokens.hash *> tokens.whitespace *> rawIdent), + segments.soft ~ (tokens.hash *> tokens.whitespace *> rawIdent) ).map(QualifiedIdentifier.apply.tupled) }.withContext("qualified_ident") diff --git a/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala b/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala index 3403fd20..ec24e6c2 100644 --- a/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala +++ b/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala @@ -50,12 +50,6 @@ object TokenKind { implicit val eq: Eq[TokenKind] = Eq.fromUniversalEquals } -@SuppressWarnings( - Array( - "scalafix:DisableSyntax.var", - "scalafix:DisableSyntax.while", - ) -) object Scanner { /** Entrypoint to scanning text into tokens. diff --git a/project/plugins.sbt b/project/plugins.sbt index 9ae17a21..b4014537 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -8,6 +8,5 @@ addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % "0.18.25" addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.1") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1") addDependencyTreePlugin From e22912cbb84d29ad79f560067b246b2604fe383b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:02:22 +0100 Subject: [PATCH 07/15] unused --- .../src/main/scala/playground/smithyql/parser/v2/scanner.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala b/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala index ec24e6c2..0f5f9683 100644 --- a/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala +++ b/modules/parser/src/main/scala/playground/smithyql/parser/v2/scanner.scala @@ -239,7 +239,7 @@ object Scanner { readAny .lift(()) .isDefined || - eatErrors() + eatErrors(): @nowarn("msg=unused value of type Boolean") // last-effort sanity check if (remaining == last) From 4534744cfc79a7ccf4d82e9563dd70ee31f1ef2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:06:49 +0100 Subject: [PATCH 08/15] Use LTS in plugin module --- build.sbt | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/build.sbt b/build.sbt index b778c6c6..59df191b 100644 --- a/build.sbt +++ b/build.sbt @@ -14,6 +14,12 @@ inThisBuild( ) ) +val ScalaLTS = "3.3.4" +val ScalaNext = "3.5.2" + +ThisBuild / scalaVersion := ScalaNext +ThisBuild / versionScheme := Some("early-semver") + import scala.sys.process.* def crossPlugin( @@ -30,14 +36,6 @@ val compilerPlugins = crossPlugin("org.typelevel" % "kind-projector" % "0.13.3") )) -ThisBuild / versionScheme := Some("early-semver") - -Global / onChangedBuildSource := ReloadOnSourceChanges - -// todo: change to 3.3.x in plugin module -ThisBuild / scalaVersion := "3.5.2" -ThisBuild / crossScalaVersions := Seq("3.5.2") - // For coursier's "latest.integration" ThisBuild / dynverSeparator := "-" @@ -65,10 +63,15 @@ val commonSettings = Seq( Test / scalacOptions -= "-Wunused:privates", // scalacOptions += "-no-indent", - scalacOptions ++= Seq( - "-source:3.7", - "-experimental", - ), + scalacOptions ++= { + if (scalaVersion.value.startsWith("3.5")) + Seq( + // for cats-tagless macros + "-experimental" + ) + else + Nil + }, Test / scalacOptions += "-Wconf:cat=deprecation:silent,msg=Specify both message and version:silent", scalacOptions ++= Seq("-release", "11"), mimaFailOnNoPrevious := false, @@ -88,6 +91,7 @@ lazy val pluginCore = module("plugin-core").settings( ), // mimaPreviousArtifacts := Set(organization.value %% name.value % "0.7.0"), mimaPreviousArtifacts := Set.empty, + scalaVersion := ScalaLTS, ) lazy val pluginSample = module("plugin-sample") From 3690a162c51e1f9d9ed47a695e549fee9f8b4330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:07:14 +0100 Subject: [PATCH 09/15] lint --- .../scala/playground/smithyql/parser/v2/ScannerTests.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerTests.scala index ad0d4c3b..5766ef72 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/v2/ScannerTests.scala @@ -10,6 +10,8 @@ import playground.smithyql.parser.v2.scanner.TokenKind.* import weaver.* import weaver.scalacheck.Checkers +import scala.annotation.nowarn + import Diffs.given import Scanner.scan @@ -17,7 +19,7 @@ object ScannerTests extends SimpleIOSuite with Checkers with ScannerSuite { arbTests("Any string input scans successfully") { implicit arbString => forall { (s: String) => - scan(s): Unit + scan(s): @nowarn("msg=discarded non-Unit value") success } } From c5ec503ea2ee7e5d04e43c69d27c1fbb30b875fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:13:18 +0100 Subject: [PATCH 10/15] simplify --- .../smithyutil/AddDynamicRefinements.scala | 45 +++++-------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala b/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala index 57c18df3..6b59b234 100644 --- a/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala +++ b/modules/core/src/main/scala/playground/smithyutil/AddDynamicRefinements.scala @@ -2,6 +2,7 @@ package playground.smithyutil import cats.syntax.all.* import smithy.api +import smithy.api.Length import smithy4s.Refinement import smithy4s.RefinementProvider import smithy4s.Surjection @@ -47,7 +48,7 @@ object AddDynamicRefinements extends (Schema ~> Schema) { private def enumSchema[A]( schema: Schema.EnumerationSchema[A] ): Schema[A] = schema - .reifyHint( + .reifyHint[Length]( using RefinementProvider.lengthConstraint(schema.total(_).stringValue.size) ) .reifyHint( @@ -67,39 +68,15 @@ object AddDynamicRefinements extends (Schema ~> Schema) { schema .reifyHint[api.Length] .reifyHint[api.Pattern] - case PByte => - schema.reifyHint[api.Range]( - using RefinementProvider.numericRangeConstraints[Byte] - ) - case PShort => - schema.reifyHint[api.Range]( - using RefinementProvider.numericRangeConstraints[Short] - ) - case PInt => - schema.reifyHint[api.Range]( - using RefinementProvider.numericRangeConstraints[Int] - ) - case PLong => - schema.reifyHint[api.Range]( - using RefinementProvider.numericRangeConstraints[Long] - ) - case PFloat => - schema.reifyHint[api.Range]( - using RefinementProvider.numericRangeConstraints[Float] - ) - case PDouble => - schema.reifyHint[api.Range]( - using RefinementProvider.numericRangeConstraints[Double] - ) - case PBigInt => - schema.reifyHint[api.Range]( - using RefinementProvider.numericRangeConstraints[BigInt] - ) - case PBigDecimal => - schema.reifyHint[api.Range]( - using RefinementProvider.numericRangeConstraints[BigDecimal] - ) - case PBlob => schema.reifyHint[api.Length] + case PByte => (schema: Schema[Byte]).reifyHint[api.Range] + case PShort => (schema: Schema[Short]).reifyHint[api.Range] + case PInt => (schema: Schema[Int]).reifyHint[api.Range] + case PLong => (schema: Schema[Long]).reifyHint[api.Range] + case PFloat => (schema: Schema[Float]).reifyHint[api.Range] + case PDouble => (schema: Schema[Double]).reifyHint[api.Range] + case PBigInt => (schema: Schema[BigInt]).reifyHint[api.Range] + case PBigDecimal => (schema: Schema[BigDecimal]).reifyHint[api.Range] + case PBlob => schema.reifyHint[api.Length] case PTimestamp | PDocument | PBoolean | PUUID => schema } From 026937cf81010f61b03eb9784a869905c20a3521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:15:33 +0100 Subject: [PATCH 11/15] recover uuid, fix imports --- .../main/scala/playground/std/StdlibRuntime.scala | 6 +----- modules/core/src/main/smithy/std.smithy | 12 ++++++++---- .../test/scala/playground/PreludeCompilerTests.scala | 2 +- .../scala/playground/smithyql/AtPositionTests.scala | 2 +- .../playground/language/CodeLensProviderTests.scala | 4 ++-- .../language/CompletionProviderTests.scala | 4 ++-- .../scala/playground/language/CompletionTests.scala | 2 +- .../language/DocumentSymbolProviderTests.scala | 2 +- .../smithyql/parser/generative/ListParserTests.scala | 2 +- .../parser/generative/PreludeParserTests.scala | 2 +- .../parser/generative/QueryParserTests.scala | 2 +- .../parser/generative/SourceFileParserTests.scala | 2 +- .../parser/generative/StructParserTests.scala | 2 +- .../parser/generative/UseServiceParserTests.scala | 2 +- 14 files changed, 23 insertions(+), 23 deletions(-) diff --git a/modules/core/src/main/scala/playground/std/StdlibRuntime.scala b/modules/core/src/main/scala/playground/std/StdlibRuntime.scala index 5b6c5499..d22e4b43 100644 --- a/modules/core/src/main/scala/playground/std/StdlibRuntime.scala +++ b/modules/core/src/main/scala/playground/std/StdlibRuntime.scala @@ -23,11 +23,7 @@ object StdlibRuntime { new playground.std.Random[F] { def nextUUID( - ): F[NextUUIDOutput] = UUIDGen[F] - .randomUUID - .map(_.toString) - .map(playground.std.UUID(_)) - .map(NextUUIDOutput(_)) + ): F[NextUUIDOutput] = UUIDGen[F].randomUUID.map(NextUUIDOutput(_)) } diff --git a/modules/core/src/main/smithy/std.smithy b/modules/core/src/main/smithy/std.smithy index fdcc425c..6baf4161 100644 --- a/modules/core/src/main/smithy/std.smithy +++ b/modules/core/src/main/smithy/std.smithy @@ -2,16 +2,18 @@ $version: "2" namespace playground.std +use alloy#UUID + @trait(selector: "service") @protocolDefinition structure stdlib {} -string UUID - @stdlib @documentation("A standard library service providing random generators of data.") service Random { - operations: [NextUUID] + operations: [ + NextUUID + ] } @documentation("Generates a new UUID.") @@ -25,7 +27,9 @@ operation NextUUID { @stdlib @documentation("A standard library service providing time operations.") service Clock { - operations: [CurrentTimestamp] + operations: [ + CurrentTimestamp + ] } @documentation("Provides the current time as a Timestamp.") diff --git a/modules/core/src/test/scala/playground/PreludeCompilerTests.scala b/modules/core/src/test/scala/playground/PreludeCompilerTests.scala index c5583e70..1acfc46d 100644 --- a/modules/core/src/test/scala/playground/PreludeCompilerTests.scala +++ b/modules/core/src/test/scala/playground/PreludeCompilerTests.scala @@ -13,7 +13,7 @@ import playground.smithyql.StringRangeUtils.* import playground.smithyql.parser.SourceParser import weaver.* -import Assertions._ +import Assertions.* import Diffs.given object PreludeCompilerTests extends FunSuite { diff --git a/modules/core/src/test/scala/playground/smithyql/AtPositionTests.scala b/modules/core/src/test/scala/playground/smithyql/AtPositionTests.scala index 0b553e8d..1c335c7d 100644 --- a/modules/core/src/test/scala/playground/smithyql/AtPositionTests.scala +++ b/modules/core/src/test/scala/playground/smithyql/AtPositionTests.scala @@ -1,6 +1,6 @@ package playground.smithyql -import playground.Assertions._ +import playground.Assertions.* import playground.Diffs.given import playground.smithyql.parser.SourceParser import weaver.* diff --git a/modules/language-support/src/test/scala/playground/language/CodeLensProviderTests.scala b/modules/language-support/src/test/scala/playground/language/CodeLensProviderTests.scala index dab002dd..7407fdd4 100644 --- a/modules/language-support/src/test/scala/playground/language/CodeLensProviderTests.scala +++ b/modules/language-support/src/test/scala/playground/language/CodeLensProviderTests.scala @@ -11,9 +11,9 @@ import playground.OperationCompiler import playground.OperationRunner import playground.PreludeCompiler import playground.ServiceIndex -import playground.ServiceUtils._ +import playground.ServiceUtils.* import playground.language.Diffs.given -import playground.smithyql.StringRangeUtils._ +import playground.smithyql.StringRangeUtils.* import playground.std.RandomGen import weaver.* diff --git a/modules/language-support/src/test/scala/playground/language/CompletionProviderTests.scala b/modules/language-support/src/test/scala/playground/language/CompletionProviderTests.scala index 2486a6a9..e5e7c594 100644 --- a/modules/language-support/src/test/scala/playground/language/CompletionProviderTests.scala +++ b/modules/language-support/src/test/scala/playground/language/CompletionProviderTests.scala @@ -2,8 +2,8 @@ package playground.language import demo.smithy.DemoServiceGen import demo.smithy.DeprecatedServiceGen -import playground.Assertions._ -import playground.ServiceUtils._ +import playground.Assertions.* +import playground.ServiceUtils.* import playground.language.Diffs.given import playground.smithyql.Position import playground.smithyql.QualifiedIdentifier diff --git a/modules/language-support/src/test/scala/playground/language/CompletionTests.scala b/modules/language-support/src/test/scala/playground/language/CompletionTests.scala index c91103dc..65ac32c0 100644 --- a/modules/language-support/src/test/scala/playground/language/CompletionTests.scala +++ b/modules/language-support/src/test/scala/playground/language/CompletionTests.scala @@ -15,7 +15,7 @@ import demo.smithy.PowerMap import demo.smithy.PrivacyTier import demo.smithy.SampleSparseList import demo.smithy.SampleSparseMap -import playground.Assertions._ +import playground.Assertions.* import playground.language.Diffs.given import playground.smithyql.NodeContext import playground.smithyql.NodeContext.PathEntry.* diff --git a/modules/language-support/src/test/scala/playground/language/DocumentSymbolProviderTests.scala b/modules/language-support/src/test/scala/playground/language/DocumentSymbolProviderTests.scala index 44bbc688..53e938ba 100644 --- a/modules/language-support/src/test/scala/playground/language/DocumentSymbolProviderTests.scala +++ b/modules/language-support/src/test/scala/playground/language/DocumentSymbolProviderTests.scala @@ -1,6 +1,6 @@ package playground.language -import playground.Assertions._ +import playground.Assertions.* import playground.language.Diffs.given import playground.smithyql.Position import playground.smithyql.SourceRange diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/ListParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/ListParserTests.scala index ee541c6f..8458527b 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/ListParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/ListParserTests.scala @@ -1,7 +1,7 @@ package playground.smithyql.parser.generative +import playground.smithyql.* import playground.smithyql.Diffs.given -import playground.smithyql._ import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite import playground.smithyql.parser.SourceParser diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/PreludeParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/PreludeParserTests.scala index 455394ff..5f06ffe9 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/PreludeParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/PreludeParserTests.scala @@ -1,7 +1,7 @@ package playground.smithyql.parser.generative +import playground.smithyql.* import playground.smithyql.Diffs.given -import playground.smithyql._ import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/QueryParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/QueryParserTests.scala index f5fc330b..f285090c 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/QueryParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/QueryParserTests.scala @@ -1,7 +1,7 @@ package playground.smithyql.parser.generative +import playground.smithyql.* import playground.smithyql.Diffs.given -import playground.smithyql._ import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala index 9c18f913..eb6345ed 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala @@ -1,7 +1,7 @@ package playground.smithyql.parser.generative +import playground.smithyql.* import playground.smithyql.Diffs.given -import playground.smithyql._ import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/StructParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/StructParserTests.scala index 55a6e6d1..1eebed2f 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/StructParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/StructParserTests.scala @@ -1,7 +1,7 @@ package playground.smithyql.parser.generative +import playground.smithyql.* import playground.smithyql.Diffs.given -import playground.smithyql._ import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/UseServiceParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/UseServiceParserTests.scala index 6160468d..b463ab0e 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/UseServiceParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/UseServiceParserTests.scala @@ -1,7 +1,7 @@ package playground.smithyql.parser.generative +import playground.smithyql.* import playground.smithyql.Diffs.given -import playground.smithyql._ import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite From 2f13dfe99065e56645248668fb53c149019dd126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:22:35 +0100 Subject: [PATCH 12/15] oops --- .../test/scala/playground/smithyql/parser/Codecs.scala | 9 +++++++++ .../parser/generative/SourceFileParserTests.scala | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala b/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala index 3e9fb4fc..8c82c7a3 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/Codecs.scala @@ -54,4 +54,13 @@ object Codecs { given Codec[Query[WithSource]] = Codec.AsObject.derived given Codec[Prelude[WithSource]] = Codec.AsObject.derived + + given Codec[Statement[WithSource]] = Codec.AsObject.derived + + given lsw: Codec[List[Statement[WithSource]]] = Codec.from( + Decoder.decodeList, + Encoder.encodeList, + ) + + given Codec[SourceFile[WithSource]] = Codec.AsObject.derived } diff --git a/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala b/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala index eb6345ed..a812b1bb 100644 --- a/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala +++ b/modules/parser/src/test/scala/playground/smithyql/parser/generative/SourceFileParserTests.scala @@ -6,5 +6,5 @@ import playground.smithyql.parser.Codecs.given import playground.smithyql.parser.ParserSuite object SourceFileParserTests extends ParserSuite { - // loadParserTests[SourceFile]("source-file") + loadParserTests[SourceFile]("source-file") } From 4078698749b2ab5063b78b7ccbe54f22145f7bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:24:02 +0100 Subject: [PATCH 13/15] magic trick --- modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala | 2 +- vscode-extension/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala b/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala index cf456ab8..937c195a 100644 --- a/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala +++ b/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala @@ -127,7 +127,7 @@ object ModelLoader { DependencyParser .dependencies( dependencies, - defaultScalaVersion = BuildInfo.scalaBinaryVersion, + defaultScalaVersion = BuildInfo.scalaVersion, ) .either val repos = diff --git a/vscode-extension/package.json b/vscode-extension/package.json index e9698d94..7544af86 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -77,7 +77,7 @@ "smithyql.server.artifact": { "type": "string", "description": "The coordinates to the language server artifact", - "default": "com.kubukoz.playground:lsp_3" + "default": "com.kubukoz.playground::lsp" }, "smithyql.server.version": { "type": "string", From 228c67a106f1e9a42c8eb7896eff430bad234143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:28:53 +0100 Subject: [PATCH 14/15] just binary is fine --- modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala b/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala index 937c195a..cf456ab8 100644 --- a/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala +++ b/modules/lsp/src/main/scala/playground/lsp/ModelLoader.scala @@ -127,7 +127,7 @@ object ModelLoader { DependencyParser .dependencies( dependencies, - defaultScalaVersion = BuildInfo.scalaVersion, + defaultScalaVersion = BuildInfo.scalaBinaryVersion, ) .either val repos = From 50888726525034dca7cfadaf44bc0e00b23d6b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 29 Oct 2024 01:34:10 +0100 Subject: [PATCH 15/15] lol --- .../core/src/main/scala/playground/std/StdlibRuntime.scala | 6 +++++- modules/core/src/main/smithy/std.smithy | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/scala/playground/std/StdlibRuntime.scala b/modules/core/src/main/scala/playground/std/StdlibRuntime.scala index d22e4b43..e01f11a2 100644 --- a/modules/core/src/main/scala/playground/std/StdlibRuntime.scala +++ b/modules/core/src/main/scala/playground/std/StdlibRuntime.scala @@ -23,7 +23,11 @@ object StdlibRuntime { new playground.std.Random[F] { def nextUUID( - ): F[NextUUIDOutput] = UUIDGen[F].randomUUID.map(NextUUIDOutput(_)) + ): F[NextUUIDOutput] = UUIDGen[F] + .randomUUID + .map(_.toString()) + .map(UUID(_)) + .map(NextUUIDOutput(_)) } diff --git a/modules/core/src/main/smithy/std.smithy b/modules/core/src/main/smithy/std.smithy index 6baf4161..59a721de 100644 --- a/modules/core/src/main/smithy/std.smithy +++ b/modules/core/src/main/smithy/std.smithy @@ -2,12 +2,12 @@ $version: "2" namespace playground.std -use alloy#UUID - @trait(selector: "service") @protocolDefinition structure stdlib {} +string UUID + @stdlib @documentation("A standard library service providing random generators of data.") service Random {