-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
203 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package langoustine.tracer | ||
|
||
import com.github.plokhotnyuk.jsoniter_scala.core.* | ||
import com.github.plokhotnyuk.jsoniter_scala.macros.* | ||
import scala.util.Try | ||
import jsonrpclib.{Payload, ErrorPayload} | ||
import jsonrpclib.CallId | ||
import jsonrpclib.InputMessage.* | ||
import jsonrpclib.OutputMessage.* | ||
import jsonrpclib.Message | ||
|
||
enum Direction: | ||
case ToServer, ToClient | ||
|
||
def reverse: Direction = this match | ||
case ToServer => ToClient | ||
case ToClient => ToServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package langoustine.tracer | ||
|
||
import com.github.plokhotnyuk.jsoniter_scala.core.* | ||
import com.github.plokhotnyuk.jsoniter_scala.macros.* | ||
import scala.util.Try | ||
import jsonrpclib.{Payload, ErrorPayload} | ||
import jsonrpclib.CallId | ||
import jsonrpclib.InputMessage.* | ||
import jsonrpclib.OutputMessage.* | ||
import jsonrpclib.Message | ||
|
||
enum LogMessage(val value: String): | ||
case Window(override val value: String, timestamp: Long) | ||
extends LogMessage(value) | ||
case Stderr(override val value: String, timestamp: Long) | ||
extends LogMessage(value) | ||
|
||
object LogMessage: | ||
given JsonValueCodec[LogMessage] = JsonCodecMaker.make | ||
given JsonValueCodec[Vector[LogMessage]] = JsonCodecMaker.make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package langoustine.tracer | ||
|
||
import com.github.plokhotnyuk.jsoniter_scala.core.* | ||
import com.github.plokhotnyuk.jsoniter_scala.macros.* | ||
import scala.util.Try | ||
import jsonrpclib.{Payload, ErrorPayload} | ||
import jsonrpclib.CallId | ||
import jsonrpclib.InputMessage.* | ||
import jsonrpclib.OutputMessage.* | ||
import jsonrpclib.Message | ||
|
||
enum LspMessage(val id: CallId): | ||
case Request( | ||
method: String, | ||
override val id: CallId, | ||
responded: Boolean, | ||
direction: Direction | ||
) extends LspMessage(id) | ||
|
||
case Response( | ||
override val id: CallId, | ||
method: Option[String], | ||
direction: Direction | ||
) extends LspMessage(id) | ||
|
||
case Notification( | ||
generatedId: CallId, | ||
method: String, | ||
direction: Direction | ||
) extends LspMessage(generatedId) | ||
|
||
def methodName: Option[String] = this match | ||
case r: Request => Some(r.method) | ||
case r: Notification => Some(r.method) | ||
case r: Response => r.method | ||
end LspMessage | ||
|
||
object LspMessage: | ||
given JsonValueCodec[LspMessage] = JsonCodecMaker.make | ||
|
||
def from( | ||
raw: RawMessage, | ||
direction: Direction, | ||
generatedId: CallId | ||
): Option[LspMessage] = | ||
raw.id match | ||
// notification | ||
case None => | ||
raw.method.map( | ||
LspMessage.Notification(generatedId, _, direction) | ||
) | ||
case Some(id) => // it's a request/response | ||
raw.method match | ||
case None => | ||
Some(LspMessage.Response(id, None, direction)) | ||
case Some(value) => | ||
Some(LspMessage.Request(value, id, responded = false, direction)) | ||
end LspMessage |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package langoustine.tracer | ||
|
||
import com.github.plokhotnyuk.jsoniter_scala.core.* | ||
import com.github.plokhotnyuk.jsoniter_scala.macros.* | ||
import scala.util.Try | ||
import jsonrpclib.{Payload, ErrorPayload} | ||
import jsonrpclib.CallId | ||
import jsonrpclib.InputMessage.* | ||
import jsonrpclib.OutputMessage.* | ||
import jsonrpclib.Message | ||
|
||
case class RawMessage( | ||
jsonrpc: String, | ||
method: Option[String] = None, | ||
result: Option[Payload] = None, | ||
error: Option[ErrorPayload] = None, | ||
params: Option[Payload] = None, | ||
id: Option[CallId] = None | ||
): | ||
def toMessage: Option[Message] = | ||
id match | ||
// notification | ||
case None => | ||
method.map( | ||
NotificationMessage(_, params) | ||
) | ||
case Some(id) => // it's a request/response | ||
method match | ||
case None => | ||
error | ||
.map(ErrorMessage(id, _)) | ||
.orElse( | ||
result.map( | ||
ResponseMessage(id, _) | ||
) | ||
) | ||
case Some(value) => | ||
Some(RequestMessage(value, id, params)) | ||
end RawMessage | ||
|
||
object RawMessage: | ||
import com.github.plokhotnyuk.jsoniter_scala.macros.* | ||
|
||
given JsonValueCodec[RawMessage] = JsonCodecMaker.make | ||
|
||
def create( | ||
method: Option[String] = None, | ||
result: Option[Payload] = None, | ||
error: Option[ErrorPayload] = None, | ||
params: Option[Payload] = None, | ||
id: Option[CallId] = None | ||
) = | ||
RawMessage("2.0", method, result, error, params, id) | ||
end RawMessage |
19 changes: 19 additions & 0 deletions
19
modules/tracer/shared/src/main/scala/ReceivedMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package langoustine.tracer | ||
|
||
import com.github.plokhotnyuk.jsoniter_scala.core.* | ||
import com.github.plokhotnyuk.jsoniter_scala.macros.* | ||
import scala.util.Try | ||
import jsonrpclib.{Payload, ErrorPayload} | ||
import jsonrpclib.CallId | ||
import jsonrpclib.InputMessage.* | ||
import jsonrpclib.OutputMessage.* | ||
import jsonrpclib.Message | ||
|
||
case class ReceivedMessage( | ||
timestamp: Long, | ||
raw: RawMessage, | ||
decoded: LspMessage | ||
) | ||
|
||
object ReceivedMessage: | ||
given JsonValueCodec[ReceivedMessage] = JsonCodecMaker.make |
Oops, something went wrong.