@@ -137,9 +137,16 @@ public Task HandleScriptExecuteRequest(ScriptingParams parameters, RequestContex
137137
138138 operation . PlanNotification += ( sender , e ) => requestContext . SendEvent ( ScriptingPlanNotificationEvent . Type , e ) . Wait ( ) ;
139139 operation . ProgressNotification += ( sender , e ) => requestContext . SendEvent ( ScriptingProgressNotificationEvent . Type , e ) . Wait ( ) ;
140- operation . CompleteNotification += ( sender , e ) => this . SendScriptingCompleteEvent ( requestContext , ScriptingCompleteEvent . Type , e , operation , parameters . ScriptDestination ) ;
140+ operation . CompleteNotification += ( sender , e ) => this . SendScriptingCompleteEvent ( requestContext , ScriptingCompleteEvent . Type , e , operation , parameters ) ;
141141
142142 RunTask ( requestContext , operation ) ;
143+
144+ // If ReturnScriptAsynchronously is enabled, return operation ID immediately
145+ if ( parameters . ReturnScriptAsynchronously )
146+ {
147+ return requestContext . SendResult ( new ScriptingResult { OperationId = operation . OperationId } ) ;
148+ }
149+
143150 return Task . CompletedTask ;
144151 }
145152
@@ -180,10 +187,19 @@ public async Task HandleScriptCancelRequest(ScriptingCancelParams parameters, Re
180187 }
181188
182189 private async void SendScriptingCompleteEvent < TParams > ( RequestContext < ScriptingResult > requestContext , EventType < TParams > eventType , TParams parameters ,
183- SmoScriptingOperation operation , string scriptDestination )
190+ SmoScriptingOperation operation , ScriptingParams scriptingParams )
184191 {
192+ // If ReturnScriptAsynchronously is enabled, include script in the complete event
193+ if ( scriptingParams . ReturnScriptAsynchronously && parameters is ScriptingCompleteParams completeParams )
194+ {
195+ completeParams . Script = operation . ScriptText ;
196+ await requestContext . SendEvent ( eventType , parameters ) ;
197+ return ;
198+ }
199+
185200 await requestContext . SendEvent ( eventType , parameters ) ;
186- switch ( scriptDestination )
201+
202+ switch ( scriptingParams . ScriptDestination )
187203 {
188204 case "ToEditor" :
189205 await requestContext . SendResult ( new ScriptingResult { OperationId = operation . OperationId , Script = operation . ScriptText } ) ;
0 commit comments