From a2f237d174e147b8de9870e3c5945de9bd13a863 Mon Sep 17 00:00:00 2001 From: "Brett V. Forsgren" Date: Wed, 25 Nov 2020 15:43:32 -0800 Subject: [PATCH] implement interfaces directly in FSharpKernel --- dotnet-interactive.sln | 15 ----------- ...tNet.Interactive.ExtensionLab.Tests.csproj | 2 +- ...oft.DotNet.Interactive.FSharp.Tests.fsproj | 1 - .../FSharpKernel.cs | 26 ------------------- ...t.DotNet.Interactive.FSharp.Wrapper.csproj | 25 ------------------ .../FSharpKernel.fs | 21 +++++++-------- .../FSharpKernelExtensions.fs | 6 ++--- ...Microsoft.DotNet.Interactive.FSharp.fsproj | 3 --- .../JupyterRequestHandlerTestBase{T}.cs | 2 +- .../JupyterFormattingKernelExtensions.cs | 2 +- ...icrosoft.DotNet.Interactive.Jupyter.csproj | 1 - .../Microsoft.DotNet.Interactive.Tests.csproj | 1 - .../dotnet-interactive.Profiler.csproj | 1 - .../dotnet-interactive.csproj | 1 - 14 files changed, 16 insertions(+), 91 deletions(-) delete mode 100644 src/Microsoft.DotNet.Interactive.FSharp.Wrapper/FSharpKernel.cs delete mode 100644 src/Microsoft.DotNet.Interactive.FSharp.Wrapper/Microsoft.DotNet.Interactive.FSharp.Wrapper.csproj diff --git a/dotnet-interactive.sln b/dotnet-interactive.sln index 0e6d598f27..a97cbe969f 100644 --- a/dotnet-interactive.sln +++ b/dotnet-interactive.sln @@ -53,8 +53,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "integration-tests", "integr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "interface-generator", "src\interface-generator\interface-generator.csproj", "{9A091E80-D5EB-4DEF-8E38-B24B128393DF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactive.FSharp.Wrapper", "src\Microsoft.DotNet.Interactive.FSharp.Wrapper\Microsoft.DotNet.Interactive.FSharp.Wrapper.csproj", "{89672116-94E4-4F17-A64A-AA049410F595}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{4DD50BCA-133B-4594-8368-ED56939BAF6B}" ProjectSection(SolutionItems) = preProject docs\CreateBinder.md = docs\CreateBinder.md @@ -350,18 +348,6 @@ Global {9A091E80-D5EB-4DEF-8E38-B24B128393DF}.Release|x64.Build.0 = Release|Any CPU {9A091E80-D5EB-4DEF-8E38-B24B128393DF}.Release|x86.ActiveCfg = Release|Any CPU {9A091E80-D5EB-4DEF-8E38-B24B128393DF}.Release|x86.Build.0 = Release|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Debug|Any CPU.Build.0 = Debug|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Debug|x64.ActiveCfg = Debug|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Debug|x64.Build.0 = Debug|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Debug|x86.ActiveCfg = Debug|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Debug|x86.Build.0 = Debug|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Release|Any CPU.ActiveCfg = Release|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Release|Any CPU.Build.0 = Release|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Release|x64.ActiveCfg = Release|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Release|x64.Build.0 = Release|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Release|x86.ActiveCfg = Release|Any CPU - {89672116-94E4-4F17-A64A-AA049410F595}.Release|x86.Build.0 = Release|Any CPU {DE942DC3-B41B-45C5-9E01-3C4F042D3916}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DE942DC3-B41B-45C5-9E01-3C4F042D3916}.Debug|Any CPU.Build.0 = Debug|Any CPU {DE942DC3-B41B-45C5-9E01-3C4F042D3916}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -401,7 +387,6 @@ Global {30DE6920-EA82-4E4F-BFCA-1FF179FAA2DA} = {11BA3480-4584-435C-BA9A-8C554DB60E9F} {8017943B-B591-49C8-B957-40141B427AD9} = {979A5022-09CA-4258-B76D-CFDC31DA71E0} {9A091E80-D5EB-4DEF-8E38-B24B128393DF} = {B95A8485-8C53-4F56-B0CE-19C0726B5805} - {89672116-94E4-4F17-A64A-AA049410F595} = {B95A8485-8C53-4F56-B0CE-19C0726B5805} {DE942DC3-B41B-45C5-9E01-3C4F042D3916} = {B95A8485-8C53-4F56-B0CE-19C0726B5805} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/src/Microsoft.DotNet.Interactive.ExtensionLab.Tests/Microsoft.DotNet.Interactive.ExtensionLab.Tests.csproj b/src/Microsoft.DotNet.Interactive.ExtensionLab.Tests/Microsoft.DotNet.Interactive.ExtensionLab.Tests.csproj index bdd08cca41..22441afba0 100644 --- a/src/Microsoft.DotNet.Interactive.ExtensionLab.Tests/Microsoft.DotNet.Interactive.ExtensionLab.Tests.csproj +++ b/src/Microsoft.DotNet.Interactive.ExtensionLab.Tests/Microsoft.DotNet.Interactive.ExtensionLab.Tests.csproj @@ -23,9 +23,9 @@ - + diff --git a/src/Microsoft.DotNet.Interactive.FSharp.Tests/Microsoft.DotNet.Interactive.FSharp.Tests.fsproj b/src/Microsoft.DotNet.Interactive.FSharp.Tests/Microsoft.DotNet.Interactive.FSharp.Tests.fsproj index 1e066f2ee5..a7b4c7dfc8 100644 --- a/src/Microsoft.DotNet.Interactive.FSharp.Tests/Microsoft.DotNet.Interactive.FSharp.Tests.fsproj +++ b/src/Microsoft.DotNet.Interactive.FSharp.Tests/Microsoft.DotNet.Interactive.FSharp.Tests.fsproj @@ -25,7 +25,6 @@ - diff --git a/src/Microsoft.DotNet.Interactive.FSharp.Wrapper/FSharpKernel.cs b/src/Microsoft.DotNet.Interactive.FSharp.Wrapper/FSharpKernel.cs deleted file mode 100644 index 76a61206c9..0000000000 --- a/src/Microsoft.DotNet.Interactive.FSharp.Wrapper/FSharpKernel.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 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.Threading.Tasks; -using Microsoft.DotNet.Interactive.Commands; - -namespace Microsoft.DotNet.Interactive.FSharp -{ - // The purpose of this class is to enable interface implementation with different generic instantiations; can be removed - // once https://github.com/dotnet/fsharp/pull/2867 is complete. - public class FSharpKernel : - FSharpKernelBase, - IKernelCommandHandler, - IKernelCommandHandler, - IKernelCommandHandler, - IKernelCommandHandler - { - public Task HandleAsync(RequestCompletions command, KernelInvocationContext context) => HandleRequestCompletionAsync(command, context); - - public Task HandleAsync(RequestDiagnostics command, KernelInvocationContext context) => HandleRequestDiagnosticsAsync(command, context); - - public Task HandleAsync(SubmitCode command, KernelInvocationContext context) => HandleSubmitCodeAsync(command, context); - - public Task HandleAsync(RequestHoverText command, KernelInvocationContext context) => HandleRequestHoverText(command, context); - } -} diff --git a/src/Microsoft.DotNet.Interactive.FSharp.Wrapper/Microsoft.DotNet.Interactive.FSharp.Wrapper.csproj b/src/Microsoft.DotNet.Interactive.FSharp.Wrapper/Microsoft.DotNet.Interactive.FSharp.Wrapper.csproj deleted file mode 100644 index 48287a6b60..0000000000 --- a/src/Microsoft.DotNet.Interactive.FSharp.Wrapper/Microsoft.DotNet.Interactive.FSharp.Wrapper.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - netstandard2.1 - latest - $(NoWarn);2003;CS8002 - false - - - - true - Microsoft.DotNet.Interactive.FSharp - Microsoft.DotNet.Interactive.Kernel implementation for F# - interactive fsharp - - - - ;NU5104;2003;8002 - - - - - - - diff --git a/src/Microsoft.DotNet.Interactive.FSharp/FSharpKernel.fs b/src/Microsoft.DotNet.Interactive.FSharp/FSharpKernel.fs index e11ed1a72d..7b10d89d68 100644 --- a/src/Microsoft.DotNet.Interactive.FSharp/FSharpKernel.fs +++ b/src/Microsoft.DotNet.Interactive.FSharp/FSharpKernel.fs @@ -29,8 +29,7 @@ open FSharp.Compiler.Scripting open FSharp.Compiler.SourceCodeServices open FsAutoComplete -[] -type FSharpKernelBase () as this = +type FSharpKernel () as this = inherit DotNetKernel("fsharp") @@ -386,17 +385,17 @@ type FSharpKernelBase () as this = member _.PackageRestoreContext = _packageRestoreContext.Value - // ideally via IKernelCommandHandler, but requires https://github.com/dotnet/fsharp/pull/2867 - member _.HandleRequestCompletionAsync(command: RequestCompletions, context: KernelInvocationContext) = handleRequestCompletions command context |> Async.StartAsTask :> Task + interface IKernelCommandHandler with + member this.HandleAsync(command: RequestCompletions, context: KernelInvocationContext) = handleRequestCompletions command context |> Async.StartAsTask :> Task - // ideally via IKernelCommandHandler Async.StartAsTask :> Task - - // ideally via IKernelCommandHandler Async.StartAsTask :> Task + interface IKernelCommandHandler with + member this.HandleAsync(command: RequestDiagnostics, context: KernelInvocationContext) = handleRequestDiagnostics command context |> Async.StartAsTask :> Task - // ideally via IKernelCommandHandler Async.StartAsTask :> Task + interface IKernelCommandHandler with + member this.HandleAsync(command: RequestHoverText, context: KernelInvocationContext) = handleRequestHoverText command context |> Async.StartAsTask :> Task + + interface IKernelCommandHandler with + member this.HandleAsync(command: SubmitCode, context: KernelInvocationContext) = handleSubmitCode command context |> Async.StartAsTask :> Task interface ISupportNuget with member _.AddRestoreSource(source: string) = diff --git a/src/Microsoft.DotNet.Interactive.FSharp/FSharpKernelExtensions.fs b/src/Microsoft.DotNet.Interactive.FSharp/FSharpKernelExtensions.fs index 5532379e8d..af5cbf4d7f 100644 --- a/src/Microsoft.DotNet.Interactive.FSharp/FSharpKernelExtensions.fs +++ b/src/Microsoft.DotNet.Interactive.FSharp/FSharpKernelExtensions.fs @@ -16,7 +16,7 @@ type FSharpKernelExtensions private () = static let openNamespaceOrType (whatToOpen: string) = sprintf "open %s" whatToOpen [] - static member UseDefaultFormatting(kernel: FSharpKernelBase) = + static member UseDefaultFormatting(kernel: FSharpKernel) = let code = [ referenceFromType typeof @@ -35,12 +35,12 @@ type FSharpKernelExtensions private () = kernel [] - static member UseDefaultNamespaces(kernel: FSharpKernelBase) = + static member UseDefaultNamespaces(kernel: FSharpKernel) = // F# has its own views on what namespaces are open by default in its scripting model kernel [] - static member UseKernelHelpers(kernel: FSharpKernelBase) = + static member UseKernelHelpers(kernel: FSharpKernel) = let code = [ referenceFromType typeof diff --git a/src/Microsoft.DotNet.Interactive.FSharp/Microsoft.DotNet.Interactive.FSharp.fsproj b/src/Microsoft.DotNet.Interactive.FSharp/Microsoft.DotNet.Interactive.FSharp.fsproj index f3df62cdb1..535b551d0b 100644 --- a/src/Microsoft.DotNet.Interactive.FSharp/Microsoft.DotNet.Interactive.FSharp.fsproj +++ b/src/Microsoft.DotNet.Interactive.FSharp/Microsoft.DotNet.Interactive.FSharp.fsproj @@ -9,9 +9,6 @@ true - - Microsoft.DotNet.Interactive.FSharp.Internal - Microsoft.DotNet.Interactive.Kernel implementation for F# interactive fsharp diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterRequestHandlerTestBase{T}.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterRequestHandlerTestBase{T}.cs index 91a988f403..3da8889952 100644 --- a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterRequestHandlerTestBase{T}.cs +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterRequestHandlerTestBase{T}.cs @@ -16,7 +16,7 @@ public abstract class JupyterRequestHandlerTestBase : IDisposable { private readonly CompositeDisposable _disposables = new CompositeDisposable(); private readonly CSharpKernel _cSharpKernel; - private readonly FSharpKernelBase _fSharpKernel; + private readonly FSharpKernel _fSharpKernel; private readonly PowerShellKernel _psKernel; private readonly CompositeKernel _compositeKernel; diff --git a/src/Microsoft.DotNet.Interactive.Jupyter/JupyterFormattingKernelExtensions.cs b/src/Microsoft.DotNet.Interactive.Jupyter/JupyterFormattingKernelExtensions.cs index b0aa093cfc..2575c0caaa 100644 --- a/src/Microsoft.DotNet.Interactive.Jupyter/JupyterFormattingKernelExtensions.cs +++ b/src/Microsoft.DotNet.Interactive.Jupyter/JupyterFormattingKernelExtensions.cs @@ -27,7 +27,7 @@ public static CSharpKernel UseMathAndLaTeX(this CSharpKernel kernel) return kernel; } - public static FSharpKernelBase UseMathAndLaTeX(this FSharpKernelBase kernel) + public static FSharpKernel UseMathAndLaTeX(this FSharpKernel kernel) { if (kernel == null) { diff --git a/src/Microsoft.DotNet.Interactive.Jupyter/Microsoft.DotNet.Interactive.Jupyter.csproj b/src/Microsoft.DotNet.Interactive.Jupyter/Microsoft.DotNet.Interactive.Jupyter.csproj index aadb26dde0..78af2b4356 100644 --- a/src/Microsoft.DotNet.Interactive.Jupyter/Microsoft.DotNet.Interactive.Jupyter.csproj +++ b/src/Microsoft.DotNet.Interactive.Jupyter/Microsoft.DotNet.Interactive.Jupyter.csproj @@ -17,7 +17,6 @@ - diff --git a/src/Microsoft.DotNet.Interactive.Tests/Microsoft.DotNet.Interactive.Tests.csproj b/src/Microsoft.DotNet.Interactive.Tests/Microsoft.DotNet.Interactive.Tests.csproj index 33eb5d1277..19e0a512b2 100644 --- a/src/Microsoft.DotNet.Interactive.Tests/Microsoft.DotNet.Interactive.Tests.csproj +++ b/src/Microsoft.DotNet.Interactive.Tests/Microsoft.DotNet.Interactive.Tests.csproj @@ -40,7 +40,6 @@ - diff --git a/src/dotnet-interactive.Profiler/dotnet-interactive.Profiler.csproj b/src/dotnet-interactive.Profiler/dotnet-interactive.Profiler.csproj index 682eeff791..93d0d97b8b 100644 --- a/src/dotnet-interactive.Profiler/dotnet-interactive.Profiler.csproj +++ b/src/dotnet-interactive.Profiler/dotnet-interactive.Profiler.csproj @@ -14,7 +14,6 @@ - diff --git a/src/dotnet-interactive/dotnet-interactive.csproj b/src/dotnet-interactive/dotnet-interactive.csproj index 1539840b19..9c0f576e9d 100644 --- a/src/dotnet-interactive/dotnet-interactive.csproj +++ b/src/dotnet-interactive/dotnet-interactive.csproj @@ -72,7 +72,6 @@ -