From f8b5017918a1ec076ccc1593cca70e9e71276b36 Mon Sep 17 00:00:00 2001 From: Dima Date: Thu, 14 Sep 2023 19:19:16 +0400 Subject: [PATCH] feat(language-server): Pass errors to lsp context [fixes LNG-243] (#888) --- .../.js/src/main/scala/aqua/lsp/AquaLSP.scala | 10 +++++-- .../src/main/scala/aqua/lsp/LspContext.scala | 13 +++++---- .../main/scala/aqua/lsp/LspSemantics.scala | 28 +++++++++---------- 3 files changed, 28 insertions(+), 23 deletions(-) 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 46d907d3..4032f479 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 @@ -203,9 +203,15 @@ object AquaLSP extends App with Logging { val result = fileRes match { case Valid(lsp) => - logger.debug("No errors on compilation.") + val errors = lsp.errors.map(CompileError.apply).flatMap(errorToInfo) + errors match + case Nil => + logger.debug("No errors on compilation.") + case errs => + logger.debug("Errors: " + errs.mkString("\n")) + CompilationResult( - List.empty.toJSArray, + errors.toJSArray, locationsToJs(lsp.locations), importsToTokenImport(lsp.importTokens) ) diff --git a/language-server/language-server-api/src/main/scala/aqua/lsp/LspContext.scala b/language-server/language-server-api/src/main/scala/aqua/lsp/LspContext.scala index f052795d..f3afd58e 100644 --- a/language-server/language-server-api/src/main/scala/aqua/lsp/LspContext.scala +++ b/language-server/language-server-api/src/main/scala/aqua/lsp/LspContext.scala @@ -1,13 +1,13 @@ package aqua.lsp -import aqua.parser.lexer.{Ability, LiteralToken, Name, NamedTypeToken, Token} +import aqua.parser.lexer.{LiteralToken, NamedTypeToken, Token} +import aqua.raw.RawContext.semiRC import aqua.raw.{RawContext, RawPart} -import aqua.types.{ArrowType, Type} -import RawContext.semiRC +import aqua.semantics.SemanticError import aqua.semantics.header.Picker - -import cats.{Monoid, Semigroup} +import aqua.types.{ArrowType, Type} import cats.syntax.monoid.* +import cats.{Monoid, Semigroup} // Context with info that necessary for language server case class LspContext[S[_]]( @@ -17,7 +17,8 @@ case class LspContext[S[_]]( constants: Map[String, Type] = Map.empty[String, Type], tokens: Map[String, Token[S]] = Map.empty[String, Token[S]], locations: List[(Token[S], Token[S])] = Nil, - importTokens: List[LiteralToken[S]] = Nil + importTokens: List[LiteralToken[S]] = Nil, + errors: List[SemanticError[S]] = Nil ) object LspContext { diff --git a/language-server/language-server-api/src/main/scala/aqua/lsp/LspSemantics.scala b/language-server/language-server-api/src/main/scala/aqua/lsp/LspSemantics.scala index cc5234b9..49b89994 100644 --- a/language-server/language-server-api/src/main/scala/aqua/lsp/LspSemantics.scala +++ b/language-server/language-server-api/src/main/scala/aqua/lsp/LspSemantics.scala @@ -67,21 +67,19 @@ class LspSemantics[S[_]] extends Semantics[S, LspContext[S]] { RawSemantics .interpret(ast, initState, init.raw) .map { case (state, ctx) => - NonEmptyChain - .fromChain(state.errors) - .fold[ValidatedNec[SemanticError[S], LspContext[S]]] { - Valid( - LspContext( - raw = ctx, - rootArrows = state.names.rootArrows, - constants = state.names.constants, - abDefinitions = state.abilities.definitions, - locations = state.locations.allLocations, - importTokens = importTokens, - tokens = state.locations.tokens - ) - ) - }(Invalid(_)) + // TODO: better to change return type in `process` method + Valid( + LspContext( + raw = ctx, + rootArrows = state.names.rootArrows, + constants = state.names.constants, + abDefinitions = state.abilities.definitions, + locations = state.locations.allLocations, + importTokens = importTokens, + tokens = state.locations.tokens, + errors = state.errors.toList + ) + ) } // TODO: return as Eval .value