mirror of https://github.com/sbt/sbt.git
Drop old application/sbt-x1 protocol
This commit is contained in:
parent
975e3db43e
commit
cad84afc6d
|
|
@ -20,7 +20,6 @@ import sbt.internal.protocol.{
|
||||||
JsonRpcResponseMessage
|
JsonRpcResponseMessage
|
||||||
}
|
}
|
||||||
import sbt.internal.util.ObjectEvent
|
import sbt.internal.util.ObjectEvent
|
||||||
import sbt.internal.util.codec.JValueFormats
|
|
||||||
import sbt.internal.util.complete.Parser
|
import sbt.internal.util.complete.Parser
|
||||||
import sbt.protocol._
|
import sbt.protocol._
|
||||||
import sbt.util.Logger
|
import sbt.util.Logger
|
||||||
|
|
@ -52,10 +51,6 @@ final class NetworkChannel(
|
||||||
private val ContentLength = """^Content\-Length\:\s*(\d+)""".r
|
private val ContentLength = """^Content\-Length\:\s*(\d+)""".r
|
||||||
private val ContentType = """^Content\-Type\:\s*(.+)""".r
|
private val ContentType = """^Content\-Type\:\s*(.+)""".r
|
||||||
private var _contentType: String = ""
|
private var _contentType: String = ""
|
||||||
private val SbtX1Protocol = "application/sbt-x1"
|
|
||||||
private val VsCode = sbt.protocol.Serialization.VsCode
|
|
||||||
private val VsCodeOld = "application/vscode-jsonrpc; charset=utf8"
|
|
||||||
private lazy val jsonFormat = new sjsonnew.BasicJsonProtocol with JValueFormats {}
|
|
||||||
private val pendingRequests: mutable.Map[String, JsonRpcRequestMessage] = mutable.Map()
|
private val pendingRequests: mutable.Map[String, JsonRpcRequestMessage] = mutable.Map()
|
||||||
|
|
||||||
private lazy val callback: ServerCallback = new ServerCallback {
|
private lazy val callback: ServerCallback = new ServerCallback {
|
||||||
|
|
@ -135,7 +130,8 @@ final class NetworkChannel(
|
||||||
// handle un-framing
|
// handle un-framing
|
||||||
state match {
|
state match {
|
||||||
case SingleLine =>
|
case SingleLine =>
|
||||||
tillEndOfLine match {
|
val line = tillEndOfLine
|
||||||
|
line match {
|
||||||
case Some(chunk) =>
|
case Some(chunk) =>
|
||||||
chunk.headOption match {
|
chunk.headOption match {
|
||||||
case None => // ignore blank line
|
case None => // ignore blank line
|
||||||
|
|
@ -215,60 +211,43 @@ final class NetworkChannel(
|
||||||
}
|
}
|
||||||
|
|
||||||
def handleBody(chunk: Vector[Byte]): Unit = {
|
def handleBody(chunk: Vector[Byte]): Unit = {
|
||||||
if (isLanguageServerProtocol) {
|
Serialization.deserializeJsonMessage(chunk) match {
|
||||||
Serialization.deserializeJsonMessage(chunk) match {
|
case Right(req: JsonRpcRequestMessage) =>
|
||||||
case Right(req: JsonRpcRequestMessage) =>
|
try {
|
||||||
try {
|
registerRequest(req)
|
||||||
registerRequest(req)
|
onRequestMessage(req)
|
||||||
onRequestMessage(req)
|
} catch {
|
||||||
} catch {
|
case LangServerError(code, message) =>
|
||||||
case LangServerError(code, message) =>
|
log.debug(s"sending error: $code: $message")
|
||||||
log.debug(s"sending error: $code: $message")
|
respondError(code, message, Some(req.id))
|
||||||
respondError(code, message, Some(req.id))
|
}
|
||||||
}
|
case Right(ntf: JsonRpcNotificationMessage) =>
|
||||||
case Right(ntf: JsonRpcNotificationMessage) =>
|
try {
|
||||||
try {
|
onNotification(ntf)
|
||||||
onNotification(ntf)
|
} catch {
|
||||||
} catch {
|
case LangServerError(code, message) =>
|
||||||
case LangServerError(code, message) =>
|
logMessage("error", s"Error $code while handling notification: $message")
|
||||||
logMessage("error", s"Error $code while handling notification: $message")
|
}
|
||||||
}
|
case Right(msg) =>
|
||||||
case Right(msg) =>
|
log.debug(s"Unhandled message: $msg")
|
||||||
log.debug(s"Unhandled message: $msg")
|
case Left(errorDesc) =>
|
||||||
case Left(errorDesc) =>
|
logMessage(
|
||||||
logMessage(
|
"error",
|
||||||
"error",
|
s"Got invalid chunk from client (${new String(chunk.toArray, "UTF-8")}): $errorDesc"
|
||||||
s"Got invalid chunk from client (${new String(chunk.toArray, "UTF-8")}): $errorDesc"
|
)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contentType match {
|
|
||||||
case SbtX1Protocol =>
|
|
||||||
Serialization
|
|
||||||
.deserializeCommand(chunk)
|
|
||||||
.fold(
|
|
||||||
errorDesc =>
|
|
||||||
logMessage(
|
|
||||||
"error",
|
|
||||||
s"Got invalid chunk from client (${new String(chunk.toArray, "UTF-8")}): " + errorDesc
|
|
||||||
),
|
|
||||||
onCommand
|
|
||||||
)
|
|
||||||
case _ =>
|
|
||||||
logMessage(
|
|
||||||
"error",
|
|
||||||
s"Unknown Content-Type: $contentType"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} // if-else
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def handleHeader(str: String): Option[Unit] = {
|
def handleHeader(str: String): Option[Unit] = {
|
||||||
|
val sbtX1Protocol = "application/sbt-x1"
|
||||||
str match {
|
str match {
|
||||||
case ContentLength(len) =>
|
case ContentLength(len) =>
|
||||||
contentLength = len.toInt
|
contentLength = len.toInt
|
||||||
Some(())
|
Some(())
|
||||||
case ContentType(ct) =>
|
case ContentType(ct) =>
|
||||||
|
if (ct == sbtX1Protocol) {
|
||||||
|
logMessage("error", s"server protocol $ct is no longer supported")
|
||||||
|
}
|
||||||
setContentType(ct)
|
setContentType(ct)
|
||||||
Some(())
|
Some(())
|
||||||
case _ => None
|
case _ => None
|
||||||
|
|
@ -277,12 +256,7 @@ final class NetworkChannel(
|
||||||
}
|
}
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
private[sbt] def isLanguageServerProtocol: Boolean = {
|
private[sbt] def isLanguageServerProtocol: Boolean = true
|
||||||
contentType match {
|
|
||||||
case "" | VsCode | VsCodeOld => true
|
|
||||||
case _ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private def registerRequest(request: JsonRpcRequestMessage): Unit = {
|
private def registerRequest(request: JsonRpcRequestMessage): Unit = {
|
||||||
this.synchronized {
|
this.synchronized {
|
||||||
|
|
@ -328,42 +302,20 @@ final class NetworkChannel(
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] def notifyEvent[A: JsonFormat](method: String, params: A): Unit = {
|
private[sbt] def notifyEvent[A: JsonFormat](method: String, params: A): Unit = {
|
||||||
if (isLanguageServerProtocol) {
|
jsonRpcNotify(method, params)
|
||||||
jsonRpcNotify(method, params)
|
|
||||||
} else {
|
|
||||||
()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def respond[A: JsonFormat](event: A): Unit = respond(event, None)
|
def respond[A: JsonFormat](event: A): Unit = respond(event, None)
|
||||||
|
|
||||||
def respond[A: JsonFormat](event: A, execId: Option[String]): Unit = {
|
def respond[A: JsonFormat](event: A, execId: Option[String]): Unit = {
|
||||||
if (isLanguageServerProtocol) {
|
respondResult(event, execId)
|
||||||
respondResult(event, execId)
|
|
||||||
} else {
|
|
||||||
contentType match {
|
|
||||||
case SbtX1Protocol =>
|
|
||||||
val bytes = Serialization.serializeEvent(event)
|
|
||||||
publishBytes(bytes, true)
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def notifyEvent(event: EventMessage): Unit = {
|
def notifyEvent(event: EventMessage): Unit = {
|
||||||
if (isLanguageServerProtocol) {
|
event match {
|
||||||
event match {
|
case entry: LogEvent => logMessage(entry.level, entry.message)
|
||||||
case entry: LogEvent => logMessage(entry.level, entry.message)
|
case entry: ExecStatusEvent => logMessage("debug", entry.status)
|
||||||
case entry: ExecStatusEvent => logMessage("debug", entry.status)
|
case _ => ()
|
||||||
case _ => ()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contentType match {
|
|
||||||
case SbtX1Protocol =>
|
|
||||||
val bytes = Serialization.serializeEventMessage(event)
|
|
||||||
publishBytes(bytes, true)
|
|
||||||
case _ => ()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,22 +324,7 @@ final class NetworkChannel(
|
||||||
* erased because it went through logging.
|
* erased because it went through logging.
|
||||||
*/
|
*/
|
||||||
private[sbt] def respond(event: ObjectEvent[_]): Unit = {
|
private[sbt] def respond(event: ObjectEvent[_]): Unit = {
|
||||||
import sjsonnew.shaded.scalajson.ast.unsafe._
|
onObjectEvent(event)
|
||||||
if (isLanguageServerProtocol) onObjectEvent(event)
|
|
||||||
else {
|
|
||||||
import jsonFormat._
|
|
||||||
val json: JValue = JObject(
|
|
||||||
JField("type", JString(event.contentType)),
|
|
||||||
Seq(JField("message", event.json), JField("level", JString(event.level.toString))) ++
|
|
||||||
(event.channelName map { channelName =>
|
|
||||||
JField("channelName", JString(channelName))
|
|
||||||
}) ++
|
|
||||||
(event.execId map { execId =>
|
|
||||||
JField("execId", JString(execId))
|
|
||||||
}): _*
|
|
||||||
)
|
|
||||||
respond(json, event.execId)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def publishBytes(event: Array[Byte]): Unit = publishBytes(event, false)
|
def publishBytes(event: Array[Byte]): Unit = publishBytes(event, false)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue