diff --git a/src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.Document_api_is_not_changed.approved.txt b/src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.Document_api_is_not_changed.approved.txt index de12a67632..13c46ba792 100644 --- a/src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.Document_api_is_not_changed.approved.txt +++ b/src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.Document_api_is_not_changed.approved.txt @@ -98,49 +98,3 @@ Microsoft.DotNet.Interactive.Documents.Jupyter public static System.Void Write(Microsoft.DotNet.Interactive.Documents.InteractiveDocument document, System.IO.Stream stream, Microsoft.DotNet.Interactive.Documents.KernelInfoCollection kernelInfos) public static System.Void Write(Microsoft.DotNet.Interactive.Documents.InteractiveDocument document, System.IO.TextWriter writer) public static System.Void Write(Microsoft.DotNet.Interactive.Documents.InteractiveDocument document, System.IO.TextWriter writer, Microsoft.DotNet.Interactive.Documents.KernelInfoCollection kernelInfos) -Microsoft.DotNet.Interactive.Documents.ParserServer - public enum DocumentSerializationType : System.Enum, System.IComparable, System.IConvertible, System.IFormattable - Dib=0 - Ipynb=1 - public class NotebookErrorResponse : NotebookParserServerResponse - .ctor(System.String id, System.String errorMessage) - public System.String ErrorMessage { get;} - public abstract class NotebookParseOrSerializeRequest - public static NotebookParseOrSerializeRequest FromJson(System.String json) - public System.String DefaultLanguage { get;} - public System.String Id { get;} - public DocumentSerializationType SerializationType { get;} - public RequestType Type { get;} - public class NotebookParseRequest : NotebookParseOrSerializeRequest - .ctor(System.String id, DocumentSerializationType serializationType, System.String defaultLanguage, System.Byte[] rawData) - public System.Byte[] RawData { get;} - public RequestType Type { get;} - public class NotebookParseResponse : NotebookParserServerResponse - .ctor(System.String id, Microsoft.DotNet.Interactive.Documents.InteractiveDocument document) - public Microsoft.DotNet.Interactive.Documents.InteractiveDocument Document { get;} - public class NotebookParserServer, System.IDisposable - public static NotebookParserServerResponse HandleRequest(NotebookParseOrSerializeRequest request) - .ctor(System.IO.TextReader input, System.IO.TextWriter output) - public System.IO.TextReader Input { get;} - public System.IO.TextWriter Output { get;} - public System.Void Dispose() - public System.Threading.Tasks.Task RunAsync() - public static class NotebookParserServerExtensions - public static System.String ToJson() - public static System.String ToJson() - public abstract class NotebookParserServerResponse - public static NotebookParserServerResponse FromJson(System.String json) - public System.String Id { get;} - public class NotebookSerializeRequest : NotebookParseOrSerializeRequest - .ctor(System.String id, DocumentSerializationType serializationType, System.String defaultLanguage, System.String newLine, Microsoft.DotNet.Interactive.Documents.InteractiveDocument document) - public Microsoft.DotNet.Interactive.Documents.InteractiveDocument Document { get;} - public System.String NewLine { get;} - public RequestType Type { get;} - public class NotebookSerializeResponse : NotebookParserServerResponse - .ctor(System.String id, System.Byte[] rawData) - public System.Byte[] RawData { get;} - public static class ParserServerSerializer - public static System.Text.Json.JsonSerializerOptions JsonSerializerOptions { get;} - public enum RequestType : System.Enum, System.IComparable, System.IConvertible, System.IFormattable - Parse=0 - Serialize=1 diff --git a/src/Microsoft.DotNet.Interactive.Documents.Tests/CodeSubmissionFormatTests.cs b/src/Microsoft.DotNet.Interactive.Documents.Tests/CodeSubmissionFormatTests.cs index 5aff3c8b91..3a26aa38ea 100644 --- a/src/Microsoft.DotNet.Interactive.Documents.Tests/CodeSubmissionFormatTests.cs +++ b/src/Microsoft.DotNet.Interactive.Documents.Tests/CodeSubmissionFormatTests.cs @@ -536,12 +536,12 @@ public async Task dib_file_can_be_round_tripped_through_read_and_write_without_t private static string GetDibContent(Dictionary metadata) { - if (metadata == null) + if (metadata is null) { throw new ArgumentNullException(nameof(metadata)); } - var serializedMetadata = JsonSerializer.Serialize(metadata, ParserServer.ParserServerSerializer.JsonSerializerOptions); + var serializedMetadata = JsonSerializer.Serialize(metadata, App.ParserServer.ParserServerSerializer.JsonSerializerOptions); return $@"#!meta diff --git a/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_ObjectInterface.cs b/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_ObjectInterface.cs index 254f2e002d..1022c097dd 100644 --- a/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_ObjectInterface.cs +++ b/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_ObjectInterface.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using FluentAssertions; -using Microsoft.DotNet.Interactive.Documents.ParserServer; +using Microsoft.DotNet.Interactive.App.ParserServer; using Newtonsoft.Json; using Xunit; diff --git a/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_Serialization.NotebookErrorResponse_serialization_contract.approved.json b/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_Serialization.NotebookErrorResponse_serialization_contract.approved.json deleted file mode 100644 index 511e13fd2e..0000000000 --- a/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_Serialization.NotebookErrorResponse_serialization_contract.approved.json +++ /dev/null @@ -1 +0,0 @@ -{"errorMessage":"some error message","id":"the-id"} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_Serialization.cs b/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_Serialization.cs index fb602ee51b..1e89b2a076 100644 --- a/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_Serialization.cs +++ b/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_Serialization.cs @@ -8,7 +8,7 @@ using Assent; using FluentAssertions; using FluentAssertions.Execution; -using Microsoft.DotNet.Interactive.Documents.ParserServer; +using Microsoft.DotNet.Interactive.App.ParserServer; using Xunit; namespace Microsoft.DotNet.Interactive.Documents.Tests; @@ -77,16 +77,6 @@ public void NotebookSerializeResponse_serialization_contract() this.Assent(json, _configuration); } - [Fact] - public void NotebookErrorResponse_serialization_contract() - { - var response = new NotebookErrorResponse("the-id", "some error message"); - - var json = response.ToJson(); - - this.Assent(json, _configuration); - } - private string GetTestFileContents(string extension = "json", [CallerFilePath] string thisFilePath = null, [CallerMemberName] string testName = null) { var fileName = $"{GetType().Name}.{testName}.approved.{extension}"; diff --git a/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_TextInterface.cs b/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_TextInterface.cs index 2266f800eb..f1e790b75f 100644 --- a/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_TextInterface.cs +++ b/src/Microsoft.DotNet.Interactive.Documents.Tests/NotebookParserServerTests_TextInterface.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; using FluentAssertions; -using Microsoft.DotNet.Interactive.Documents.ParserServer; +using Microsoft.DotNet.Interactive.App.ParserServer; using Nerdbank.Streams; using Pocket; using Xunit; diff --git a/src/Microsoft.DotNet.Interactive.Documents/CodeSubmission.cs b/src/Microsoft.DotNet.Interactive.Documents/CodeSubmission.cs index c48fe7cede..fec7105cce 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/CodeSubmission.cs +++ b/src/Microsoft.DotNet.Interactive.Documents/CodeSubmission.cs @@ -8,7 +8,6 @@ using System.Text; using System.Text.Json; using System.Threading.Tasks; -using Microsoft.DotNet.Interactive.Documents.ParserServer; using Microsoft.DotNet.Interactive.Documents.Utility; using Microsoft.DotNet.Interactive.Utility; @@ -53,7 +52,7 @@ public static InteractiveDocument Parse( var metadataString = sb.ToString(); - metadata = JsonSerializer.Deserialize>(metadataString, ParserServerSerializer.JsonSerializerOptions); + metadata = JsonSerializer.Deserialize>(metadataString, InteractiveDocument.JsonSerializerOptions); if (InteractiveDocument.TryGetKernelInfoFromMetadata(metadata, out var kernelInfoFromMetadata)) { @@ -170,7 +169,7 @@ public static string ToCodeSubmissionContent( { lines.Add($"{MagicCommandPrefix}meta"); lines.Add(""); - lines.Add(JsonSerializer.Serialize(document.Metadata, ParserServerSerializer.JsonSerializerOptions)); + lines.Add(JsonSerializer.Serialize(document.Metadata, InteractiveDocument.JsonSerializerOptions)); lines.Add(""); } @@ -226,4 +225,4 @@ public static void Write(InteractiveDocument document, TextWriter writer, Kernel InteractiveDocument.MergeKernelInfos(document, kernelInfos); Write(document, writer, newline); } -} \ No newline at end of file +} diff --git a/src/Microsoft.DotNet.Interactive.Documents/InteractiveDocument.cs b/src/Microsoft.DotNet.Interactive.Documents/InteractiveDocument.cs index 826e2a67a9..881cae9479 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/InteractiveDocument.cs +++ b/src/Microsoft.DotNet.Interactive.Documents/InteractiveDocument.cs @@ -10,10 +10,12 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; +using System.Text.Encodings.Web; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; +using Microsoft.DotNet.Interactive.Documents.Json; using Microsoft.DotNet.Interactive.Documents.Jupyter; -using Microsoft.DotNet.Interactive.Documents.ParserServer; using Microsoft.DotNet.Interactive.Documents.Utility; using Microsoft.DotNet.Interactive.Utility; @@ -21,6 +23,24 @@ namespace Microsoft.DotNet.Interactive.Documents; public class InteractiveDocument : IEnumerable { + static InteractiveDocument() + { + JsonSerializerOptions = new JsonSerializerOptions + { + WriteIndented = false, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.AllowNamedFloatingPointLiterals, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + Converters = + { + new ByteArrayConverter(), + new DataDictionaryConverter(), + new JsonStringEnumConverter(JsonNamingPolicy.CamelCase), + new InteractiveDocumentConverter(), + } + }; + } + private static Parser? _importFieldsParser; private static Argument? _importedFileArgument; @@ -254,7 +274,7 @@ internal static bool TryGetKernelInfoFromMetadata( if (metadata.TryGetValue("kernelInfo", out var kernelInfoObj) ) { if (kernelInfoObj is JsonElement kernelInfoJson && - kernelInfoJson.Deserialize(ParserServerSerializer.JsonSerializerOptions) is + JsonSerializer.Deserialize(kernelInfoJson, JsonSerializerOptions) is { } kernelInfoDeserialized) { kernelInfo = kernelInfoDeserialized; @@ -262,7 +282,7 @@ internal static bool TryGetKernelInfoFromMetadata( } // todo: the kernelInfo should not deserialize as a dictionary - if (kernelInfoObj is Dictionary kernelInfoAsDictionary) + if (kernelInfoObj is Dictionary kernelInfoAsDictionary) { var deserializedKernelInfo = new KernelInfoCollection(); if (kernelInfoAsDictionary.TryGetValue("defaultKernelName", out var defaultKernelNameObj) && @@ -272,11 +292,11 @@ internal static bool TryGetKernelInfoFromMetadata( } if (kernelInfoAsDictionary.TryGetValue("items", - out var items)) + out var items)) { if (items is IEnumerable itemList) { - foreach (var item in itemList.Cast>()) + foreach (var item in itemList.Cast>()) { if (item.TryGetValue("name", out var nameObj) && nameObj is string name) @@ -437,4 +457,5 @@ private static void EnsureInputFieldParserIsInitialized() .Build(); } + internal static JsonSerializerOptions JsonSerializerOptions { get; } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Documents/JsonReaderExtensions.cs b/src/Microsoft.DotNet.Interactive.Documents/JsonReaderExtensions.cs index 7a9177df25..7563213d85 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/JsonReaderExtensions.cs +++ b/src/Microsoft.DotNet.Interactive.Documents/JsonReaderExtensions.cs @@ -1,6 +1,8 @@ // 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. +#nullable enable +using System; using System.Collections.Generic; using System.Text.Json; @@ -54,7 +56,8 @@ internal static class JsonReaderExtensions { case JsonTokenType.StartArray: var lines = JsonSerializer.Deserialize(ref reader); - return string.Join("", lines); + + return string.Join("", lines ?? Array.Empty()); case JsonTokenType.String: return reader.GetString(); diff --git a/src/Microsoft.DotNet.Interactive.Documents/KernelInfo.cs b/src/Microsoft.DotNet.Interactive.Documents/KernelInfo.cs index 27fb48a2ce..39bca4c294 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/KernelInfo.cs +++ b/src/Microsoft.DotNet.Interactive.Documents/KernelInfo.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Text.Json.Serialization; -using Microsoft.DotNet.Interactive.Documents.ParserServer; namespace Microsoft.DotNet.Interactive.Documents; diff --git a/src/Microsoft.DotNet.Interactive.Documents/KernelInfoCollection.cs b/src/Microsoft.DotNet.Interactive.Documents/KernelInfoCollection.cs index 96659e77fc..212e1dafd3 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/KernelInfoCollection.cs +++ b/src/Microsoft.DotNet.Interactive.Documents/KernelInfoCollection.cs @@ -1,117 +1,116 @@ -// 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.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json.Serialization; -using Microsoft.DotNet.Interactive.Documents.ParserServer; - -namespace Microsoft.DotNet.Interactive.Documents; - -[JsonConverter(typeof(KernelInfoCollectionConverter))] -public class KernelInfoCollection : ICollection -{ - private readonly HashSet _kernelNames = new(); - private readonly Dictionary _kernelInfoByNameOrAlias = new(); - private string? _defaultKernelName; - - public int Count => _kernelNames.Count; - - public bool IsReadOnly => false; - - public string? DefaultKernelName - { - get => _defaultKernelName ?? (_kernelNames.Count == 1 - ? _kernelNames.Single().Name - : null); - set => _defaultKernelName = value; - } - - public void Add(KernelInfo kernelInfo) - { - foreach (var alias in kernelInfo.Aliases.Append(kernelInfo.Name)) - { +// 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.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json.Serialization; + +namespace Microsoft.DotNet.Interactive.Documents; + +[JsonConverter(typeof(KernelInfoCollectionConverter))] +public class KernelInfoCollection : ICollection +{ + private readonly HashSet _kernelNames = new(); + private readonly Dictionary _kernelInfoByNameOrAlias = new(); + private string? _defaultKernelName; + + public int Count => _kernelNames.Count; + + public bool IsReadOnly => false; + + public string? DefaultKernelName + { + get => _defaultKernelName ?? (_kernelNames.Count == 1 + ? _kernelNames.Single().Name + : null); + set => _defaultKernelName = value; + } + + public void Add(KernelInfo kernelInfo) + { + foreach (var alias in kernelInfo.Aliases.Append(kernelInfo.Name)) + { try { _kernelInfoByNameOrAlias.Add(alias, kernelInfo); - } - catch (ArgumentException argumentException) + } + catch (ArgumentException argumentException) { throw new ArgumentException($"A {nameof(KernelInfo)} with name or alias '{alias}' is already present in the collection.", argumentException); - } - } - - _kernelNames.Add(kernelInfo); - } - - public void AddRange(IEnumerable collection) - { - foreach (var info in collection) - { - Add(info); - } - } - - public void Clear() - { - _kernelNames.Clear(); - _kernelInfoByNameOrAlias.Clear(); - } - - public bool Remove(KernelInfo item) - { - var removed = _kernelNames.Remove(item); - - if (removed) - { - foreach (var alias in item.Aliases.Append(item.Name)) - { - _kernelInfoByNameOrAlias.Remove(alias); - } - } - - return removed; - } - - public bool Contains(KernelInfo kernelInfo) - { - return _kernelNames.Contains(kernelInfo); - } - - public void CopyTo(KernelInfo[] array, int arrayIndex) - { - _kernelNames.CopyTo(array, arrayIndex); - } - - public bool Contains(string nameOrAlias) - { - return _kernelInfoByNameOrAlias!.ContainsKey(nameOrAlias); - } - - public KernelInfoCollection Clone() - { - var clone = new KernelInfoCollection - { - _defaultKernelName = _defaultKernelName - }; - clone.AddRange(this); - return clone; - } - - public bool TryGetByAlias(string alias, out KernelInfo info) - { - return _kernelInfoByNameOrAlias!.TryGetValue(alias, out info); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return _kernelNames.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return _kernelNames.GetEnumerator(); - } -} + } + } + + _kernelNames.Add(kernelInfo); + } + + public void AddRange(IEnumerable collection) + { + foreach (var info in collection) + { + Add(info); + } + } + + public void Clear() + { + _kernelNames.Clear(); + _kernelInfoByNameOrAlias.Clear(); + } + + public bool Remove(KernelInfo item) + { + var removed = _kernelNames.Remove(item); + + if (removed) + { + foreach (var alias in item.Aliases.Append(item.Name)) + { + _kernelInfoByNameOrAlias.Remove(alias); + } + } + + return removed; + } + + public bool Contains(KernelInfo kernelInfo) + { + return _kernelNames.Contains(kernelInfo); + } + + public void CopyTo(KernelInfo[] array, int arrayIndex) + { + _kernelNames.CopyTo(array, arrayIndex); + } + + public bool Contains(string nameOrAlias) + { + return _kernelInfoByNameOrAlias!.ContainsKey(nameOrAlias); + } + + public KernelInfoCollection Clone() + { + var clone = new KernelInfoCollection + { + _defaultKernelName = _defaultKernelName + }; + clone.AddRange(this); + return clone; + } + + public bool TryGetByAlias(string alias, out KernelInfo info) + { + return _kernelInfoByNameOrAlias!.TryGetValue(alias, out info); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return _kernelNames.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return _kernelNames.GetEnumerator(); + } +} diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/KernelInfoCollectionConverter.cs b/src/Microsoft.DotNet.Interactive.Documents/KernelInfoCollectionConverter.cs similarity index 97% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/KernelInfoCollectionConverter.cs rename to src/Microsoft.DotNet.Interactive.Documents/KernelInfoCollectionConverter.cs index 55e71f5100..58880c288d 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/KernelInfoCollectionConverter.cs +++ b/src/Microsoft.DotNet.Interactive.Documents/KernelInfoCollectionConverter.cs @@ -4,7 +4,7 @@ using System; using System.Text.Json; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.Documents; internal class KernelInfoCollectionConverter : JsonConverter { diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/KernelInfoConverter.cs b/src/Microsoft.DotNet.Interactive.Documents/KernelInfoConverter.cs similarity index 96% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/KernelInfoConverter.cs rename to src/Microsoft.DotNet.Interactive.Documents/KernelInfoConverter.cs index a5d31c0a72..a4a78858f7 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/KernelInfoConverter.cs +++ b/src/Microsoft.DotNet.Interactive.Documents/KernelInfoConverter.cs @@ -4,7 +4,7 @@ using System; using System.Text.Json; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.Documents; internal class KernelInfoConverter : JsonConverter { @@ -56,10 +56,10 @@ public override void Write(Utf8JsonWriter writer, KernelInfo value, JsonSerializ writer.WritePropertyName("name"); writer.WriteStringValue(value.Name); - if (value.LanguageName is { }) - { - writer.WritePropertyName("languageName"); - writer.WriteStringValue(value.LanguageName); + if (value.LanguageName is { }) + { + writer.WritePropertyName("languageName"); + writer.WriteStringValue(value.LanguageName); } if (value.Aliases.Count > 0) @@ -77,4 +77,4 @@ public override void Write(Utf8JsonWriter writer, KernelInfo value, JsonSerializ writer.WriteEndObject(); } -} +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Documents/Microsoft.DotNet.Interactive.Documents.csproj b/src/Microsoft.DotNet.Interactive.Documents/Microsoft.DotNet.Interactive.Documents.csproj index a28ef18ebb..05462b3846 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/Microsoft.DotNet.Interactive.Documents.csproj +++ b/src/Microsoft.DotNet.Interactive.Documents/Microsoft.DotNet.Interactive.Documents.csproj @@ -27,9 +27,6 @@ - - all - diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookErrorResponse.cs b/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookErrorResponse.cs deleted file mode 100644 index 90c5924717..0000000000 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookErrorResponse.cs +++ /dev/null @@ -1,17 +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; - -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; - -public class NotebookErrorResponse : NotebookParserServerResponse -{ - public NotebookErrorResponse(string id, string errorMessage) - : base(id) - { - ErrorMessage = errorMessage ?? throw new ArgumentNullException(nameof(errorMessage)); - } - - public string ErrorMessage { get; } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive/Utility/StringExtensions.cs b/src/Microsoft.DotNet.Interactive/Utility/StringExtensions.cs index b03169f827..c360c57329 100644 --- a/src/Microsoft.DotNet.Interactive/Utility/StringExtensions.cs +++ b/src/Microsoft.DotNet.Interactive/Utility/StringExtensions.cs @@ -33,7 +33,7 @@ public static string TruncateForDisplay( } else if (lines.Length > 1) { - firstLine = firstLine + " ..."; + // firstLine = firstLine + " ..."; } return firstLine; diff --git a/src/Microsoft.DotNet.Interactive/Utility/TaskExtensions.cs b/src/Microsoft.DotNet.Interactive/Utility/TaskExtensions.cs deleted file mode 100644 index 18d368e253..0000000000 --- a/src/Microsoft.DotNet.Interactive/Utility/TaskExtensions.cs +++ /dev/null @@ -1,12 +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; - -namespace Microsoft.DotNet.Interactive.Utility; - -internal static class TaskExtensions -{ - internal static void WaitAndUnwrapException(this Task task) => - task?.GetAwaiter().GetResult(); -} \ No newline at end of file diff --git a/src/dotnet-interactive/CommandLine/CommandLineParser.cs b/src/dotnet-interactive/CommandLine/CommandLineParser.cs index 852b3c49bc..ff11918090 100644 --- a/src/dotnet-interactive/CommandLine/CommandLineParser.cs +++ b/src/dotnet-interactive/CommandLine/CommandLineParser.cs @@ -16,9 +16,9 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Html; using Microsoft.DotNet.Interactive.App.Connection; +using Microsoft.DotNet.Interactive.App.ParserServer; using Microsoft.DotNet.Interactive.Connection; using Microsoft.DotNet.Interactive.CSharp; -using Microsoft.DotNet.Interactive.Documents.ParserServer; using Microsoft.DotNet.Interactive.Formatting; using Microsoft.DotNet.Interactive.Formatting.Csv; using Microsoft.DotNet.Interactive.Formatting.TabularData; @@ -57,7 +57,8 @@ public delegate Task StartKernelHost( IConsole console); public delegate Task StartNotebookParser( - NotebookParserServer notebookParserServer); + NotebookParserServer notebookParserServer, + DirectoryInfo logPath = null); public delegate Task StartHttp( StartupOptions options, @@ -99,7 +100,7 @@ public static Parser Create( startKernelHost ??= StdIoMode.Do; - startNotebookParser ??= ParseNotebookCommand.Do; + startNotebookParser ??= ParseNotebookCommand.RunParserServer; startHttp ??= HttpCommand.Do; @@ -312,10 +313,10 @@ Command StdIO() stdIOCommand.Handler = CommandHandler.Create( async (startupOptions, options, console, context, cancellationToken) => { - using var c = + using var _ = console is TestConsole ? Disposable.Empty - : Program.StartToolLogging(startupOptions); + : Program.StartToolLogging(startupOptions.LogPath); using var operation = Log.OnEnterAndExit(); operation.Trace("Command line: {0}", Environment.CommandLine); @@ -411,7 +412,7 @@ Command NotebookParser() Console.OutputEncoding = Encoding.UTF8; var notebookParserServer = new NotebookParserServer(Console.In, Console.Out); context.GetCancellationToken().Register(() => notebookParserServer.Dispose()); - await startNotebookParser(notebookParserServer); + await startNotebookParser(notebookParserServer, context.ParseResult.GetValueForOption(logPathOption)); }); return notebookParserCommand; } diff --git a/src/dotnet-interactive/CommandLine/ParseNotebookCommand.cs b/src/dotnet-interactive/CommandLine/ParseNotebookCommand.cs index a11e505cee..feee9dcb5d 100644 --- a/src/dotnet-interactive/CommandLine/ParseNotebookCommand.cs +++ b/src/dotnet-interactive/CommandLine/ParseNotebookCommand.cs @@ -1,15 +1,23 @@ // 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.IO; using System.Threading.Tasks; -using Microsoft.DotNet.Interactive.Documents.ParserServer; +using Microsoft.DotNet.Interactive.App.ParserServer; +using Pocket; +using static Pocket.Logger; namespace Microsoft.DotNet.Interactive.App.CommandLine; internal static class ParseNotebookCommand { - public static Task Do(NotebookParserServer parserServer) + public static Task RunParserServer( + NotebookParserServer parserServer, + DirectoryInfo logPath = null) { + using var _ = Program.StartToolLogging(logPath); + using var __ = Log.OnEnterAndExit(); + return parserServer.RunAsync(); } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/DocumentSerializationType.cs b/src/dotnet-interactive/ParserServer/DocumentSerializationType.cs similarity index 79% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/DocumentSerializationType.cs rename to src/dotnet-interactive/ParserServer/DocumentSerializationType.cs index ae86b55b0b..2c68ceb2f2 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/DocumentSerializationType.cs +++ b/src/dotnet-interactive/ParserServer/DocumentSerializationType.cs @@ -1,7 +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. -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public enum DocumentSerializationType { diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/InteractiveDocumentConverter.cs b/src/dotnet-interactive/ParserServer/InteractiveDocumentConverter.cs similarity index 93% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/InteractiveDocumentConverter.cs rename to src/dotnet-interactive/ParserServer/InteractiveDocumentConverter.cs index f8c5876a3e..00b5b8e666 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/InteractiveDocumentConverter.cs +++ b/src/dotnet-interactive/ParserServer/InteractiveDocumentConverter.cs @@ -1,15 +1,17 @@ // 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. +#nullable enable using System; using System.Text.Json; +using Microsoft.DotNet.Interactive.Documents; using Microsoft.DotNet.Interactive.Utility; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; internal class InteractiveDocumentConverter : JsonConverter { - public override InteractiveDocument? Read( + public override InteractiveDocument Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseOrSerializeRequest.cs b/src/dotnet-interactive/ParserServer/NotebookParseOrSerializeRequest.cs similarity index 94% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseOrSerializeRequest.cs rename to src/dotnet-interactive/ParserServer/NotebookParseOrSerializeRequest.cs index a1f10348fb..7114cf1526 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseOrSerializeRequest.cs +++ b/src/dotnet-interactive/ParserServer/NotebookParseOrSerializeRequest.cs @@ -4,7 +4,7 @@ using System; using System.Text.Json; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public abstract class NotebookParseOrSerializeRequest { diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseRequest.cs b/src/dotnet-interactive/ParserServer/NotebookParseRequest.cs similarity index 91% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseRequest.cs rename to src/dotnet-interactive/ParserServer/NotebookParseRequest.cs index 17c5f8e9b3..c4c4ab1de4 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseRequest.cs +++ b/src/dotnet-interactive/ParserServer/NotebookParseRequest.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public sealed class NotebookParseRequest : NotebookParseOrSerializeRequest { diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseRequestConverter.cs b/src/dotnet-interactive/ParserServer/NotebookParseRequestConverter.cs similarity index 89% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseRequestConverter.cs rename to src/dotnet-interactive/ParserServer/NotebookParseRequestConverter.cs index 8a735b20c9..81dedbdbff 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseRequestConverter.cs +++ b/src/dotnet-interactive/ParserServer/NotebookParseRequestConverter.cs @@ -1,10 +1,12 @@ // 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. +#nullable enable using System; using System.Text.Json; +using Microsoft.DotNet.Interactive.Documents; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; internal class NotebookParseRequestConverter : JsonConverter { @@ -41,8 +43,8 @@ public override NotebookParseOrSerializeRequest Read( { id = reader.GetString(); } - break; + case "serializationType": if (reader.Read() && reader.TokenType == JsonTokenType.String) { @@ -86,7 +88,13 @@ id is null || serializationType is null || defaultLanguage is null) { - throw new JsonException($"Missing required property 'id' when deserializing {typeof(NotebookParseOrSerializeRequest)}"); + throw new JsonException($""" + Unable to deserialize {typeof(NotebookParseOrSerializeRequest)}. + {nameof(type)} = {type} + {nameof(id)} = {id} + {nameof(serializationType)} = {serializationType} + {nameof(defaultLanguage)} = {defaultLanguage} + """); } switch (type.GetValueOrDefault()) diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseResponse.cs b/src/dotnet-interactive/ParserServer/NotebookParseResponse.cs similarity index 71% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseResponse.cs rename to src/dotnet-interactive/ParserServer/NotebookParseResponse.cs index b12cee5278..9d4becc2eb 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseResponse.cs +++ b/src/dotnet-interactive/ParserServer/NotebookParseResponse.cs @@ -2,10 +2,11 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using Microsoft.DotNet.Interactive.Documents; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; -public class NotebookParseResponse : NotebookParserServerResponse +public sealed class NotebookParseResponse : NotebookParserServerResponse { public InteractiveDocument Document { get; } diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseResponseConverter.cs b/src/dotnet-interactive/ParserServer/NotebookParseResponseConverter.cs similarity index 84% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseResponseConverter.cs rename to src/dotnet-interactive/ParserServer/NotebookParseResponseConverter.cs index 3b3adbeeb4..cae88dd364 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParseResponseConverter.cs +++ b/src/dotnet-interactive/ParserServer/NotebookParseResponseConverter.cs @@ -1,10 +1,12 @@ // 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. +#nullable enable using System; using System.Text.Json; +using Microsoft.DotNet.Interactive.Documents; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; internal class NotebookParseResponseConverter : JsonConverter { @@ -47,13 +49,6 @@ public override NotebookParserServerResponse Read( } break; - case "errorMessage": - if (reader.Read() && reader.TokenType == JsonTokenType.String) - { - errorMessage = reader.GetString(); - } - break; - default: reader.Skip(); break; @@ -76,11 +71,6 @@ public override NotebookParserServerResponse Read( return new NotebookSerializeResponse(id, rawData); } - if (errorMessage is not null) - { - return new NotebookErrorResponse(id, errorMessage); - } - throw new JsonException($"Cannot deserialize {typeToConvert} due to missing properties"); } } diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServer.cs b/src/dotnet-interactive/ParserServer/NotebookParserServer.cs similarity index 82% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServer.cs rename to src/dotnet-interactive/ParserServer/NotebookParserServer.cs index f1d4aea2fe..9e5dca5c26 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServer.cs +++ b/src/dotnet-interactive/ParserServer/NotebookParserServer.cs @@ -1,16 +1,17 @@ // 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. +#nullable enable using System; -using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.DotNet.Interactive.Documents; using Microsoft.DotNet.Interactive.Documents.Jupyter; using Pocket; -using static Pocket.Logger; +using static Pocket.Logger; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public class NotebookParserServer : IDisposable { @@ -46,12 +47,12 @@ public async Task RunAsync() while (!_cancellationTokenSource.IsCancellationRequested) { - var line = await Input.ReadLineAsync(); + var line = await Input.ReadLineAsync(_cancellationTokenSource.Token); + if (line is not null) { - NotebookParserServerResponse? response = null; - string? requestId = null; - NotebookParseOrSerializeRequest? request = null; + NotebookParserServerResponse? response; + NotebookParseOrSerializeRequest? request; try { @@ -65,21 +66,17 @@ public async Task RunAsync() try { - requestId = request.Id; response = HandleRequest(request); } catch (Exception ex) { - op.Error("Exception while handling request with id {requestId}: {request}", ex, requestId, request); + op.Error("Exception while handling request with id {requestId}: {request}", ex, request.Id, request); break; } - if (response is not null) - { - var responsePayload = response.ToJson(); - await Output.WriteLineAsync(responsePayload); - await Output.FlushAsync(); - } + var responsePayload = response.ToJson(); + await Output.WriteLineAsync(responsePayload); + await Output.FlushAsync(); } } @@ -88,6 +85,11 @@ public async Task RunAsync() public static NotebookParserServerResponse HandleRequest(NotebookParseOrSerializeRequest request) { + if (request is null) + { + throw new ArgumentNullException(nameof(request)); + } + switch (request) { case NotebookParseRequest parse: @@ -123,7 +125,7 @@ public static NotebookParserServerResponse HandleRequest(NotebookParseOrSerializ } default: - return new NotebookErrorResponse(request.Id, $"Unsupported request: {request}"); + throw new IndexOutOfRangeException($"Request type not supported: {request.GetType()}"); } } diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServerExtensions.cs b/src/dotnet-interactive/ParserServer/NotebookParserServerExtensions.cs similarity index 74% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServerExtensions.cs rename to src/dotnet-interactive/ParserServer/NotebookParserServerExtensions.cs index 8268db6445..c8d2f6d27c 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServerExtensions.cs +++ b/src/dotnet-interactive/ParserServer/NotebookParserServerExtensions.cs @@ -3,19 +3,19 @@ using System.Text.Json; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public static class NotebookParserServerExtensions { public static string ToJson(this NotebookParserServerResponse response) { - var text = JsonSerializer.Serialize(response, response.GetType(), ParserServerSerializer.JsonSerializerOptions); + var text = JsonSerializer.Serialize(response, response.GetType(), App.ParserServer.ParserServerSerializer.JsonSerializerOptions); return text; } public static string ToJson(this NotebookParseOrSerializeRequest request) { - var text = JsonSerializer.Serialize(request, request.GetType(), ParserServerSerializer.JsonSerializerOptions); + var text = JsonSerializer.Serialize(request, request.GetType(), App.ParserServer.ParserServerSerializer.JsonSerializerOptions); return text; } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServerResponse.cs b/src/dotnet-interactive/ParserServer/NotebookParserServerResponse.cs similarity index 76% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServerResponse.cs rename to src/dotnet-interactive/ParserServer/NotebookParserServerResponse.cs index 08b23c7413..e61f35ba78 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookParserServerResponse.cs +++ b/src/dotnet-interactive/ParserServer/NotebookParserServerResponse.cs @@ -4,11 +4,11 @@ using System; using System.Text.Json; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public abstract class NotebookParserServerResponse { - protected NotebookParserServerResponse(string id) + private protected NotebookParserServerResponse(string id) { Id = id; } @@ -22,7 +22,7 @@ public static NotebookParserServerResponse FromJson(string json) throw new ArgumentNullException(nameof(json)); } - var request = JsonSerializer.Deserialize(json, ParserServerSerializer.JsonSerializerOptions); + var request = JsonSerializer.Deserialize(json, App.ParserServer.ParserServerSerializer.JsonSerializerOptions); return request ?? throw new InvalidOperationException(); } diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookSerializeRequest.cs b/src/dotnet-interactive/ParserServer/NotebookSerializeRequest.cs similarity index 88% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookSerializeRequest.cs rename to src/dotnet-interactive/ParserServer/NotebookSerializeRequest.cs index ecf915986b..c4fef40406 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookSerializeRequest.cs +++ b/src/dotnet-interactive/ParserServer/NotebookSerializeRequest.cs @@ -2,8 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using Microsoft.DotNet.Interactive.Documents; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public sealed class NotebookSerializeRequest : NotebookParseOrSerializeRequest { diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookSerializeResponse.cs b/src/dotnet-interactive/ParserServer/NotebookSerializeResponse.cs similarity index 75% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookSerializeResponse.cs rename to src/dotnet-interactive/ParserServer/NotebookSerializeResponse.cs index adf7c27bd5..548fe48b3a 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/NotebookSerializeResponse.cs +++ b/src/dotnet-interactive/ParserServer/NotebookSerializeResponse.cs @@ -3,9 +3,9 @@ using System; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; -public class NotebookSerializeResponse : NotebookParserServerResponse +public sealed class NotebookSerializeResponse : NotebookParserServerResponse { public byte[] RawData { get; } diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/ParserServerSerializer.cs b/src/dotnet-interactive/ParserServer/ParserServerSerializer.cs similarity index 95% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/ParserServerSerializer.cs rename to src/dotnet-interactive/ParserServer/ParserServerSerializer.cs index 8877ce4ac6..1de07805bd 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/ParserServerSerializer.cs +++ b/src/dotnet-interactive/ParserServer/ParserServerSerializer.cs @@ -6,7 +6,7 @@ using System.Text.Json.Serialization; using Microsoft.DotNet.Interactive.Documents.Json; -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public static class ParserServerSerializer { diff --git a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/RequestType.cs b/src/dotnet-interactive/ParserServer/RequestType.cs similarity index 78% rename from src/Microsoft.DotNet.Interactive.Documents/ParserServer/RequestType.cs rename to src/dotnet-interactive/ParserServer/RequestType.cs index f32bb20bd1..289c7ceef6 100644 --- a/src/Microsoft.DotNet.Interactive.Documents/ParserServer/RequestType.cs +++ b/src/dotnet-interactive/ParserServer/RequestType.cs @@ -1,7 +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. -namespace Microsoft.DotNet.Interactive.Documents.ParserServer; +namespace Microsoft.DotNet.Interactive.App.ParserServer; public enum RequestType { diff --git a/src/dotnet-interactive/Program.cs b/src/dotnet-interactive/Program.cs index 890e2aeb58..f881e2fa22 100644 --- a/src/dotnet-interactive/Program.cs +++ b/src/dotnet-interactive/Program.cs @@ -3,6 +3,7 @@ using System; using System.CommandLine.Parsing; +using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; @@ -11,6 +12,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.DotNet.Interactive.App.CommandLine; +using Microsoft.DotNet.Interactive.Documents; using Microsoft.DotNet.Interactive.Http; using Microsoft.DotNet.Interactive.Jupyter; using Microsoft.Extensions.DependencyInjection; @@ -36,17 +38,18 @@ public static async Task Main(string[] args) typeof(Startup).Assembly, // dotnet-interactive.dll typeof(Kernel).Assembly, // Microsoft.DotNet.Interactive.dll typeof(Shell).Assembly, // Microsoft.DotNet.Interactive.Jupyter.dll + typeof(InteractiveDocument).Assembly, // Microsoft.DotNet.Interactive.Documents.dll }; - internal static IDisposable StartToolLogging(StartupOptions options) + internal static IDisposable StartToolLogging(DirectoryInfo logPath = null) { var disposables = new CompositeDisposable(); - if (options.LogPath is not null) + if (logPath is not null) { var log = new SerilogLoggerConfiguration() .WriteTo - .RollingFileAlternate(options.LogPath.FullName, outputTemplate: "{Message}{NewLine}") + .RollingFileAlternate(logPath.FullName, outputTemplate: "{Message}{NewLine}") .CreateLogger(); var subscription = LogEvents.Subscribe( @@ -73,7 +76,7 @@ public static IWebHostBuilder ConstructWebHostBuilder( // TODO: (ConstructWebHostBuilder) dispose me var disposables = new CompositeDisposable { - StartToolLogging(options) + StartToolLogging(options.LogPath) }; using var _ = Log.OnEnterAndExit(); diff --git a/src/dotnet-interactive/dotnet-interactive.csproj b/src/dotnet-interactive/dotnet-interactive.csproj index 02076dabb1..244fb0bcbd 100644 --- a/src/dotnet-interactive/dotnet-interactive.csproj +++ b/src/dotnet-interactive/dotnet-interactive.csproj @@ -118,6 +118,9 @@ + + + diff --git a/src/interface-generator/InterfaceGenerator.cs b/src/interface-generator/InterfaceGenerator.cs index d0006465f2..87f5a7048e 100644 --- a/src/interface-generator/InterfaceGenerator.cs +++ b/src/interface-generator/InterfaceGenerator.cs @@ -8,12 +8,12 @@ using System.Reflection; using System.Text; using System.Text.Json.Serialization; +using Microsoft.DotNet.Interactive.App.ParserServer; using Microsoft.DotNet.Interactive.Commands; using Microsoft.DotNet.Interactive.CSharpProject; using Microsoft.DotNet.Interactive.CSharpProject.Commands; using Microsoft.DotNet.Interactive.CSharpProject.Events; using Microsoft.DotNet.Interactive.Documents; -using Microsoft.DotNet.Interactive.Documents.ParserServer; using Microsoft.DotNet.Interactive.Events; using Microsoft.DotNet.Interactive.VSCode; @@ -60,7 +60,6 @@ public class InterfaceGenerator // responses typeof(NotebookParseResponse), typeof(NotebookSerializeResponse), - typeof(NotebookErrorResponse), }; private static readonly HashSet OptionalFields = new() diff --git a/src/interface-generator/interface-generator.csproj b/src/interface-generator/interface-generator.csproj index ec3ed8bdaa..45a1b9389b 100644 --- a/src/interface-generator/interface-generator.csproj +++ b/src/interface-generator/interface-generator.csproj @@ -1,4 +1,4 @@ - + Exe @@ -12,8 +12,7 @@ - - +