Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion remote-view/shared/src/main/scala/parsley/debug/RemoteView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ import parsley.debug.RefCodec.CodedRef
sealed trait RemoteView extends DebugView.Reusable with DebugView.Pauseable with DebugView.Manageable {
protected val port: Int
protected val address: String
protected var name: Option[String] = None

/** Set a name to identify this view in the remote service
*
* @param debugName The identifying name
* @return This instance of RemoteView
*/
def named(debugName: String): RemoteView = {
require(!debugName.isEmpty, "debugName should not be empty")
name = Some(debugName)
this
}

// Identifies a session for the receiver
private var sessionId: Int = -1
Expand Down Expand Up @@ -99,7 +111,7 @@ sealed trait RemoteView extends DebugView.Reusable with DebugView.Pauseable with

private [debug] def renderWithTimeout(input: =>String, tree: =>DebugTree, timeout: FiniteDuration, isDebuggable: Boolean = false, refs: Seq[CodedRef] = Nil): Option[RemoteViewResponse] = {
// JSON formatted payload for post request
val payload: String = DebugTreeSerialiser.toJSON(input, tree, sessionId, ParserInfoCollector.info.toList, isDebuggable, refs)
val payload: String = DebugTreeSerialiser.toJSON(input, tree, sessionId, ParserInfoCollector.info.toList, isDebuggable, refs, name)

// Send POST
println("Sending Debug Tree to Server...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ private object SerialisableDebugTree {
* @param root The root node of the debug tree.
* @param parserInfo A map from filename to a list of (start, end) locations of named parsers.
* @param isDebuggable Flag representing whether this instance is debuggable.
* @param sessionName Optional name of the session.
*/
private case class SerialisablePayload(input: String, root: SerialisableDebugTree, parserInfo: Map[String, List[(Int, Int)]], sessionId: Int, isDebuggable: Boolean, refs: Seq[CodedRef])
private case class SerialisablePayload(input: String, root: SerialisableDebugTree, parserInfo: Map[String, List[(Int, Int)]], sessionId: Int, isDebuggable: Boolean, refs: Seq[CodedRef], sessionName: Option[String])

private object SerialisablePayload {
implicit val rw: up.ReadWriter[SerialisablePayload] = up.macroRW
Expand Down Expand Up @@ -97,9 +98,9 @@ object DebugTreeSerialiser {
* @param file A valid writer object.
* @param tree The DebugTree.
*/
def writeJSON(file: Writer, input: String, tree: DebugTree, sessionId: Int, parserInfo: List[ParserInfo], isDebuggable: Boolean, refs: Seq[CodedRef]): Unit = {
def writeJSON(file: Writer, input: String, tree: DebugTree, sessionId: Int, parserInfo: List[ParserInfo], isDebuggable: Boolean, refs: Seq[CodedRef], sessionName: Option[String]): Unit = {
val treeRoot: SerialisableDebugTree = this.convertDebugTree(tree)
up.writeTo(SerialisablePayload(input, treeRoot, parserInfo.map((info: ParserInfo) => (info.path, info.positions)).toMap, sessionId, isDebuggable, refs), file)
up.writeTo(SerialisablePayload(input, treeRoot, parserInfo.map((info: ParserInfo) => (info.path, info.positions)).toMap, sessionId, isDebuggable, refs, sessionName), file)
}

/**
Expand All @@ -108,9 +109,9 @@ object DebugTreeSerialiser {
* @param tree The DebugTree
* @return JSON formatted String
*/
def toJSON(input: String, tree: DebugTree, sessionId: Int, parserInfo: List[ParserInfo], isDebuggable: Boolean, refs: Seq[CodedRef]): String = {
def toJSON(input: String, tree: DebugTree, sessionId: Int, parserInfo: List[ParserInfo], isDebuggable: Boolean, refs: Seq[CodedRef], sessionName: Option[String]): String = {
val treeRoot: SerialisableDebugTree = this.convertDebugTree(tree)
up.write(SerialisablePayload(input, treeRoot, parserInfo.map((info: ParserInfo) => (info.path, info.positions)).toMap, sessionId, isDebuggable, refs))
up.write(SerialisablePayload(input, treeRoot, parserInfo.map((info: ParserInfo) => (info.path, info.positions)).toMap, sessionId, isDebuggable, refs, sessionName))
}

}
}