@@ -48,10 +48,6 @@ public SynchronousPowerShellTask(
48
48
49
49
public override ExecutionOptions ExecutionOptions => PowerShellExecutionOptions ;
50
50
51
- // These are PowerShell's intrinsic debugger commands that must be run via
52
- // `ProcessDebugCommand`.
53
- private static readonly string [ ] DebuggerCommands = { "continue" , "c" , "k" , "h" , "?" , "list" , "l" , "stepInto" , "s" , "stepOut" , "o" , "stepOver" , "v" , "quit" , "q" , "detach" , "d" } ;
54
-
55
51
public override IReadOnlyList < TResult > Run ( CancellationToken cancellationToken )
56
52
{
57
53
_psesHost . Runspace . ThrowCancelledIfUnusable ( ) ;
@@ -65,8 +61,14 @@ public override IReadOnlyList<TResult> Run(CancellationToken cancellationToken)
65
61
_psesHost . WriteWithPrompt ( _psCommand , cancellationToken ) ;
66
62
}
67
63
64
+ // If we're in a breakpoint it means we're executing either interactive commands in
65
+ // a debug prompt, or our own special commands to query the PowerShell debugger for
66
+ // state that we sync with the LSP debugger. The former commands we want to send
67
+ // through PowerShell's `Debugger.ProcessCommand` so that they work as expected, but
68
+ // the latter we must not send through it else they pollute the history as this
69
+ // PowerShell API does not let us exclude them from it.
68
70
return _pwsh . Runspace . Debugger . InBreakpoint
69
- && ( IsDebuggerCommand ( _psCommand ) || _pwsh . Runspace . RunspaceIsRemote )
71
+ && ( PowerShellExecutionOptions . AddToHistory || IsPromptCommand ( _psCommand ) || _pwsh . Runspace . RunspaceIsRemote )
70
72
? ExecuteInDebugger ( cancellationToken )
71
73
: ExecuteNormally ( cancellationToken ) ;
72
74
}
@@ -78,7 +80,7 @@ public override IReadOnlyList<TResult> Run(CancellationToken cancellationToken)
78
80
79
81
public override string ToString ( ) => _psCommand . GetInvocationText ( ) ;
80
82
81
- private static bool IsDebuggerCommand ( PSCommand command )
83
+ private static bool IsPromptCommand ( PSCommand command )
82
84
{
83
85
if ( command . Commands . Count is not 1
84
86
|| command . Commands [ 0 ] is { IsScript : false } or { Parameters . Count : > 0 } )
@@ -87,15 +89,7 @@ private static bool IsDebuggerCommand(PSCommand command)
87
89
}
88
90
89
91
string commandText = command . Commands [ 0 ] . CommandText ;
90
- foreach ( string knownCommand in DebuggerCommands )
91
- {
92
- if ( commandText . Equals ( knownCommand , StringComparison . OrdinalIgnoreCase ) )
93
- {
94
- return true ;
95
- }
96
- }
97
-
98
- return false ;
92
+ return commandText . Equals ( "prompt" , StringComparison . OrdinalIgnoreCase ) ;
99
93
}
100
94
101
95
private IReadOnlyList < TResult > ExecuteNormally ( CancellationToken cancellationToken )
@@ -124,7 +118,7 @@ private IReadOnlyList<TResult> ExecuteNormally(CancellationToken cancellationTok
124
118
result = _pwsh . InvokeCommand < TResult > ( _psCommand , invocationSettings ) ;
125
119
cancellationToken . ThrowIfCancellationRequested ( ) ;
126
120
}
127
- // Allow terminate exceptions to propogate for flow control.
121
+ // Allow terminate exceptions to propagate for flow control.
128
122
catch ( TerminateException )
129
123
{
130
124
throw ;
@@ -222,12 +216,12 @@ private IReadOnlyList<TResult> ExecuteInDebugger(CancellationToken cancellationT
222
216
//
223
217
// Unfortunately, this API does not allow us to pass in the InvocationSettings,
224
218
// which means (for instance) that we cannot instruct it to avoid adding our
225
- // debugger implmentation 's commands to the history. So instead we now only call
219
+ // debugger implementation 's commands to the history. So instead we now only call
226
220
// `ExecuteInDebugger` for PowerShell's own intrinsic debugger commands.
227
221
debuggerResult = _pwsh . Runspace . Debugger . ProcessCommand ( _psCommand , outputCollection ) ;
228
222
cancellationToken . ThrowIfCancellationRequested ( ) ;
229
223
}
230
- // Allow terminate exceptions to propogate for flow control.
224
+ // Allow terminate exceptions to propagate for flow control.
231
225
catch ( TerminateException )
232
226
{
233
227
throw ;
@@ -281,7 +275,7 @@ private IReadOnlyList<TResult> ExecuteInDebugger(CancellationToken cancellationT
281
275
282
276
_psesHost . DebugContext . ProcessDebuggerResult ( debuggerResult ) ;
283
277
284
- // Optimisation to save wasted computation if we're going to throw the output away anyway
278
+ // Optimization to save wasted computation if we're going to throw the output away anyway
285
279
if ( PowerShellExecutionOptions . WriteOutputToHost )
286
280
{
287
281
return Array . Empty < TResult > ( ) ;
0 commit comments