From 5f5fc494b66f649b440fd332edf8adcd39beb8e8 Mon Sep 17 00:00:00 2001 From: Dima Date: Fri, 9 Jun 2023 13:59:41 +0300 Subject: [PATCH] fix(aqua-api): Add default constants to Aqua API [LNG-194] (#738) --- .../main/scala/aqua/api/APICompilation.scala | 2 +- .../aqua/compiler/AquaCompilerConf.scala | 2 +- .../aqua/compiler/AquaCompilerSpec.scala | 28 +++---------------- .../.js/src/main/scala/aqua/lsp/AquaLSP.scala | 3 +- .../.jvm/src/main/scala/aqua/lsp/Test.scala | 3 +- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/api/aqua-api/src/main/scala/aqua/api/APICompilation.scala b/api/aqua-api/src/main/scala/aqua/api/APICompilation.scala index b7e183b2c..da3aedc83 100644 --- a/api/aqua-api/src/main/scala/aqua/api/APICompilation.scala +++ b/api/aqua-api/src/main/scala/aqua/api/APICompilation.scala @@ -139,8 +139,8 @@ object APICompilation { LogFormatter.initLogger(Some(level)) - val config = AquaCompilerConf(constants) val transformConfig = aquaConfig.getTransformConfig + val config = AquaCompilerConf(constants ++ transformConfig.constantsList) CompilerAPI .compile[IO, AquaFileError, FileModuleId, FileSpan.F]( diff --git a/compiler/src/main/scala/aqua/compiler/AquaCompilerConf.scala b/compiler/src/main/scala/aqua/compiler/AquaCompilerConf.scala index 9c133dcef..22e4992ad 100644 --- a/compiler/src/main/scala/aqua/compiler/AquaCompilerConf.scala +++ b/compiler/src/main/scala/aqua/compiler/AquaCompilerConf.scala @@ -7,4 +7,4 @@ import aqua.raw.ConstantRaw * * @param constantsList List of known constants */ -case class AquaCompilerConf(constantsList: List[ConstantRaw] = ConstantRaw.defaultConstants(None)) \ No newline at end of file +case class AquaCompilerConf(constantsList: List[ConstantRaw]) \ No newline at end of file diff --git a/compiler/src/test/scala/aqua/compiler/AquaCompilerSpec.scala b/compiler/src/test/scala/aqua/compiler/AquaCompilerSpec.scala index e776af450..5ee595616 100644 --- a/compiler/src/test/scala/aqua/compiler/AquaCompilerSpec.scala +++ b/compiler/src/test/scala/aqua/compiler/AquaCompilerSpec.scala @@ -1,14 +1,6 @@ package aqua.compiler -import aqua.model.{ - CallModel, - ForModel, - FunctorModel, - IntoIndexModel, - LiteralModel, - ValueModel, - VarModel -} +import aqua.model.{CallModel, ForModel, FunctorModel, IntoIndexModel, LiteralModel, ValueModel, VarModel} import aqua.model.transform.TransformConfig import aqua.model.transform.Transform import aqua.parser.ParserError @@ -16,21 +8,9 @@ import aqua.parser.Ast import aqua.parser.Parser import aqua.parser.lift.Span import aqua.parser.lift.Span.S +import aqua.raw.ConstantRaw import aqua.raw.value.{LiteralRaw, ValueRaw, VarRaw} -import aqua.res.{ - ApRes, - CallRes, - CallServiceRes, - CanonRes, - FoldRes, - MakeRes, - MatchMismatchRes, - NextRes, - ParRes, - RestrictionRes, - SeqRes, - XorRes -} +import aqua.res.{ApRes, CallRes, CallServiceRes, CanonRes, FoldRes, MakeRes, MatchMismatchRes, NextRes, ParRes, RestrictionRes, SeqRes, XorRes} import aqua.types.{ArrayType, CanonStreamType, LiteralType, ScalarType, StreamType, Type} import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers @@ -64,7 +44,7 @@ class AquaCompilerSpec extends AnyFlatSpec with Matchers { .compileToContext[Id, String, String, Span.S]( aquaSource(src, imports), id => txt => Parser.parse(Parser.parserSchema)(txt), - AquaCompilerConf() + AquaCompilerConf(ConstantRaw.defaultConstants(None)) ) "aqua compiler" should "compile a simple snipped to the right context" in { diff --git a/language-server/language-server-api/.js/src/main/scala/aqua/lsp/AquaLSP.scala b/language-server/language-server-api/.js/src/main/scala/aqua/lsp/AquaLSP.scala index 16e3f2c21..46d907d39 100644 --- a/language-server/language-server-api/.js/src/main/scala/aqua/lsp/AquaLSP.scala +++ b/language-server/language-server-api/.js/src/main/scala/aqua/lsp/AquaLSP.scala @@ -7,6 +7,7 @@ import aqua.parser.lexer.{LiteralToken, Token} import aqua.parser.lift.FileSpan.F import aqua.parser.lift.{FileSpan, Span} import aqua.parser.{ArrowReturnError, BlockIndentError, LexerError, ParserError} +import aqua.raw.ConstantRaw import aqua.semantics.{HeaderError, RulesViolated, WrongAST} import aqua.{AquaIO, SpanParser} import cats.data.Validated.{Invalid, Valid, invalidNec, validNec} @@ -137,7 +138,7 @@ object AquaLSP extends App with Logging { val path = Path(pathStr) val pathId = FileModuleId(path) val sources = new AquaFileSources[IO](path, imports.toList.map(Path.apply)) - val config = AquaCompilerConf() + val config = AquaCompilerConf(ConstantRaw.defaultConstants(None)) val proc = for { diff --git a/language-server/language-server-api/.jvm/src/main/scala/aqua/lsp/Test.scala b/language-server/language-server-api/.jvm/src/main/scala/aqua/lsp/Test.scala index b58dd32b6..ce9806aa2 100644 --- a/language-server/language-server-api/.jvm/src/main/scala/aqua/lsp/Test.scala +++ b/language-server/language-server-api/.jvm/src/main/scala/aqua/lsp/Test.scala @@ -5,6 +5,7 @@ import aqua.files.{AquaFileSources, AquaFilesIO, FileModuleId} import aqua.io.AquaFileError import aqua.lsp.LSPCompiler import aqua.parser.lift.FileSpan +import aqua.raw.ConstantRaw import aqua.{AquaIO, SpanParser} import cats.data.Validated import cats.effect.{IO, IOApp, Sync} @@ -18,7 +19,7 @@ object Test extends IOApp.Simple { override def run: IO[Unit] = { val sources = new AquaFileSources[IO](Path("./aqua-src/antithesis.aqua"), List(Path("./aqua"))) - val config = AquaCompilerConf() + val config = AquaCompilerConf(ConstantRaw.defaultConstants(None)) for { start <- IO(System.currentTimeMillis())