forked from dotnet/interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSharpKernelExtensions.fs
More file actions
55 lines (43 loc) · 2.2 KB
/
Copy pathFSharpKernelExtensions.fs
File metadata and controls
55 lines (43 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 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.
namespace Microsoft.DotNet.Interactive.FSharp
open System
open System.Runtime.CompilerServices
open Microsoft.AspNetCore.Html
open Microsoft.DotNet.Interactive
open Microsoft.DotNet.Interactive.Commands
open Microsoft.DotNet.Interactive.FSharp
open Microsoft.DotNet.Interactive.Formatting
[<AbstractClass; Extension; Sealed>]
type FSharpKernelExtensions private () =
static let referenceAssemblyContaining (typ: Type) = sprintf "#r \"%s\"" (typ.Assembly.Location.Replace("\\", "/"))
static let openNamespaceContaining (typ: Type) = sprintf "open %s" typ.Namespace
static let openType (typ: Type) = sprintf "open type %s.%s" typ.Namespace typ.Name
[<Extension>]
static member UseDefaultFormatting(kernel: FSharpKernel) =
let code =
[
referenceAssemblyContaining typeof<IHtmlContent>
referenceAssemblyContaining typeof<Kernel>
referenceAssemblyContaining typeof<FSharpKernelHelpers.IMarker>
referenceAssemblyContaining typeof<Formatter>
openNamespaceContaining typeof<System.Console>
openNamespaceContaining typeof<System.IO.File>
openNamespaceContaining typeof<System.Text.StringBuilder>
openNamespaceContaining typeof<Formatter>
] |> String.concat Environment.NewLine
kernel.DeferCommand(SubmitCode code)
kernel
[<Extension>]
static member UseKernelHelpers(kernel: FSharpKernel) =
let code =
[
referenceAssemblyContaining typeof<FSharpKernelHelpers.IMarker>
// opens Microsoft.DotNet.Interactive.FSharp.FSharpKernelHelpers
// note this has some AutoOpen content inside
openNamespaceContaining typeof<FSharpKernelHelpers.IMarker>
referenceAssemblyContaining typeof<Kernel>
openType typeof<Kernel>
] |> String.concat Environment.NewLine
kernel.DeferCommand(SubmitCode code)
kernel