Skip to content
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

fix handling of completions that rely on nested commands #2727

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions NotebookTestScript.dib
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!meta

{"kernelInfo":{"defaultKernelName":null,"items":[{"name":"csharp","languageName":"C#","aliases":["c#","cs"]},{"name":"fsharp","languageName":"F#","aliases":["f#","fs"]},{"name":"pwsh","languageName":"PowerShell","aliases":["powershell"]},{"name":"javascript","languageName":"JavaScript","aliases":["js"]},{"name":"html","languageName":"HTML"},{"name":"sql","languageName":"SQL"},{"name":"kql","languageName":"KQL"},{"name":"mermaid","languageName":"Mermaid"},{"name":"http","languageName":"HTTP"},{"name":"value"}]}}
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"name":"csharp","aliases":[]}]}}

#!markdown

Expand Down Expand Up @@ -188,7 +188,7 @@ Console.Error.Write("\x1b[0m");
#!markdown

# vscode kernel and user input prompts
This cell should prompt the user for input
This cell should prompt the user for input. Type something into the input field. Whatever you typed should be displayed in the output.

#!csharp

Expand Down Expand Up @@ -221,7 +221,16 @@ value_from_input

#!markdown

Now check the variable explorer. Is the value there in the `#!value` kernel?
Now check the variable explorer. Is the value there in the `value` kernel?

#!markdown

This should prompt you for input. Type something into the input field. Whatever you typed should be displayed in the output.

#!csharp

#!set --name csharpVarFromInput --value @input:"Please enter a value"
csharpVarFromInput

#!markdown

Expand Down
18 changes: 9 additions & 9 deletions src/Microsoft.DotNet.Interactive/KernelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ private static void ConfigureAndAddSetMagicCommand<T>(T kernel) where T : Kernel

valueOption.AddCompletions(_ =>
{
// FIX: (ConfigureAndAddSetMagicCommand) why is this getting invoked this option wasn't specified?

if (kernel.ParentKernel is { } composite)
{
var getValueTasks = composite.ChildKernels
Expand All @@ -295,13 +293,15 @@ private static void ConfigureAndAddSetMagicCommand<T>(T kernel) where T : Kernel

var tasks = Task.WhenAll(getValueTasks).GetAwaiter().GetResult();

return tasks
.Select(t => t.Events.OfType<ValueInfosProduced>())
.SelectMany(events => events.Select(e => new { e.Command.TargetKernelName, e.ValueInfos }))
.SelectMany(x => x.ValueInfos.Select(i => $"@{x.TargetKernelName}:{i.Name}"))
.OrderBy(x => x)
.Select(n => new CompletionItem(n))
.ToArray();
var x = tasks
.Select(t => t.Events.OfType<ValueInfosProduced>())
.SelectMany(events => events.Select(e => new { e.Command.TargetKernelName, e.ValueInfos }))
.SelectMany(x => x.ValueInfos.Select(i => $"@{x.TargetKernelName}:{i.Name}"))
.OrderBy(x => x)
.Select(n => new CompletionItem(n))
.ToArray();

return x;
}

return Array.Empty<CompletionItem>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class InteractiveClient {
token = token || this.getNextToken();
const id = Guid.create().toString();
let disposable = this.subscribeToKernelTokenEvents(token, eventEnvelope => {
if (eventEnvelope.command?.token === token) {
if (eventEnvelope.command?.token === token && eventEnvelope.eventType === expectedEventType) {
switch (eventEnvelope.eventType) {
case CommandFailedType:
if (!handled) {
Expand Down