@@ -23,10 +23,10 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
23
23
public class DebugAdapter : DebugAdapterBase
24
24
{
25
25
private EditorSession editorSession ;
26
- private OutputDebouncer outputDebouncer ;
27
26
28
27
private bool noDebug ;
29
28
private bool waitingForAttach ;
29
+ private bool ownsEditorSession ;
30
30
private string scriptPathToLaunch ;
31
31
private string arguments ;
32
32
@@ -35,21 +35,26 @@ public DebugAdapter(HostDetails hostDetails, ProfilePaths profilePaths)
35
35
{
36
36
}
37
37
38
+ public DebugAdapter ( EditorSession editorSession , ChannelBase serverChannel )
39
+ : base ( serverChannel )
40
+ {
41
+ this . editorSession = editorSession ;
42
+ this . editorSession . PowerShellContext . RunspaceChanged += this . powerShellContext_RunspaceChanged ;
43
+ this . editorSession . DebugService . DebuggerStopped += this . DebugService_DebuggerStopped ;
44
+ }
45
+
38
46
public DebugAdapter (
39
47
HostDetails hostDetails ,
40
48
ProfilePaths profilePaths ,
41
49
ChannelBase serverChannel ,
42
50
IEditorOperations editorOperations )
43
51
: base ( serverChannel )
44
52
{
53
+ this . ownsEditorSession = true ;
45
54
this . editorSession = new EditorSession ( ) ;
46
55
this . editorSession . StartDebugSession ( hostDetails , profilePaths , editorOperations ) ;
47
56
this . editorSession . PowerShellContext . RunspaceChanged += this . powerShellContext_RunspaceChanged ;
48
57
this . editorSession . DebugService . DebuggerStopped += this . DebugService_DebuggerStopped ;
49
- this . editorSession . ConsoleService . OutputWritten += this . powerShellContext_OutputWritten ;
50
-
51
- // Set up the output debouncer to throttle output event writes
52
- this . outputDebouncer = new OutputDebouncer ( this ) ;
53
58
}
54
59
55
60
protected override void Initialize ( )
@@ -82,15 +87,12 @@ protected override void Initialize()
82
87
83
88
protected Task LaunchScript ( RequestContext < object > requestContext )
84
89
{
85
- return editorSession . PowerShellContext
90
+ return editorSession . ConsoleService
86
91
. ExecuteScriptAtPath ( this . scriptPathToLaunch , this . arguments )
87
92
. ContinueWith (
88
93
async ( t ) => {
89
94
Logger . Write ( LogLevel . Verbose , "Execution completed, flushing output then terminating..." ) ;
90
95
91
- // Make sure remaining output is flushed before exiting
92
- await this . outputDebouncer . Flush ( ) ;
93
-
94
96
await this . SendEvent (
95
97
TerminatedEvent . Type ,
96
98
new TerminatedEvent ( ) ) ;
@@ -102,14 +104,18 @@ await this.SendEvent(
102
104
103
105
protected override void Shutdown ( )
104
106
{
105
- // Make sure remaining output is flushed before exiting
106
- this . outputDebouncer . Flush ( ) . Wait ( ) ;
107
-
108
107
Logger . Write ( LogLevel . Normal , "Debug adapter is shutting down..." ) ;
109
108
110
109
if ( this . editorSession != null )
111
110
{
112
- this . editorSession . Dispose ( ) ;
111
+ this . editorSession . PowerShellContext . RunspaceChanged -= this . powerShellContext_RunspaceChanged ;
112
+ this . editorSession . DebugService . DebuggerStopped -= this . DebugService_DebuggerStopped ;
113
+
114
+ if ( this . ownsEditorSession )
115
+ {
116
+ this . editorSession . Dispose ( ) ;
117
+ }
118
+
113
119
this . editorSession = null ;
114
120
}
115
121
}
@@ -657,26 +663,7 @@ protected async Task HandleEvaluateRequest(
657
663
"repl" ,
658
664
StringComparison . CurrentCultureIgnoreCase ) ;
659
665
660
- if ( isFromRepl )
661
- {
662
- // Check for special commands
663
- if ( string . Equals ( "!ctrlc" , evaluateParams . Expression , StringComparison . CurrentCultureIgnoreCase ) )
664
- {
665
- editorSession . PowerShellContext . AbortExecution ( ) ;
666
- }
667
- else if ( string . Equals ( "!break" , evaluateParams . Expression , StringComparison . CurrentCultureIgnoreCase ) )
668
- {
669
- editorSession . DebugService . Break ( ) ;
670
- }
671
- else
672
- {
673
- // Send the input through the console service
674
- editorSession . ConsoleService . ExecuteCommand (
675
- evaluateParams . Expression ,
676
- false ) ;
677
- }
678
- }
679
- else
666
+ if ( ! isFromRepl )
680
667
{
681
668
VariableDetails result =
682
669
await editorSession . DebugService . EvaluateExpression (
@@ -692,6 +679,12 @@ await editorSession.DebugService.EvaluateExpression(
692
679
result . Id : 0 ;
693
680
}
694
681
}
682
+ else
683
+ {
684
+ Logger . Write (
685
+ LogLevel . Verbose ,
686
+ $ "Debug adapter client attempted to evaluate command in REPL: { evaluateParams . Expression } ") ;
687
+ }
695
688
696
689
await requestContext . SendResult (
697
690
new EvaluateResponseBody
@@ -707,9 +700,6 @@ await requestContext.SendResult(
707
700
708
701
async void DebugService_DebuggerStopped ( object sender , DebuggerStoppedEventArgs e )
709
702
{
710
- // Flush pending output before sending the event
711
- await this . outputDebouncer . Flush ( ) ;
712
-
713
703
// Provide the reason for why the debugger has stopped script execution.
714
704
// See https://github.com/Microsoft/vscode/issues/3648
715
705
// The reason is displayed in the breakpoints viewlet. Some recommended reasons are:
@@ -766,12 +756,6 @@ await this.SendEvent<ContinuedEvent>(
766
756
}
767
757
}
768
758
769
- async void powerShellContext_OutputWritten ( object sender , OutputWrittenEventArgs e )
770
- {
771
- // Queue the output for writing
772
- await this . outputDebouncer . Invoke ( e ) ;
773
- }
774
-
775
759
#endregion
776
760
}
777
761
}
0 commit comments