Skip to content

Commit

Permalink
Merge pull request #156 from viperproject/meilers_lsp_warnings
Browse files Browse the repository at this point in the history
Fixed handling of warnings
  • Loading branch information
ArquintL authored Jul 17, 2023
2 parents 7592927 + 29c9294 commit e6ef7b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ object ViperIDEProtocol extends akka.http.scaladsl.marshallers.sprayjson.SprayJs
override def write(obj: WarningsDuringTypechecking): JsArray = JsArray(obj.warnings.map(_.asInstanceOf[AbstractError].toJson).toVector)
})

implicit val warningsDuringVerification_writer: RootJsonFormat[WarningsDuringVerification] = lift(new RootJsonWriter[WarningsDuringVerification] {
override def write(obj: WarningsDuringVerification): JsArray = JsArray(obj.warnings.map(_.asInstanceOf[AbstractError].toJson).toVector)
})

implicit val simpleMessage_writer: RootJsonFormat[SimpleMessage] = lift(new RootJsonWriter[SimpleMessage] {
override def write(obj: SimpleMessage): JsObject = JsObject("text" -> JsString(obj.text))
})
Expand Down
24 changes: 21 additions & 3 deletions src/main/scala/viper/server/frontends/lsp/FileManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ class FileManager(coordinator: ClientCoordinator, file_uri: String)(implicit exe
case InvalidArgumentsReport(_, errors) =>
markErrorsAsReported(errors)
processErrors(backendClassName, errors, Some(s"Invalid arguments have been passed to the backend $backendClassName:"))
case WarningsDuringParsing(warnings) =>
markErrorsAsReported(warnings)
processErrors(backendClassName, warnings)
case WarningsDuringTypechecking(warnings) =>
markErrorsAsReported(warnings)
processErrors(backendClassName, warnings)
case WarningsDuringVerification(warnings) =>
markErrorsAsReported(warnings)
processErrors(backendClassName, warnings)
case EntitySuccessMessage(_, concerning, _, _) =>
if (progress == null) {
coordinator.logger.debug("The backend must send a VerificationStart message before the ...Verified message.")
Expand Down Expand Up @@ -243,7 +252,7 @@ class FileManager(coordinator: ClientCoordinator, file_uri: String)(implicit exe
val newErrors = failure.errors.filterNot(hasAlreadyBeenReported)
markErrorsAsReported(newErrors)
processErrors(backendClassName, newErrors)
// the completion handler is not yet invoked (but as part of Status.Success)
// the completion handler is not yet invoked (but as part of Status.Success)
case m: Message => coordinator.client.notifyUnhandledViperServerMessage(UnhandledViperServerMessageTypeParams(m.name, m.toString, LogLevel.Info.id))
case Status.Success =>
// Success is sent when the stream is completed
Expand All @@ -258,13 +267,23 @@ class FileManager(coordinator: ClientCoordinator, file_uri: String)(implicit exe
private def processErrors(backendClassName: String, errors: Seq[AbstractError], errorMsgPrefix: Option[String] = None): Unit = {
val diags = errors.map(err => {
var errorType: String = ""
var severity = DiagnosticSeverity.Error
if (err.fullId != null && err.fullId == "typechecker.error") {
typeCheckingCompleted = false
errorType = "Typechecker error"
} else if (err.fullId != null && err.fullId == "parser.error") {
parsingCompleted = false
typeCheckingCompleted = false
errorType = "Parser error"
} else if (err.fullId != null && err.fullId == "typechecker.warning") {
severity = DiagnosticSeverity.Warning
errorType = "Typechecker warning"
} else if (err.fullId != null && err.fullId == "parser.warning") {
severity = DiagnosticSeverity.Warning
errorType = "Parser warning"
} else if (err.fullId != null && err.fullId == "verifier.warning") {
severity = DiagnosticSeverity.Warning
errorType = "Verification warning"
} else {
errorType = "Verification error"
}
Expand All @@ -287,9 +306,8 @@ class FileManager(coordinator: ClientCoordinator, file_uri: String)(implicit exe
s"${if(err.fullId != null) "[" + err.fullId + "] " else ""}" +
s"${range.getStart.getLine + 1}:${range.getStart.getCharacter + 1} $errMsgPrefixWithWhitespace${err.readableMessage}s")


val cachFlag: String = if(err.cached) "(cached)" else ""
new Diagnostic(range, errMsgPrefixWithWhitespace + err.readableMessage + cachFlag, DiagnosticSeverity.Error, "")
new Diagnostic(range, errMsgPrefixWithWhitespace + err.readableMessage + cachFlag, severity, "")
})

diagnostics.appendAll(diags)
Expand Down

0 comments on commit e6ef7b8

Please sign in to comment.