mirror of https://github.com/sbt/sbt.git
Added deserialization for NotificationMessage and used it in handleBody
This commit is contained in:
parent
36e079d12b
commit
c689821383
|
|
@ -166,8 +166,8 @@ final class NetworkChannel(val name: String,
|
|||
|
||||
def handleBody(chunk: Vector[Byte]): Unit = {
|
||||
if (isLanguageServerProtocol) {
|
||||
Serialization.deserializeJsonRequest(chunk) match {
|
||||
case Right(req) =>
|
||||
Serialization.deserializeJsonMessage(chunk) match {
|
||||
case Right(Right(req)) =>
|
||||
try {
|
||||
onRequestMessage(req)
|
||||
} catch {
|
||||
|
|
@ -175,6 +175,14 @@ final class NetworkChannel(val name: String,
|
|||
log.debug(s"sending error: $code: $message")
|
||||
langError(Option(req.id), code, message)
|
||||
}
|
||||
case Right(Left(ntf)) =>
|
||||
try {
|
||||
onNotification(ntf)
|
||||
} catch {
|
||||
case LangServerError(code, message) =>
|
||||
log.debug(s"sending error: $code: $message")
|
||||
langError(None, code, message) // new id?
|
||||
}
|
||||
case Left(errorDesc) =>
|
||||
val msg = s"Got invalid chunk from client (${new String(chunk.toArray, "UTF-8")}): " + errorDesc
|
||||
langError(None, ErrorCodes.ParseError, msg)
|
||||
|
|
|
|||
|
|
@ -143,15 +143,21 @@ object Serialization {
|
|||
}
|
||||
}
|
||||
|
||||
private[sbt] def deserializeJsonRequest(
|
||||
bytes: Seq[Byte]): Either[String, JsonRpcRequestMessage] = {
|
||||
private[sbt] def deserializeJsonMessage(bytes: Seq[Byte])
|
||||
: Either[String, Either[JsonRpcNotificationMessage, JsonRpcRequestMessage]] = {
|
||||
val buffer = ByteBuffer.wrap(bytes.toArray)
|
||||
Parser.parseFromByteBuffer(buffer) match {
|
||||
case Success(json) =>
|
||||
import sbt.internal.protocol.codec.JsonRPCProtocol._
|
||||
Converter.fromJson[JsonRpcRequestMessage](json) match {
|
||||
case Success(msg) => Right(msg)
|
||||
case Failure(e) => throw e
|
||||
case Success(request) if (request.id.nonEmpty) => Right(Right(request))
|
||||
case Failure(e) => throw e
|
||||
case _ => {
|
||||
Converter.fromJson[JsonRpcNotificationMessage](json) match {
|
||||
case Success(notification) => Right(Left(notification))
|
||||
case Failure(e) => throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
case Failure(e) =>
|
||||
Left(s"Parse error: ${e.getMessage}")
|
||||
|
|
|
|||
Loading…
Reference in New Issue