@@ -20,6 +20,8 @@ public class DebugAdapter : DebugAdapterBase
20
20
{
21
21
private EditorSession editorSession ;
22
22
private OutputDebouncer outputDebouncer ;
23
+ private bool isConfigurationDoneRequestComplete ;
24
+ private bool isLaunchRequestComplete ;
23
25
private string scriptPathToLaunch ;
24
26
private string arguments ;
25
27
@@ -65,6 +67,23 @@ protected override void Initialize()
65
67
this . SetRequestHandler ( EvaluateRequest . Type , this . HandleEvaluateRequest ) ;
66
68
}
67
69
70
+ protected Task LaunchScript ( RequestContext < object > requestContext )
71
+ {
72
+ return editorSession . PowerShellContext
73
+ . ExecuteScriptAtPath ( this . scriptPathToLaunch , this . arguments )
74
+ . ContinueWith (
75
+ async ( t ) => {
76
+ Logger . Write ( LogLevel . Verbose , "Execution completed, terminating..." ) ;
77
+
78
+ await requestContext . SendEvent (
79
+ TerminatedEvent . Type ,
80
+ null ) ;
81
+
82
+ // Stop the server
83
+ this . Stop ( ) ;
84
+ } ) ;
85
+ }
86
+
68
87
protected override void Shutdown ( )
69
88
{
70
89
// Make sure remaining output is flushed before exiting
@@ -81,6 +100,23 @@ protected override void Shutdown()
81
100
82
101
#region Built-in Message Handlers
83
102
103
+ protected async Task HandleConfigurationDoneRequest (
104
+ object args ,
105
+ RequestContext < object > requestContext )
106
+ {
107
+ // The order of debug protocol messages apparently isn't as guaranteed as we might like.
108
+ // Need to be able to handle the case where we get the configurationDone request after the
109
+ // launch request.
110
+ if ( this . isLaunchRequestComplete )
111
+ {
112
+ this . LaunchScript ( requestContext ) ;
113
+ }
114
+
115
+ this . isConfigurationDoneRequestComplete = true ;
116
+
117
+ await requestContext . SendResult ( null ) ;
118
+ }
119
+
84
120
protected async Task HandleLaunchRequest (
85
121
LaunchRequestArguments launchParams ,
86
122
RequestContext < object > requestContext )
@@ -114,14 +150,24 @@ protected async Task HandleLaunchRequest(
114
150
Logger . Write ( LogLevel . Verbose , "Script arguments are: " + arguments ) ;
115
151
}
116
152
117
- // NOTE: We don't actually launch the script in response to this
118
- // request. We wait until we receive the configurationDone request
119
- // to actually launch the script under the debugger. This gives
120
- // us and VSCode a chance to finish configuring all the types of
121
- // breakpoints.
153
+ // We may not actually launch the script in response to this
154
+ // request unless it comes after the configurationDone request.
155
+ // If the launch request comes first, then stash the launch
156
+ // params so that the subsequent configurationDone request handler
157
+ // can launch the script.
122
158
this . scriptPathToLaunch = launchParams . Program ;
123
159
this . arguments = arguments ;
124
160
161
+ // The order of debug protocol messages apparently isn't as guaranteed as we might like.
162
+ // Need to be able to handle the case where we get the launch request after the
163
+ // configurationDone request.
164
+ if ( this . isConfigurationDoneRequestComplete )
165
+ {
166
+ this . LaunchScript ( requestContext ) ;
167
+ }
168
+
169
+ this . isLaunchRequestComplete = true ;
170
+
125
171
await requestContext . SendResult ( null ) ;
126
172
}
127
173
@@ -133,31 +179,6 @@ protected Task HandleAttachRequest(
133
179
throw new NotImplementedException ( ) ;
134
180
}
135
181
136
- protected async Task HandleConfigurationDoneRequest (
137
- object args ,
138
- RequestContext < object > requestContext )
139
- {
140
- // Execute the given PowerShell script and send the response.
141
- // Note that we aren't waiting for execution to complete here
142
- // because the debugger could stop while the script executes.
143
- Task executeTask =
144
- editorSession . PowerShellContext
145
- . ExecuteScriptAtPath ( this . scriptPathToLaunch , this . arguments )
146
- . ContinueWith (
147
- async ( t ) => {
148
- Logger . Write ( LogLevel . Verbose , "Execution completed, terminating..." ) ;
149
-
150
- await requestContext . SendEvent (
151
- TerminatedEvent . Type ,
152
- null ) ;
153
-
154
- // Stop the server
155
- this . Stop ( ) ;
156
- } ) ;
157
-
158
- await requestContext . SendResult ( null ) ;
159
- }
160
-
161
182
protected Task HandleDisconnectRequest (
162
183
object disconnectParams ,
163
184
RequestContext < object > requestContext )
0 commit comments