Skip to content

Commit 7f72d87

Browse files
committed
Fix #222: Prompt functions hang in editor commands
This change fixes an issue where $host.UI prompt functions do not return the user's response when run inside of PowerShell editor commands. This was caused by the HandleInvokeExtensionCommand method returning a Task that did not complete until after the command completed. The fix was to not await on completion of the command so that the prompt response has a chance to come through.
1 parent ba27e4a commit 7f72d87

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ private Task HandleInvokeExtensionCommandRequest(
193193
InvokeExtensionCommandRequest commandDetails,
194194
RequestContext<string> requestContext)
195195
{
196+
// We don't await the result of the execution here because we want
197+
// to be able to receive further messages while the editor command
198+
// is executing. This important in cases where the pipeline thread
199+
// gets blocked by something in the script like a prompt to the user.
196200
EditorContext editorContext =
197201
this.editorOperations.ConvertClientEditorContext(
198202
commandDetails.Context);
@@ -207,7 +211,7 @@ private Task HandleInvokeExtensionCommandRequest(
207211
return requestContext.SendResult(null);
208212
});
209213

210-
return commandTask;
214+
return Task.FromResult(true);
211215
}
212216

213217
private async Task HandleExpandAliasRequest(

0 commit comments

Comments
 (0)