Skip to content

[Revamp pipeline thread handling] Reinstate prompt handlers #1583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rjmholt opened this issue Oct 12, 2021 · 1 comment
Closed

[Revamp pipeline thread handling] Reinstate prompt handlers #1583

rjmholt opened this issue Oct 12, 2021 · 1 comment
Assignees
Labels

Comments

@rjmholt
Copy link
Contributor

rjmholt commented Oct 12, 2021

In the migration from the PowerShellContext, this code was taken out:

internal class ProtocolChoicePromptHandler : ConsoleChoicePromptHandler
{
private readonly ILanguageServerFacade _languageServer;
private readonly IHostInput _hostInput;
private TaskCompletionSource<string> _readLineTask;
public ProtocolChoicePromptHandler(
ILanguageServerFacade languageServer,
IHostInput hostInput,
IHostOutput hostOutput,
ILogger logger)
: base(hostOutput, logger)
{
_languageServer = languageServer;
this._hostInput = hostInput;
this.hostOutput = hostOutput;
}
protected override void ShowPrompt(PromptStyle promptStyle)
{
base.ShowPrompt(promptStyle);
_languageServer.SendRequest<ShowChoicePromptRequest>(
"powerShell/showChoicePrompt",
new ShowChoicePromptRequest
{
IsMultiChoice = this.IsMultiChoice,
Caption = this.Caption,
Message = this.Message,
Choices = this.Choices,
DefaultChoices = this.DefaultChoices
})
.Returning<ShowChoicePromptResponse>(CancellationToken.None)
.ContinueWith(HandlePromptResponse)
.ConfigureAwait(false);
}
protected override Task<string> ReadInputStringAsync(CancellationToken cancellationToken)
{
this._readLineTask = new TaskCompletionSource<string>();
return this._readLineTask.Task;
}
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.LogError(
"ShowChoicePrompt request failed with error:\r\n{0}",
responseTask.Exception.ToString());
}
// Cancel the current prompt
this._hostInput.SendControlC();
}
this._readLineTask = null;
}
}
internal class ProtocolInputPromptHandler : ConsoleInputPromptHandler
{
private readonly ILanguageServerFacade _languageServer;
private readonly IHostInput hostInput;
private TaskCompletionSource<string> readLineTask;
public ProtocolInputPromptHandler(
ILanguageServerFacade languageServer,
IHostInput hostInput,
IHostOutput hostOutput,
ILogger logger)
: base(hostOutput, logger)
{
_languageServer = languageServer;
this.hostInput = hostInput;
this.hostOutput = hostOutput;
}
protected override void ShowFieldPrompt(FieldDetails fieldDetails)
{
base.ShowFieldPrompt(fieldDetails);
_languageServer.SendRequest<ShowInputPromptRequest>(
"powerShell/showInputPrompt",
new ShowInputPromptRequest
{
Name = fieldDetails.Name,
Label = fieldDetails.Label
}).Returning<ShowInputPromptResponse>(CancellationToken.None)
.ContinueWith(HandlePromptResponse)
.ConfigureAwait(false);
}
protected override Task<string> ReadInputStringAsync(CancellationToken cancellationToken)
{
this.readLineTask = new TaskCompletionSource<string>();
return this.readLineTask.Task;
}
private void HandlePromptResponse(
Task<ShowInputPromptResponse> responseTask)
{
if (responseTask.IsCompleted)
{
ShowInputPromptResponse 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.LogError(
"ShowInputPrompt request failed with error:\r\n{0}",
responseTask.Exception.ToString());
}
// Cancel the current prompt
this.hostInput.SendControlC();
}
this.readLineTask = null;
}
protected override Task<SecureString> ReadSecureStringAsync(CancellationToken cancellationToken)
{
// TODO: Write a message to the console
throw new NotImplementedException();
}
}

We should ensure that functionality is restored in the extension.

@ghost ghost added the Needs: Triage Maintainer attention needed! label Oct 12, 2021
@StevenBucher98 StevenBucher98 added Area-General Area-psEditor Issue-Enhancement A feature request (enhancement). and removed Needs: Triage Maintainer attention needed! labels Oct 18, 2021
@andyleejordan
Copy link
Member

Oh no @SydneyhSmith apparently this is why those interfaces disappeared...we took out the tests in #1660. I guess if users ask for this we'll work to bring it back.

@andyleejordan andyleejordan moved this to Todo in Sea Biscuit Jan 20, 2022
Repository owner moved this from Todo to Done in Sea Biscuit Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants