Skip to content

Commit 62f1e5b

Browse files
committed
Add !ctrlc and !break commands to debug adapter evaluator
This change adds the !ctrlc and !break commands which are special to the debug adapter's REPL interface. The provide the ability to send a Ctrl+C (abort) or Ctrl+B (break) at any time. This is necessary because the debugger UI can't properly handle or transfer these commands in some cases.
1 parent 47b47e3 commit 62f1e5b

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,14 @@ protected async Task HandleSetBreakpointsRequest(
344344
RequestContext<SetBreakpointsResponseBody> requestContext)
345345
{
346346
ScriptFile scriptFile = null;
347-
Exception notFoundException = null;
348347

349348
// Fix for issue #195 - user can change name of file outside of VSCode in which case
350349
// VSCode sends breakpoint requests with the original filename that doesn't exist anymore.
351350
try
352351
{
353352
scriptFile = editorSession.Workspace.GetFile(setBreakpointsParams.Source.Path);
354353
}
355-
catch (DirectoryNotFoundException e)
356-
{
357-
notFoundException = e;
358-
}
359-
catch (FileNotFoundException e)
360-
{
361-
notFoundException = e;
362-
}
363-
364-
if (notFoundException != null)
354+
catch (Exception e) when (e is FileNotFoundException || e is DirectoryNotFoundException)
365355
{
366356
Logger.Write(
367357
LogLevel.Warning,
@@ -659,10 +649,22 @@ protected async Task HandleEvaluateRequest(
659649

660650
if (isFromRepl)
661651
{
662-
// Send the input through the console service
663-
editorSession.ConsoleService.ExecuteCommand(
664-
evaluateParams.Expression,
665-
false);
652+
// Check for special commands
653+
if (string.Equals("!ctrlc", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
654+
{
655+
editorSession.PowerShellContext.AbortExecution();
656+
}
657+
else if (string.Equals("!break", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
658+
{
659+
editorSession.DebugService.Break();
660+
}
661+
else
662+
{
663+
// Send the input through the console service
664+
editorSession.ConsoleService.ExecuteCommand(
665+
evaluateParams.Expression,
666+
false);
667+
}
666668
}
667669
else
668670
{

0 commit comments

Comments
 (0)