Extract jsonRpcRespondErrorImpl

This commit is contained in:
Dale Wijnand 2018-03-09 12:02:52 +00:00
parent 268b5111ab
commit d3ef452a5f
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
1 changed files with 12 additions and 11 deletions

View File

@ -10,6 +10,7 @@ package internal
package server
import sjsonnew.JsonFormat
import sjsonnew.shaded.scalajson.ast.unsafe.JValue
import sjsonnew.support.scalajson.unsafe.Converter
import sbt.protocol.Serialization
import sbt.protocol.{ SettingQuery => Q }
@ -143,16 +144,8 @@ private[sbt] trait LanguageServerProtocol extends CommandChannel { self =>
}
/** Respond back to Language Server's client. */
private[sbt] def jsonRpcRespondError(
execId: Option[String],
code: Long,
message: String,
): Unit = {
val e = JsonRpcResponseError(code, message, None)
val m = JsonRpcResponseMessage("2.0", execId, None, Option(e))
val bytes = Serialization.serializeResponseMessage(m)
publishBytes(bytes)
}
private[sbt] def jsonRpcRespondError(execId: Option[String], code: Long, message: String): Unit =
jsonRpcRespondErrorImpl(execId, code, message, None)
/** Respond back to Language Server's client. */
private[sbt] def jsonRpcRespondError[A: JsonFormat](
@ -160,8 +153,16 @@ private[sbt] trait LanguageServerProtocol extends CommandChannel { self =>
code: Long,
message: String,
data: A,
): Unit =
jsonRpcRespondErrorImpl(execId, code, message, Option(Converter.toJson[A](data).get))
private[this] def jsonRpcRespondErrorImpl(
execId: Option[String],
code: Long,
message: String,
data: Option[JValue],
): Unit = {
val e = JsonRpcResponseError(code, message, Option(Converter.toJson[A](data).get))
val e = JsonRpcResponseError(code, message, data)
val m = JsonRpcResponseMessage("2.0", execId, None, Option(e))
val bytes = Serialization.serializeResponseMessage(m)
publishBytes(bytes)