Skip to content

Commit a4c9276

Browse files
feat: MoonSharpVsCodeDebugServer RequestPause(Script script)
1 parent af7cfe1 commit a4c9276

4 files changed

Lines changed: 55 additions & 65 deletions

File tree

src/MoonSharp.Interpreter.Tests/EmbeddableNUnitWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if EMBEDTEST || UNITY_5 || UNITY_5_3_OR_NEWER || UNITY_EDITOR || UNITY_STANDALONE
1+
#if EMBEDTEST || UNITY_5_3_OR_NEWER || UNITY_EDITOR || UNITY_STANDALONE
22

33
using System;
44
using System.Collections.Generic;

src/MoonSharp.Interpreter.Tests/NUnit2Compat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !(UNITY_5 || UNITY_5_3_OR_NEWER || UNITY_EDITOR || UNITY_STANDALONE)
1+
#if !(UNITY_5_3_OR_NEWER || UNITY_EDITOR || UNITY_STANDALONE)
22

33
using System;
44
using NUnit.Framework.Interfaces;
@@ -35,7 +35,7 @@ public ExpectedExceptionCommand(TestCommand innerCommand, Type expectedException
3535
_expectedException = expectedException;
3636
}
3737

38-
#if UNITY_5 || UNITY_5_3_OR_NEWER || UNITY_EDITOR || UNITY_STANDALONE
38+
#if UNITY_5_3_OR_NEWER || UNITY_EDITOR || UNITY_STANDALONE
3939
public override TestResult Execute(ITestExecutionContext context)
4040
#else
4141
public override TestResult Execute(TestExecutionContext context)

src/MoonSharp.VsCodeDebugger/DebuggerLogic/ScriptDebugSession.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,26 @@ public bool RemoveDebugger(Script script)
266266
}
267267
}
268268

269+
public bool RequestPause(Script script)
270+
{
271+
if (script == null)
272+
{
273+
return false;
274+
}
275+
276+
lock (m_Lock)
277+
{
278+
if (!m_ThreadIdByScript.TryGetValue(script, out var threadId) || !m_ThreadsById.TryGetValue(threadId, out var state))
279+
{
280+
return false;
281+
}
282+
283+
state.StopReason = STOP_REASON_PAUSED;
284+
state.Debugger.PauseRequested = true;
285+
return true;
286+
}
287+
}
288+
269289
public override void Initialize(Response response, Table args)
270290
{
271291
SendResponse(response, new Capabilities(

src/MoonSharp.VsCodeDebugger/MoonSharpVsCodeDebugServer.cs

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#if (!UNITY_5) || UNITY_STANDALONE
2-
31
using System;
42
using System.Collections.Generic;
53
using System.Linq;
@@ -144,6 +142,38 @@ public void Detach(Script script)
144142
}
145143
}
146144

145+
/// <summary>
146+
/// Requests a pause for the specified attached script.
147+
/// </summary>
148+
public void RequestPause(Script script)
149+
{
150+
if (script == null)
151+
{
152+
throw new ArgumentException("Cannot pause null.");
153+
}
154+
155+
lock (m_Lock)
156+
{
157+
if (m_Session != null)
158+
{
159+
if (!m_Session.RequestPause(script))
160+
{
161+
throw new ArgumentException("Cannot find script associated with debugger.");
162+
}
163+
}
164+
else
165+
{
166+
AsyncDebugger debugger = m_PendingDebuggerList.FirstOrDefault(d => d.Script == script);
167+
if (debugger == null)
168+
{
169+
throw new ArgumentException("Cannot find script associated with debugger.");
170+
}
171+
172+
debugger.PauseRequested = true;
173+
}
174+
}
175+
}
176+
147177
/// <summary>
148178
/// Gets a list of the attached debuggers by id and name
149179
/// </summary>
@@ -354,63 +384,3 @@ static void SpawnThread(string name, Action threadProc)
354384
}
355385
}
356386
}
357-
358-
#else
359-
using System;
360-
using System.Collections.Generic;
361-
using MoonSharp.Interpreter;
362-
using MoonSharp.Interpreter.Debugging;
363-
364-
namespace MoonSharp.VsCodeDebugger
365-
{
366-
public class MoonSharpVsCodeDebugServer : IDisposable
367-
{
368-
public MoonSharpVsCodeDebugServer(int port = 41912)
369-
{
370-
}
371-
372-
public void AttachToScript(Script script, string name, Func<SourceCode, string> sourceFinder = null)
373-
{
374-
}
375-
376-
public void ReplaceAttachedScript(Script previousScript, Script newScript, string name = null, Func<SourceCode, string> sourceFinder = null)
377-
{
378-
}
379-
380-
public IEnumerable<KeyValuePair<int, string>> GetAttachedDebuggersByIdAndName()
381-
{
382-
yield break;
383-
}
384-
385-
public IEnumerable<KeyValuePair<int, string>> GetListenersByPortAndDebuggerName()
386-
{
387-
yield break;
388-
}
389-
390-
public IEnumerable<KeyValuePair<int, string>> GetSessionsByPortAndName()
391-
{
392-
yield break;
393-
}
394-
395-
/// <summary>
396-
/// Detaches the specified script. The debugger attached to that script will get disconnected.
397-
/// </summary>
398-
/// <param name="script">The script.</param>
399-
/// <exception cref="ArgumentException">Thrown if the script cannot be found.</exception>
400-
public void Detach(Script script)
401-
{
402-
}
403-
404-
public Action<string> Logger { get; set; }
405-
406-
public void Dispose()
407-
{
408-
}
409-
410-
public MoonSharpVsCodeDebugServer Start()
411-
{
412-
return this;
413-
}
414-
}
415-
}
416-
#endif

0 commit comments

Comments
 (0)