Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Mar 22, 2024
1 parent 5958632 commit 6598963
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 201 deletions.
11 changes: 1 addition & 10 deletions modules/app/src/main/scala/LangoustineApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,7 @@ object LangoustineApp:
.concurrently(
in
.through(lsp.decodeMessages)
.evalMap {
case Left(err) => IO.pure(None) // TODO
// Logging
// .error(
// s"Failed to decode message from target LSP's stdout: $err"
// )
// .as(None)
case Right(payload) => IO.pure(Some(payload))
}
.unNone
.evalMap(IO.fromEither)
.through(channel.input)
)
.concurrently(
Expand Down
2 changes: 0 additions & 2 deletions modules/tests/src/test/scalajvm/tracer/Feed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ case class Feed(
case Some(value) =>
f(this).publish1(value)
end match

// f(this).publish1(Payload(ser.getBytes()))
end send

def send(f: this.type => Topic[IO, Chunk[Byte]], str: String) =
Expand Down
17 changes: 17 additions & 0 deletions modules/tracer/shared/src/main/scala/Direction.scala
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
20 changes: 20 additions & 0 deletions modules/tracer/shared/src/main/scala/LogMessage.scala
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
58 changes: 58 additions & 0 deletions modules/tracer/shared/src/main/scala/LspMessage.scala
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
189 changes: 0 additions & 189 deletions modules/tracer/shared/src/main/scala/Protocol.scala

This file was deleted.

54 changes: 54 additions & 0 deletions modules/tracer/shared/src/main/scala/RawMessage.scala
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 modules/tracer/shared/src/main/scala/ReceivedMessage.scala
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
Loading

0 comments on commit 6598963

Please sign in to comment.