Skip to content

Commit f176687

Browse files
committed
Show deprecation message in VS Code Debug Console
This change causes a message to be displayed in VS Code's Debug Console if the user tries to execute a command there while debugging a PowerShell script. The message directs the user to open the Integrated Console instead. Resolves PowerShell/vscode-powershell#596.
1 parent 8efdcc3 commit f176687

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

+41-17
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ await this.editorSession.PowerShellContext.ExecuteScriptString(
295295
"", false, true);
296296
}
297297

298+
if (this.editorSession.ConsoleService.EnableConsoleRepl)
299+
{
300+
await this.WriteUseIntegratedConsoleMessage();
301+
}
302+
298303
// Send the InitializedEvent so that the debugger will continue
299304
// sending configuration requests
300305
await this.SendEvent(
@@ -743,23 +748,30 @@ protected async Task HandleEvaluateRequest(
743748

744749
if (isFromRepl)
745750
{
746-
// Check for special commands
747-
if (string.Equals("!ctrlc", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
748-
{
749-
editorSession.PowerShellContext.AbortExecution();
750-
}
751-
else if (string.Equals("!break", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
751+
if (!this.editorSession.ConsoleService.EnableConsoleRepl)
752752
{
753-
editorSession.DebugService.Break();
753+
// Check for special commands
754+
if (string.Equals("!ctrlc", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
755+
{
756+
editorSession.PowerShellContext.AbortExecution();
757+
}
758+
else if (string.Equals("!break", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
759+
{
760+
editorSession.DebugService.Break();
761+
}
762+
else
763+
{
764+
// Send the input through the console service
765+
var notAwaited =
766+
this.editorSession
767+
.PowerShellContext
768+
.ExecuteScriptString(evaluateParams.Expression, false, true)
769+
.ConfigureAwait(false);
770+
}
754771
}
755772
else
756773
{
757-
// Send the input through the console service
758-
var notAwaited =
759-
this.editorSession
760-
.PowerShellContext
761-
.ExecuteScriptString(evaluateParams.Expression, false, true)
762-
.ConfigureAwait(false);
774+
await this.WriteUseIntegratedConsoleMessage();
763775
}
764776
}
765777
else
@@ -770,10 +782,11 @@ protected async Task HandleEvaluateRequest(
770782
// has been resumed, return an empty result in this case.
771783
if (editorSession.PowerShellContext.IsDebuggerStopped)
772784
{
773-
await editorSession.DebugService.EvaluateExpression(
774-
evaluateParams.Expression,
775-
evaluateParams.FrameId,
776-
isFromRepl);
785+
result =
786+
await editorSession.DebugService.EvaluateExpression(
787+
evaluateParams.Expression,
788+
evaluateParams.FrameId,
789+
isFromRepl);
777790
}
778791

779792
if (result != null)
@@ -793,6 +806,17 @@ await requestContext.SendResult(
793806
});
794807
}
795808

809+
private async Task WriteUseIntegratedConsoleMessage()
810+
{
811+
await this.SendEvent(
812+
OutputEvent.Type,
813+
new OutputEventBody
814+
{
815+
Output = "\nThe Debug Console is no longer used for PowerShell debugging. Please use the 'PowerShell Integrated Console' to execute commands in the debugger. Run the 'PowerShell: Show Integrated Console' command to open it.",
816+
Category = "stderr"
817+
});
818+
}
819+
796820
#endregion
797821

798822
#region Event Handlers

0 commit comments

Comments
 (0)