Skip to content

Commit

Permalink
API renaming (dotnet#564)
Browse files Browse the repository at this point in the history
This addresses dotnet#512.
  • Loading branch information
jonsequitur authored Jun 23, 2020
1 parent affc1e6 commit b126716
Show file tree
Hide file tree
Showing 154 changed files with 1,184 additions and 1,375 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Package | Version
`Microsoft.dotnet-interactive` | [![Nuget](https://img.shields.io/nuget/v/Microsoft.dotnet-interactive.svg)](https://www.nuget.org/packages/Microsoft.dotnet-interactive) | The `dotnet-interactive` global tool
`Microsoft.DotNet.Interactive` | [![Nuget](https://img.shields.io/nuget/v/Microsoft.DotNet.Interactive.svg)](https://www.nuget.org/packages/Microsoft.DotNet.Interactive) | Core types for building applications providing interactive programming for .NET.
`Microsoft.DotNet.Interactive.Formatting` | [![Nuget](https://img.shields.io/nuget/v/Microsoft.DotNet.Interactive.Formatting.svg)](https://www.nuget.org/packages/Microsoft.DotNet.Interactive.Formatting) | Convention-based and highly configurable .NET object formatting for interactive programming, including support for mime types suitable for building visualizations for Jupyter Notebooks and web browsers.
`Microsoft.DotNet.Interactive.FSharp` | [![Nuget](https://img.shields.io/nuget/v/Microsoft.DotNet.Interactive.FSharp.svg)](https://www.nuget.org/packages/Microsoft.DotNet.Interactive.FSharp) | Microsoft.DotNet.Interactive.IKernel implementation for F#
`Microsoft.DotNet.Interactive.CSharp` | [![Nuget](https://img.shields.io/nuget/v/Microsoft.DotNet.Interactive.CSharp.svg)](https://www.nuget.org/packages/Microsoft.DotNet.Interactive.CSharp) | Microsoft.DotNet.Interactive.IKernel implementation for C#
`Microsoft.DotNet.Interactive.FSharp` | [![Nuget](https://img.shields.io/nuget/v/Microsoft.DotNet.Interactive.FSharp.svg)](https://www.nuget.org/packages/Microsoft.DotNet.Interactive.FSharp) | Microsoft.DotNet.Interactive.Kernel implementation for F#
`Microsoft.DotNet.Interactive.CSharp` | [![Nuget](https://img.shields.io/nuget/v/Microsoft.DotNet.Interactive.CSharp.svg)](https://www.nuget.org/packages/Microsoft.DotNet.Interactive.CSharp) | Microsoft.DotNet.Interactive.Kernel implementation for C#

## Contribution Guidelines

Expand Down
31 changes: 16 additions & 15 deletions docs/extending-dotnet-interactive.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The `IKernelExtension` interface is simple:
```csharp
public interface IKernelExtension
{
Task OnLoadAsync(IKernel kernel);
Task OnLoadAsync(Kernel kernel);
}
```

Expand All @@ -26,29 +26,30 @@ You can add to the set of magic commands available in your notebooks. Here's an
```csharp
public class ClockKernelExtension : IKernelExtension
{
public async Task OnLoadAsync(IKernel kernel)
public async Task OnLoadAsync(Kernel kernel)
{
// ...
if (kernel is KernelBase kernelBase)
var clockCommand = new Command("#!clock", "Displays a clock showing the current or specified time.")
{
var clockCommand = new Command("#!clock", "Displays a clock showing the current or specified time.")
{
new Option<int>(new[]{"-o","--hour"},
"The position of the hour hand"),
new Option<int>(new[]{"-m","--minute"},
"The position of the minute hand"),
new Option<int>(new[]{"-s","--second"},
"The position of the second hand")
};
new Option<int>(new[]{"-o","--hour"},
"The position of the hour hand"),
new Option<int>(new[]{"-m","--minute"},
"The position of the minute hand"),
new Option<int>(new[]{"-s","--second"},
"The position of the second hand")
};

//...
kernelBase.AddDirective(clockCommand);
}
kernel.AddDirective(clockCommand);

// ...
}
}
```

The first thing the code does is determine whether the `kernel` that was passed is of type `KernelBase`, which provides the `AddDirective` method. Once the `Command` has been added, it's available in the kernel and ready to be used.
Once the `Command` has been added using `Kernel.AddDirective`, it's available in the kernel and ready to be used.

The magic command syntax is a command line syntax. It's implemented using the `System.CommandLine` command line [library](https://nuget.org/packages/System.CommandLine). You can get help for a magic command in the same way you can typically get help from a command line tool. Here's the help for the `#!clock` magic command that the previous code produces:

Expand Down
10 changes: 5 additions & 5 deletions docs/kernels-overview.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# .NET Interactive Architectural Overview

The kernel concept in .NET Interactive is a component that accepts commands and produces outputs. The commands are typically blocks of arbitrary code, and the outputs are events that describe the results and effects of that code. The `IKernel` interface represents this core abstraction.
The kernel concept in .NET Interactive is a component that accepts commands and produces outputs. The commands are typically blocks of arbitrary code, and the outputs are events that describe the results and effects of that code. The `Kernel` class represents this core abstraction.

A kernel doesn't have to run in its own process. The default `dotnet-interactive` configuration runs several kernels in one process, enabling scenarios such as language-switching and .NET variable sharing. But one or more kernels can also run out-of-process, which will be transparent from the point of view of someone using it.

Expand All @@ -10,7 +10,7 @@ The `dotnet-interactive` tool also provides a number of protocols, including the

## Commands and events

All communication with a kernel takes place through a sequence of commands and events. The typical sequence starts with a command being sent to the kernel, which will reply with one or more events. The terminating event will always be either `CommandHandled` (if everything completed successfully) or `CommandFailed` (if there was a compilation error or runtime exception), but this will usually be preceded by one or more other events describing the results of the command.
All communication with a kernel takes place through a sequence of commands and events. The typical sequence starts with a command being sent to the kernel, which will reply with one or more events. The terminating event will always be either `CommandSucceeded` (if everything completed successfully) or `CommandFailed` (if there was a compilation error or runtime exception), but this will usually be preceded by one or more other events describing the results of the command.

The most common command is `SubmitCode`, which is used when a block of code is sent to the kernel for execution. A code submission is created each time you run a notebook cell. But a single submission may in fact generate multiple commands.

Expand All @@ -23,11 +23,11 @@ Console.WriteLine("Hi!");

This submission will actually be broken into two commands, a `SubmitCode` for the `Console.WriteLine` call as well as an internal `DirectiveCommand` for the `#!time` magic command.

When this splitting occurs, the API still only returns a single terminating `CommandHandled` or `CommandFailed` event. Programmtically, you don't need to be concerned with whether a submission is going be split, but understanding this mechanism can be helpful, for example when implementing your own middleware behaviors.
When this splitting occurs, the API still only returns a single terminating `CommandSucceeded` or `CommandFailed` event. Programmtically, you don't need to be concerned with whether a submission is going be split, but understanding this mechanism can be helpful, for example when implementing your own middleware behaviors.

You can see some additional examples of command and event interactions in the following diagram, illustrating different kinds of output as well as the behavior of a middleware component (for the `#!time` magic command) augmenting the behavior of a code submission by emitting an additional `DisplayedValueProduced` event.

![image](https://user-images.githubusercontent.com/547415/82275655-2703cc00-9938-11ea-8637-ab45c564f831.png)
![image](https://user-images.githubusercontent.com/547415/85328568-ce1eda80-b485-11ea-8d6e-a821dfe5db62.png)

## Nested Kernels

Expand All @@ -48,7 +48,7 @@ Even though this will initially be sent as a single `SubmitCode` command, it wil

The work of routing these commands is done by the `CompositeKernel` class, which wraps a number of subkernels. Here are some examples:

![image](https://user-images.githubusercontent.com/547415/82275667-2ec37080-9938-11ea-9950-e53de4406af3.png)
![image](https://user-images.githubusercontent.com/547415/85328679-ff97a600-b485-11ea-839c-ebc65b0f6472.png)

Note that while the composite configuration is the defaut when using the `dotnet-interactive` tool via Visual Studio Code or Jupyter, the .NET Interactive [NuGet packages](../README.md#Packages) let you create other configurations. For example, you might provide a single-language embedded scripting experience using the C# kernel by itself, or you might provide multiple F# kernels each preconfigured to run code on a different processor.

Expand Down
4 changes: 2 additions & 2 deletions samples/extensions/ClockExtension/ClockExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.20111.6" />
<PackageReference Include="microsoft.dotnet.interactive.formatting" Version="1.0.0-beta.20111.6" />
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.20322.2" />
<PackageReference Include="microsoft.dotnet.interactive.formatting" Version="1.0.0-beta.20322.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace SampleExtensions.Tests
{
public class ClockExtensionTests : IDisposable
{
private readonly IKernel _kernel;
private readonly KernelBase _kernel;

public ClockExtensionTests()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\..\Microsoft.DotNet.Interactive.Tests\TestUtility.cs" Link="TestUtility.cs" />
<Compile Include="..\..\..\src\Microsoft.DotNet.Interactive.Tests\Utility\TestUtility.cs" Link="TestUtility.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="microsoft.dotnet.interactive.csharp" Version="1.0.0-beta.20111.6" />
<PackageReference Include="microsoft.dotnet.interactive.fsharp" Version="1.0.0-beta.20111.6" />
<PackageReference Include="microsoft.dotnet.interactive.csharp" Version="1.0.0-beta.20322.2" />
<PackageReference Include="microsoft.dotnet.interactive.fsharp" Version="1.0.0-beta.20322.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SubmissionParsingTests
[Fact]
public async Task pound_r_is_split_into_separate_command_from_csharp_code()
{
var receivedCommands = new List<IKernelCommand>();
var receivedCommands = new List<KernelCommand>();

using var kernel = new CSharpKernel();

Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.DotNet.Interactive.CSharp/CSharpKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CSharpKernel :
DotNetLanguageKernel,
IExtensibleKernel,
ISupportNuget,
IKernelCommandHandler<RequestCompletion>,
IKernelCommandHandler<RequestCompletions>,
IKernelCommandHandler<RequestHoverText>,
IKernelCommandHandler<SubmitCode>
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public class CSharpKernel :
typeof(Enumerable).Assembly,
typeof(IEnumerable<>).Assembly,
typeof(Task<>).Assembly,
typeof(IKernel).Assembly,
typeof(Kernel).Assembly,
typeof(CSharpKernel).Assembly,
typeof(PocketView).Assembly,
typeof(PlotlyChart).Assembly);
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task HandleAsync(RequestHoverText command, KernelInvocationContext
{
var document = _workspace.ForkDocument(command.Code);
var text = await document.GetTextAsync();
var cursorPosition = text.Lines.GetPosition(command.Position);
var cursorPosition = text.Lines.GetPosition(command.LinePosition);
var service = QuickInfoService.GetService(document);
var info = await service.GetQuickInfoAsync(document, cursorPosition);

Expand Down Expand Up @@ -268,7 +268,7 @@ private async Task RunAsync(
}

public async Task HandleAsync(
RequestCompletion command,
RequestCompletions command,
KernelInvocationContext context)
{
var completionRequestReceived = new CompletionRequestReceived(command);
Expand All @@ -278,9 +278,9 @@ public async Task HandleAsync(
var completionList =
await GetCompletionList(
command.Code,
SourceUtilities.GetCursorOffsetFromPosition(command.Code, command.Position));
SourceUtilities.GetCursorOffsetFromPosition(command.Code, command.LinePosition));

context.Publish(new CompletionRequestCompleted(completionList, command));
context.Publish(new CompletionsProduced(completionList, command));
}

private async Task<IEnumerable<CompletionItem>> GetCompletionList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageDescription>Microsoft.DotNet.Interactive.IKernel implementation for C#</PackageDescription>
<PackageDescription>Microsoft.DotNet.Interactive.Kernel implementation for C#</PackageDescription>
<PackageTags>interactive csharp</PackageTags>
</PropertyGroup>

Expand Down
25 changes: 11 additions & 14 deletions src/Microsoft.DotNet.Interactive.ExtensionLab/DownloadExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,21 @@ namespace Microsoft.DotNet.Interactive.ExtensionLab
{
public class DownloadExtension : IKernelExtension
{
public Task OnLoadAsync(IKernel kernel)
public Task OnLoadAsync(Kernel kernel)
{
if (kernel is KernelBase kernelBase)
var download = new Command("#!download")
{
var download = new Command("#!download")
{
new Option<Uri>("--uri"),
new Option<FileInfo>(
new [] {"-o", "--output"},
parseArgument: ParsePath,
isDefault: true)
};
new Option<Uri>("--uri"),
new Option<FileInfo>(
new[] { "-o", "--output" },
parseArgument: ParsePath,
isDefault: true)
};

download.Handler = CommandHandler.Create(
(Uri uri, FileInfo output, KernelInvocationContext context) => Download(uri, output, context));
download.Handler = CommandHandler.Create(
(Uri uri, FileInfo output, KernelInvocationContext context) => Download(uri, output, context));

kernelBase.AddDirective(download);
}
kernel.AddDirective(download);

return Task.CompletedTask;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Microsoft.DotNet.Interactive.ExtensionLab
{
public class RecordTranscriptExtension : IKernelExtension
{
public Task OnLoadAsync(IKernel kernel)
public Task OnLoadAsync(Kernel kernel)
{
if (kernel is CompositeKernel kernelBase)
if (kernel is CompositeKernel compositeKernel)
{
var record = new Command(
"#!record",
Expand All @@ -25,7 +25,7 @@ public Task OnLoadAsync(IKernel kernel)

record.Handler = CommandHandler.Create<FileInfo>(output =>
{
kernelBase.AddMiddleware(async (command, context, next) =>
compositeKernel.AddMiddleware(async (command, context, next) =>
{
var json = KernelCommandEnvelope.Serialize(command);

Expand All @@ -42,7 +42,7 @@ await File.AppendAllLinesAsync(
return Task.CompletedTask;
});

kernelBase.AddDirective(record);
compositeKernel.AddDirective(record);
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Microsoft.DotNet.Interactive.FSharp
// once https://github.com/dotnet/fsharp/pull/2867 is complete.
public class FSharpKernel :
FSharpKernelBase,
IKernelCommandHandler<RequestCompletion>,
IKernelCommandHandler<RequestCompletions>,
IKernelCommandHandler<SubmitCode>
{
public Task HandleAsync(RequestCompletion command, KernelInvocationContext context) => HandleRequestCompletionAsync(command, context);
public Task HandleAsync(RequestCompletions command, KernelInvocationContext context) => HandleRequestCompletionAsync(command, context);

public Task HandleAsync(SubmitCode command, KernelInvocationContext context) => HandleSubmitCodeAsync(command, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Microsoft.DotNet.Interactive.FSharp</PackageId>
<PackageDescription>Microsoft.DotNet.Interactive.IKernel implementation for F#</PackageDescription>
<PackageDescription>Microsoft.DotNet.Interactive.Kernel implementation for F#</PackageDescription>
<PackageTags>interactive fsharp</PackageTags>
</PropertyGroup>

Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.DotNet.Interactive.FSharp/FSharpKernel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ type FSharpKernelBase () as this =
context.Fail(null, "Command cancelled")
}

let handleRequestCompletion (requestCompletion: RequestCompletion) (context: KernelInvocationContext) =
let handleRequestCompletions (requestCompletions: RequestCompletions) (context: KernelInvocationContext) =
async {
context.Publish(CompletionRequestReceived(requestCompletion))
let! declarationItems = script.Value.GetCompletionItems(requestCompletion.Code, requestCompletion.Position.Line + 1, requestCompletion.Position.Character)
context.Publish(CompletionRequestReceived(requestCompletions))
let! declarationItems = script.Value.GetCompletionItems(requestCompletions.Code, requestCompletions.LinePosition.Line + 1, requestCompletions.LinePosition.Character)
let completionItems =
declarationItems
|> Array.map completionItem
context.Publish(CompletionRequestCompleted(completionItems, requestCompletion))
context.Publish(CompletionsProduced(completionItems, requestCompletions))
}

let createPackageRestoreContext registerForDisposal =
Expand Down Expand Up @@ -155,7 +155,7 @@ type FSharpKernelBase () as this =
member _.PackageRestoreContext = _packageRestoreContext.Value

// ideally via IKernelCommandHandler<RequestCompletion>, but requires https://github.com/dotnet/fsharp/pull/2867
member _.HandleRequestCompletionAsync(command: RequestCompletion, context: KernelInvocationContext) = handleRequestCompletion command context |> Async.StartAsTask :> Task
member _.HandleRequestCompletionAsync(command: RequestCompletions, context: KernelInvocationContext) = handleRequestCompletions command context |> Async.StartAsTask :> Task

// ideally via IKernelCommandHandler<SubmitCode, but requires https://github.com/dotnet/fsharp/pull/2867
member _.HandleSubmitCodeAsync(command: SubmitCode, context: KernelInvocationContext) = handleSubmitCode command context |> Async.StartAsTask :> Task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type FSharpKernelExtensions private () =
let code =
[
referenceFromType typeof<IHtmlContent>
referenceFromType typeof<IKernel>
referenceFromType typeof<Kernel>
referenceFromType typeof<FSharpPocketViewTags>
referenceFromType typeof<PlotlyChart>
referenceFromType typeof<Formatter>
Expand Down
Loading

0 comments on commit b126716

Please sign in to comment.