feat(language-server): Pass errors to lsp context [fixes LNG-243] (#888)

This commit is contained in:
Dima 2023-09-14 19:19:16 +04:00 committed by GitHub
parent d6f879ef7a
commit f8b5017918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 23 deletions

View File

@ -203,9 +203,15 @@ object AquaLSP extends App with Logging {
val result = fileRes match { val result = fileRes match {
case Valid(lsp) => 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( CompilationResult(
List.empty.toJSArray, errors.toJSArray,
locationsToJs(lsp.locations), locationsToJs(lsp.locations),
importsToTokenImport(lsp.importTokens) importsToTokenImport(lsp.importTokens)
) )

View File

@ -1,13 +1,13 @@
package aqua.lsp 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.raw.{RawContext, RawPart}
import aqua.types.{ArrowType, Type} import aqua.semantics.SemanticError
import RawContext.semiRC
import aqua.semantics.header.Picker import aqua.semantics.header.Picker
import aqua.types.{ArrowType, Type}
import cats.{Monoid, Semigroup}
import cats.syntax.monoid.* import cats.syntax.monoid.*
import cats.{Monoid, Semigroup}
// Context with info that necessary for language server // Context with info that necessary for language server
case class LspContext[S[_]]( case class LspContext[S[_]](
@ -17,7 +17,8 @@ case class LspContext[S[_]](
constants: Map[String, Type] = Map.empty[String, Type], constants: Map[String, Type] = Map.empty[String, Type],
tokens: Map[String, Token[S]] = Map.empty[String, Token[S]], tokens: Map[String, Token[S]] = Map.empty[String, Token[S]],
locations: List[(Token[S], Token[S])] = Nil, locations: List[(Token[S], Token[S])] = Nil,
importTokens: List[LiteralToken[S]] = Nil importTokens: List[LiteralToken[S]] = Nil,
errors: List[SemanticError[S]] = Nil
) )
object LspContext { object LspContext {

View File

@ -67,21 +67,19 @@ class LspSemantics[S[_]] extends Semantics[S, LspContext[S]] {
RawSemantics RawSemantics
.interpret(ast, initState, init.raw) .interpret(ast, initState, init.raw)
.map { case (state, ctx) => .map { case (state, ctx) =>
NonEmptyChain // TODO: better to change return type in `process` method
.fromChain(state.errors) Valid(
.fold[ValidatedNec[SemanticError[S], LspContext[S]]] { LspContext(
Valid( raw = ctx,
LspContext( rootArrows = state.names.rootArrows,
raw = ctx, constants = state.names.constants,
rootArrows = state.names.rootArrows, abDefinitions = state.abilities.definitions,
constants = state.names.constants, locations = state.locations.allLocations,
abDefinitions = state.abilities.definitions, importTokens = importTokens,
locations = state.locations.allLocations, tokens = state.locations.tokens,
importTokens = importTokens, errors = state.errors.toList
tokens = state.locations.tokens )
) )
)
}(Invalid(_))
} }
// TODO: return as Eval // TODO: return as Eval
.value .value