Skip to content

Commit

Permalink
fail invocation context when user input is canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Oct 8, 2024
1 parent e05e149 commit 68825f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Microsoft.DotNet.Interactive/KeyValueStoreKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ Task<KernelCommand> TryGetKernelCommandAsync(
ExpressionBindingResult expressionBindingResult,
Kernel keyValueStoreKernel)
{
if (expressionBindingResult.Diagnostics.FirstOrDefault(d => d.Severity == DiagnosticSeverity.Error) is { } diagnostic)
{
directiveNode.AddDiagnostic(diagnostic);
return Task.FromResult<KernelCommand>(null);
}

var parameterValues = directiveNode
.GetParameterValues(directive, expressionBindingResult.BoundValues)
.ToDictionary(t => t.Name, t => (t.Value, t.ParameterNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal DirectiveExpressionNode(SourceText sourceText, SyntaxTree syntaxTree) :

public DirectiveExpressionParametersNode? ParametersNode { get; private set; }

public bool IsInputExpression =>
TypeNode?.Type is "input" or "password";

public void Add(DirectiveExpressionTypeNode node)
{
AddInternal(node);
Expand Down
11 changes: 10 additions & 1 deletion src/Microsoft.DotNet.Interactive/Parsing/SubmissionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@ await RequestSingleValueOrInputAsync(
sourceCommand,
directiveNode.TargetKernelName);
if (expressionNode.Parent is { Parent: DirectiveParameterNode { NameNode.Text: { } parameterName } })
if (bindingResult?.IsSuccessful == true &&
expressionNode.Parent is { Parent: DirectiveParameterNode { NameNode.Text: { } parameterName } })
{
if (inputProduced is not null)
{
Expand All @@ -798,6 +799,14 @@ await RequestSingleValueOrInputAsync(
valuesProduced.Add(parameterName, valueProduced);
}
}
else
{
if (directiveNode.DescendantNodesAndTokens().OfType<DirectiveExpressionNode>().Any(node => node.IsInputExpression) &&
KernelInvocationContext.Current is { Command: SubmitCode } context)
{
context.Fail(sourceCommand, message: "Input not provided.");
}
}
return bindingResult;
});
Expand Down

0 comments on commit 68825f9

Please sign in to comment.