private void HandlePromptResponse( Task <ShowChoicePromptResponse> responseTask) { if (responseTask.IsCompleted) { ShowChoicePromptResponse response = responseTask.Result; if (!response.PromptCancelled) { this.consoleService.ReceivePromptResponse( response.ChosenItem, false); } else { // Cancel the current prompt this.consoleService.SendControlC(); } } else { if (responseTask.IsFaulted) { // Log the error Logger.Write( LogLevel.Error, "ShowChoicePrompt request failed with error:\r\n{0}", responseTask.Exception.ToString()); } // Cancel the current prompt this.consoleService.SendControlC(); } }
public async Task <string> PromptSelectionAsync(string message, IReadOnlyList <PromptChoiceDetails> choices, int defaultChoiceIndex) { ChoiceDetails[] choiceDetails = GetChoiceDetails(choices); ShowChoicePromptResponse response = await _languageServer.SendRequest <ShowChoicePromptRequest>( "powerShell/showChoicePrompt", new ShowChoicePromptRequest { IsMultiChoice = false, Caption = string.Empty, Message = message, Choices = choiceDetails, DefaultChoices = defaultChoiceIndex > -1 ? new[] { defaultChoiceIndex } : null, }).Returning <ShowChoicePromptResponse>(CancellationToken.None); if (response.PromptCancelled) { return(null); } return(response.ResponseText); }
public async Task <IReadOnlyList <string> > PromptMultipleSelectionAsync(string message, IReadOnlyList <PromptChoiceDetails> choices, IReadOnlyList <int> defaultChoiceIndexes) { ChoiceDetails[] choiceDetails = GetChoiceDetails(choices); ShowChoicePromptResponse response = await _languageServer.SendRequest <ShowChoicePromptRequest>( "powerShell/showChoicePrompt", new ShowChoicePromptRequest { IsMultiChoice = true, Caption = string.Empty, Message = message, Choices = choiceDetails, DefaultChoices = defaultChoiceIndexes?.ToArray(), }).Returning <ShowChoicePromptResponse>(CancellationToken.None); if (response.PromptCancelled) { return(null); } return(response.ResponseText.Split(s_choiceResponseLabelSeparators, StringSplitOptions.None)); }
private void HandlePromptResponse( Task <ShowChoicePromptResponse> responseTask) { if (responseTask.IsCompleted) { ShowChoicePromptResponse response = responseTask.Result; if (!response.PromptCancelled) { this.hostOutput.WriteOutput( response.ResponseText, OutputType.Normal); this.readLineTask.TrySetResult(response.ResponseText); } else { // Cancel the current prompt this.hostInput.SendControlC(); } } else { if (responseTask.IsFaulted) { // Log the error Logger.Write( LogLevel.Error, "ShowChoicePrompt request failed with error:\r\n{0}", responseTask.Exception.ToString()); } // Cancel the current prompt this.hostInput.SendControlC(); } this.readLineTask = null; }