Skip to content

Commit

Permalink
remove nested commands' events from outer KernelCommandResult.Events (#…
Browse files Browse the repository at this point in the history
…3177)

* allow explicit parenting, refactor away a bunch of command id usage

* remove command id from .NET code

* wip: remove id from TypeScript command

* Fix tests for polyglot notebook ts project

* align bahaviour to C#

* remove token property on typescript

* cleanup getOrCreateToken usage

* fix the child command root

* rename nested classes to avoid warning

---------

Co-authored-by: Diego Colombo <dicolomb@microsoft.com>
  • Loading branch information
jonsequitur and colombod authored Sep 19, 2023
1 parent 85fe710 commit f0979a5
Show file tree
Hide file tree
Showing 79 changed files with 343 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Microsoft.DotNet.Interactive
public System.Threading.Tasks.Task EndInvoke(System.IAsyncResult result)
public System.Threading.Tasks.Task Invoke(Microsoft.DotNet.Interactive.Commands.KernelCommand command, KernelInvocationContext context, KernelPipelineContinuation next)
public class KernelCommandResult
.ctor(Microsoft.DotNet.Interactive.Commands.KernelCommand command, System.Collections.Generic.IEnumerable<Microsoft.DotNet.Interactive.Events.KernelEvent> events = null)
.ctor(Microsoft.DotNet.Interactive.Commands.KernelCommand command)
public Microsoft.DotNet.Interactive.Commands.KernelCommand Command { get;}
public System.Collections.Generic.IReadOnlyList<Microsoft.DotNet.Interactive.Events.KernelEvent> Events { get;}
public class KernelCommandScheduler : KernelScheduler<Microsoft.DotNet.Interactive.Commands.KernelCommand,KernelCommandResult>, IKernelScheduler<Microsoft.DotNet.Interactive.Commands.KernelCommand,KernelCommandResult>, System.IDisposable
Expand Down Expand Up @@ -394,10 +394,9 @@ Microsoft.DotNet.Interactive.Commands
public Microsoft.DotNet.Interactive.CommandRoutingSlip RoutingSlip { get;}
public System.String TargetKernelName { get;}
public System.Boolean Equals(KernelCommand other)
public System.Int32 GetHashCode()
public System.String GetOrCreateToken()
public System.Threading.Tasks.Task InvokeAsync(Microsoft.DotNet.Interactive.KernelInvocationContext context)
public System.Void SetId(System.String id)
public System.Void SetParent(KernelCommand parent)
public System.Void SetToken(System.String token)
public abstract class LanguageServiceCommand : KernelCommand, System.IEquatable<KernelCommand>
public System.String Code { get;}
Expand Down Expand Up @@ -478,7 +477,6 @@ Microsoft.DotNet.Interactive.Connection
public System.Threading.Tasks.Task SendAsync(Microsoft.DotNet.Interactive.Events.KernelEvent kernelEvent, System.Threading.CancellationToken cancellationToken)
public abstract class IKernelCommandEnvelope
public Microsoft.DotNet.Interactive.Commands.KernelCommand Command { get;}
public System.String CommandId { get;}
public System.String CommandType { get;}
public System.String Token { get;}
public abstract class IKernelEventEnvelope
Expand Down Expand Up @@ -512,7 +510,6 @@ Microsoft.DotNet.Interactive.Connection
public static System.Void RegisterDefaults()
public static System.String Serialize(Microsoft.DotNet.Interactive.Commands.KernelCommand command)
public static System.String Serialize(IKernelCommandEnvelope envelope)
public System.String CommandId { get;}
public System.String CommandType { get;}
public System.String Token { get;}
public class KernelCommandEnvelope<T> : KernelCommandEnvelope, IKernelCommandEnvelope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "CompileProject",
"command": {
"targetKernelName": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "OpenDocument",
"command": {
"relativeFilePath": "./path",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "OpenProject",
"command": {
"project": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"eventType": "AssemblyProduced",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "CompileProject",
"command": {
"targetKernelName": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"eventType": "DocumentOpened",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "OpenDocument",
"command": {
"relativeFilePath": "./path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"eventType": "ProjectOpened",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "OpenProject",
"command": {
"project": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public void Command_contract_has_not_been_broken(KernelCommand command)
.UsingExtension($"{command.GetType().Name}.json")
.SetInteractive(Debugger.IsAttached);

command.SetId("command-id");
command.SetToken("the-token");

var json = KernelCommandEnvelope.Serialize(command);
Expand All @@ -113,7 +112,6 @@ public void Event_contract_has_not_been_broken(KernelEvent @event)
.UsingExtension($"{@event.GetType().Name}.json")
.SetInteractive(Debugger.IsAttached);

@event.Command?.SetId("command-id");
@event.Command?.SetToken("the-token");

var json = KernelEventEnvelope.Serialize(@event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.CommandLine;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -11,20 +12,37 @@
using Microsoft.DotNet.Interactive.Formatting;
using Microsoft.DotNet.Interactive.FSharp;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Pocket;
using Pocket.For.Xunit;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.DotNet.Interactive.Jupyter.Tests;

public partial class MagicCommandTests
{
public class LSMmagic
[LogToPocketLogger(FileNameEnvironmentVariable = "POCKETLOGGER_LOG_PATH")]
public class LSMmagic : IDisposable
{
private readonly CompositeDisposable _disposables = new();

public LSMmagic(ITestOutputHelper output)
{
_disposables.Add(output.SubscribeToPocketLogger());
}

public void Dispose()
{
_disposables.Dispose();
}

[Fact]
public async Task lsmagic_lists_registered_magic_commands()
{
using var kernel = new CompositeKernel()
.UseDefaultMagicCommands()
.LogEventsToPocketLogger();
.UseDefaultMagicCommands()
.LogEventsToPocketLogger();

kernel.AddDirective(new Command("#!one"));
kernel.AddDirective(new Command("#!two"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private static Command lsmagic(Kernel kernel)
foreach (var subkernel in subkernels)
{
var command = new SubmitCode(((SubmitCode)context.Command).Code);
command.SetParent(context.Command);

await subkernel.SendAsync(command);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<ProjectConfiguration>
<Settings />
<Settings>
<IgnoredTests>
<NamedTestSelector>
<TestName>Microsoft.DotNet.Interactive.Kql.Tests.KqlConnectionTests.query_produces_expected_formatted_values</TestName>
</NamedTestSelector>
</IgnoredTests>
</Settings>
</ProjectConfiguration>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "Cancel",
"command": {
"targetKernelName": "csharp",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "ChangeWorkingDirectory",
"command": {
"workingDirectory": "/path/to/somewhere",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "DisplayError",
"command": {
"message": "oops!",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "DisplayValue",
"command": {
"formattedValue": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "Quit",
"command": {
"targetKernelName": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "RequestCompletions",
"command": {
"code": "Cons",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "RequestDiagnostics",
"command": {
"code": "the-code",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "RequestHoverText",
"command": {
"code": "document-contents",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "RequestInput",
"command": {
"prompt": "provide answer",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "RequestKernelInfo",
"command": {
"targetKernelName": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "RequestSignatureHelp",
"command": {
"code": "sig-help-contents",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "RequestValue",
"command": {
"name": "a",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "RequestValueInfos",
"command": {
"mimeType": "text/plain+summary",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "SendEditableCode",
"command": {
"kernelName": "someKernelName",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "SendValue",
"command": {
"formattedValue": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "123",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"token": "the-token",
"id": "command-id",
"commandType": "UpdateDisplayedValue",
"command": {
"formattedValue": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"eventType": "CodeSubmissionReceived",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"eventType": "CommandFailed",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"eventType": "CommandSucceeded",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"eventType": "CompleteCodeSubmissionReceived",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"eventType": "CompletionsProduced",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "RequestCompletions",
"command": {
"code": "Console.Wri",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"eventType": "DiagnosticsProduced",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"eventType": "DisplayedValueProduced",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "b(\"hi!\")",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"eventType": "DisplayedValueUpdated",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "b(\"hi!\")",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"eventType": "ErrorProduced",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"eventType": "HoverTextProduced",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "RequestHoverText",
"command": {
"code": "document-contents",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"eventType": "IncompleteCodeSubmissionReceived",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"eventType": "InputProduced",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "RequestInput",
"command": {
"prompt": "What is the path to the log file?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"eventType": "KernelExtensionLoaded",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "SubmitCode",
"command": {
"code": "#r \"nuget:package\" ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"eventType": "KernelInfoProduced",
"command": {
"token": "the-token",
"id": "command-id",
"commandType": "RequestKernelInfo",
"command": {
"targetKernelName": null,
Expand Down
Loading

0 comments on commit f0979a5

Please sign in to comment.