forked from moonsharp-devs/moonsharp
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMoonSharpDebugSession.cs
95 lines (78 loc) · 2.06 KB
/
MoonSharpDebugSession.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using MoonSharp.Interpreter;
using MoonSharp.VsCodeDebugger.SDK;
namespace MoonSharp.VsCodeDebugger.DebuggerLogic
{
public class Session
{
public int port { get; }
public string name { get; }
public Session(int port, string name)
{
this.port = port;
this.name = name;
}
}
public class SessionsResponseBody : ResponseBody
{
public Session[] sessions { get; }
public SessionsResponseBody(List<Session> sessions)
{
this.sessions = sessions.ToArray<Session>();
}
}
internal abstract class MoonSharpDebugSession : DebugSession
{
readonly object _sendLock = new object();
public int Port { get; }
public MoonSharpVsCodeDebugServer Server { get; }
public AsyncDebugger Debugger { get; } // Can be null!
public abstract string Name { get; }
internal MoonSharpDebugSession(int port, MoonSharpVsCodeDebugServer server, AsyncDebugger debugger)
{
Port = port;
Server = server;
Debugger = debugger;
}
protected override void SendMessage(ProtocolMessage message)
{
lock (_sendLock)
{
base.SendMessage(message);
}
}
protected override void DispatchRequest(string command, Table args, Response response)
{
if (args == null)
{
args = new Table(null);
}
try
{
switch (command)
{
case "_sessions":
Sessions(response, args);
return;
}
}
catch (Exception e)
{
SendErrorResponse(response, 1104, "error while processing request '{_request}' (exception: {_exception})", new { _request = command, _exception = e.Message });
}
base.DispatchRequest(command, args, response);
}
protected void SendTerminateEvent(bool restart)
{
SendEvent(new TerminatedEvent(restart ? new {} : null));
}
public void Sessions(Response response, Table arguments)
{
List<Session> sessions = Server.GetSessionsByPortAndName().Select((p => new Session(p.Key, p.Value))).ToList();
SendResponse(response, new SessionsResponseBody(sessions));
}
public abstract void Terminate(bool restart = false);
}
}