From 7f72d87e7be8297b08c2f3e205423dcec794de1c Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 16 May 2016 14:30:38 -0700 Subject: [PATCH] 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. --- .../Server/LanguageServer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 1cd5065c5..872548d21 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -193,6 +193,10 @@ private Task HandleInvokeExtensionCommandRequest( InvokeExtensionCommandRequest commandDetails, RequestContext requestContext) { + // We don't await the result of the execution here because we want + // to be able to receive further messages while the editor command + // is executing. This important in cases where the pipeline thread + // gets blocked by something in the script like a prompt to the user. EditorContext editorContext = this.editorOperations.ConvertClientEditorContext( commandDetails.Context); @@ -207,7 +211,7 @@ private Task HandleInvokeExtensionCommandRequest( return requestContext.SendResult(null); }); - return commandTask; + return Task.FromResult(true); } private async Task HandleExpandAliasRequest(