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 {
case Valid(lsp) =>
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)
)

View File

@ -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 {

View File

@ -67,9 +67,7 @@ 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]]] {
// TODO: better to change return type in `process` method
Valid(
LspContext(
raw = ctx,
@ -78,10 +76,10 @@ class LspSemantics[S[_]] extends Semantics[S, LspContext[S]] {
abDefinitions = state.abilities.definitions,
locations = state.locations.allLocations,
importTokens = importTokens,
tokens = state.locations.tokens
tokens = state.locations.tokens,
errors = state.errors.toList
)
)
}(Invalid(_))
}
// TODO: return as Eval
.value