From e7bef2c57beb6e86d2b37f7b213299d8e8fd79f3 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Mon, 28 Aug 2023 08:58:35 -0700 Subject: [PATCH 1/8] Move JSON serialization code to Json folder --- .../CommonResources.cs | 2 +- .../ProjectSnapshotSerializationBenchmark.cs | 2 +- .../ProjectRazorJsonSerializationBenchmark.cs | 2 +- .../TagHelperSerializationBenchmark.cs | 2 +- .../RazorProjectJsonSerializer.cs | 2 +- .../RazorLanguageServerWrapper.cs | 2 +- .../Serialization/JsonFileDeserializer.cs | 2 +- .../Serialization/JsonSerializerExtensions.cs | 2 +- .../Converters/ChecksumJsonConverter.cs | 2 +- .../Converters/ProjectRazorJsonJsonConverter.cs | 15 ++++++++++++++- .../ProjectSnapshotHandleJsonConverter.cs | 2 +- .../TagHelperDeltaResultJsonConverter.cs | 2 +- .../JsonConverterCollectionExtensions.cs | 3 ++- .../Serialization/{ => Json}/JsonDataConvert.cs | 2 +- .../{ => Json}/JsonDataReader.Policy.cs | 2 +- .../Serialization/{ => Json}/JsonDataReader.cs | 2 +- .../{ => Json}/JsonDataWriter.Policy.cs | 2 +- .../Serialization/{ => Json}/JsonDataWriter.cs | 2 +- .../{ => Json}/JsonReaderExtensions.cs | 2 +- .../{ => Json}/ObjectJsonConverter`1.cs | 2 +- .../Serialization/{ => Json}/ObjectReaders.cs | 2 +- .../Serialization/{ => Json}/ObjectWriters.cs | 2 +- .../{ => Json}/WellKnownPropertyNames.cs | 2 +- .../RazorServiceDescriptors.cs | 2 +- .../ProjectRazorJsonPublisher.cs | 2 +- .../LiveShareJsonConverterCollectionExtensions.cs | 2 +- .../ProjectSnapshotHandleProxyJsonConverter.cs | 2 +- .../LanguageServerTestBase.cs | 3 +-- .../Formatting/FormattingTestBase.cs | 2 +- .../ChecksumTests.cs | 2 +- .../ProjectSnapshotHandleSerializationTest.cs | 2 +- .../TagHelperDeltaResultSerializationTest.cs | 3 ++- .../SerializationTest.cs | 3 ++- .../RazorConfigurationSerializationTest.cs | 2 +- .../TagHelperDescriptorSerializationTest.cs | 2 +- .../TagHelperDescriptorCacheTest.cs | 2 +- 36 files changed, 52 insertions(+), 37 deletions(-) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/Converters/ChecksumJsonConverter.cs (90%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/Converters/ProjectRazorJsonJsonConverter.cs (60%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/Converters/ProjectSnapshotHandleJsonConverter.cs (91%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/Converters/TagHelperDeltaResultJsonConverter.cs (95%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{Converters => Json}/JsonConverterCollectionExtensions.cs (89%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/JsonDataConvert.cs (97%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/JsonDataReader.Policy.cs (91%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/JsonDataReader.cs (99%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/JsonDataWriter.Policy.cs (91%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/JsonDataWriter.cs (99%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/JsonReaderExtensions.cs (95%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/ObjectJsonConverter`1.cs (96%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/ObjectReaders.cs (99%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/ObjectWriters.cs (99%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ => Json}/WellKnownPropertyNames.cs (85%) diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs index 6c24dec5c6..1bfbc600d1 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs @@ -5,7 +5,7 @@ using System.Collections.Immutable; using System.IO; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.ProjectSystem; -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; namespace Microsoft.AspNetCore.Razor.Microbenchmarks; diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotSerializationBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotSerializationBenchmark.cs index 2d658c3483..09933da2bd 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotSerializationBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotSerializationBenchmark.cs @@ -8,7 +8,7 @@ using System.IO; using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Razor.Serialization; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Newtonsoft.Json; diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/ProjectRazorJsonSerializationBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/ProjectRazorJsonSerializationBenchmark.cs index 2f3222140f..03328f7b50 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/ProjectRazorJsonSerializationBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/ProjectRazorJsonSerializationBenchmark.cs @@ -5,7 +5,7 @@ using System.IO; using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Razor.ProjectSystem; -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Serialization; diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/TagHelperSerializationBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/TagHelperSerializationBenchmark.cs index 688980353d..5a9628408c 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/TagHelperSerializationBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/TagHelperSerializationBenchmark.cs @@ -7,7 +7,7 @@ using System.IO; using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Serialization; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectJsonSerializer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectJsonSerializer.cs index d072ef7803..33cbe9d8c2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectJsonSerializer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectJsonSerializer.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.ProjectEngineHost; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Serialization; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs index 610c1ebe7d..0ff99aeeaa 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServerWrapper.cs @@ -5,7 +5,7 @@ using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Serialization/JsonFileDeserializer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Serialization/JsonFileDeserializer.cs index eb7d3fd2ce..3a94e15d51 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Serialization/JsonFileDeserializer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Serialization/JsonFileDeserializer.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System.IO; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Newtonsoft.Json; namespace Microsoft.AspNetCore.Razor.LanguageServer.Serialization; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Serialization/JsonSerializerExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Serialization/JsonSerializerExtensions.cs index 90d799bc92..e227e85caa 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Serialization/JsonSerializerExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Serialization/JsonSerializerExtensions.cs @@ -3,7 +3,7 @@ using System; using Microsoft.AspNetCore.Razor.LanguageServer.Serialization; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ChecksumJsonConverter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ChecksumJsonConverter.cs similarity index 90% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ChecksumJsonConverter.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ChecksumJsonConverter.cs index 5a320f563c..68ba6c4816 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ChecksumJsonConverter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ChecksumJsonConverter.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Razor.Utilities; -namespace Microsoft.AspNetCore.Razor.Serialization.Converters; +namespace Microsoft.AspNetCore.Razor.Serialization.Json.Converters; internal class ChecksumJsonConverter : ObjectJsonConverter { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ProjectRazorJsonJsonConverter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectRazorJsonJsonConverter.cs similarity index 60% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ProjectRazorJsonJsonConverter.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectRazorJsonJsonConverter.cs index 41c3d71957..bc20eda461 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ProjectRazorJsonJsonConverter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectRazorJsonJsonConverter.cs @@ -1,9 +1,22 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. + +/* Unmerged change from project 'Microsoft.AspNetCore.Razor.ProjectEngineHost (net8.0)' +Before: +using Microsoft.AspNetCore.Razor.ProjectSystem; +After: +using Microsoft; +using Microsoft.AspNetCore.Razor; + +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Razor.ProjectSystem; +*/ using Microsoft.AspNetCore.Razor.ProjectSystem; -namespace Microsoft.AspNetCore.Razor.Serialization.Converters; +namespace Microsoft.AspNetCore.Razor.Serialization.Json.Converters; internal class ProjectRazorJsonJsonConverter : ObjectJsonConverter { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ProjectSnapshotHandleJsonConverter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectSnapshotHandleJsonConverter.cs similarity index 91% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ProjectSnapshotHandleJsonConverter.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectSnapshotHandleJsonConverter.cs index 3edd8e93d1..ae6b6473a9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/ProjectSnapshotHandleJsonConverter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectSnapshotHandleJsonConverter.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.Serialization.Converters; +namespace Microsoft.AspNetCore.Razor.Serialization.Json.Converters; internal partial class ProjectSnapshotHandleJsonConverter : ObjectJsonConverter { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/TagHelperDeltaResultJsonConverter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/TagHelperDeltaResultJsonConverter.cs similarity index 95% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/TagHelperDeltaResultJsonConverter.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/TagHelperDeltaResultJsonConverter.cs index 3935bf3ead..f5018fe60f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/TagHelperDeltaResultJsonConverter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/TagHelperDeltaResultJsonConverter.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.Serialization.Converters; +namespace Microsoft.AspNetCore.Razor.Serialization.Json.Converters; internal partial class TagHelperDeltaResultJsonConverter : ObjectJsonConverter { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/JsonConverterCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonConverterCollectionExtensions.cs similarity index 89% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/JsonConverterCollectionExtensions.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonConverterCollectionExtensions.cs index d81d872953..6a758cab3e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Converters/JsonConverterCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonConverterCollectionExtensions.cs @@ -4,9 +4,10 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using Microsoft.AspNetCore.Razor.Serialization.Json.Converters; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Razor.Serialization.Converters; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal static class JsonConverterCollectionExtensions { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataConvert.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataConvert.cs similarity index 97% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataConvert.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataConvert.cs index 8e783e1e9e..8775b51368 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataConvert.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataConvert.cs @@ -6,7 +6,7 @@ using System.IO; using System.Text; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal static class JsonDataConvert { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataReader.Policy.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataReader.Policy.cs similarity index 91% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataReader.Policy.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataReader.Policy.cs index fbd989465e..14de3daeea 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataReader.Policy.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataReader.Policy.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.ObjectPool; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal partial class JsonDataReader { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataReader.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataReader.cs similarity index 99% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataReader.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataReader.cs index 43da0e28e9..5ce0b2e65a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataReader.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataReader.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.Extensions.ObjectPool; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal delegate T ReadValue(JsonDataReader reader); internal delegate T ReadProperties(JsonDataReader reader); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataWriter.Policy.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataWriter.Policy.cs similarity index 91% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataWriter.Policy.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataWriter.Policy.cs index f362dbf116..1760abb83f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataWriter.Policy.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataWriter.Policy.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.ObjectPool; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal partial class JsonDataWriter { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataWriter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataWriter.cs similarity index 99% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataWriter.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataWriter.cs index 9ff763e555..5214d875c5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonDataWriter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonDataWriter.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.Extensions.ObjectPool; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal delegate void WriteProperties(JsonDataWriter writer, T value); internal delegate void WriteValue(JsonDataWriter writer, T value); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonReaderExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonReaderExtensions.cs similarity index 95% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonReaderExtensions.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonReaderExtensions.cs index 9dc45f580c..04f7599548 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/JsonReaderExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonReaderExtensions.cs @@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal static class JsonReaderExtensions { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectJsonConverter`1.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectJsonConverter`1.cs similarity index 96% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectJsonConverter`1.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectJsonConverter`1.cs index f737c77bdb..6baf351717 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectJsonConverter`1.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectJsonConverter`1.cs @@ -4,7 +4,7 @@ using System; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal abstract class ObjectJsonConverter : JsonConverter where T : class diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectReaders.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs similarity index 99% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectReaders.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs index 8b34f2ef6c..b848c5eff4 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectReaders.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs @@ -11,7 +11,7 @@ using Microsoft.CodeAnalysis.CSharp; using static Microsoft.AspNetCore.Razor.Language.RequiredAttributeDescriptor; using Checksum = Microsoft.AspNetCore.Razor.Utilities.Checksum; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal static partial class ObjectReaders { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectWriters.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs similarity index 99% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectWriters.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs index b7f4a4c6ac..51e42222a0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ObjectWriters.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Utilities; using Checksum = Microsoft.AspNetCore.Razor.Utilities.Checksum; -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal static class ObjectWriters { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/WellKnownPropertyNames.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/WellKnownPropertyNames.cs similarity index 85% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/WellKnownPropertyNames.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/WellKnownPropertyNames.cs index d3552b7322..77f5ea51d2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/WellKnownPropertyNames.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/WellKnownPropertyNames.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.Json; internal static class WellKnownPropertyNames { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RazorServiceDescriptors.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RazorServiceDescriptors.cs index ce58e1c769..aad42bd51c 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RazorServiceDescriptors.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RazorServiceDescriptors.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Immutable; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Newtonsoft.Json; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/ProjectRazorJsonPublisher.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/ProjectRazorJsonPublisher.cs index 10505326b5..c7d9c961e1 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/ProjectRazorJsonPublisher.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/ProjectRazorJsonPublisher.cs @@ -7,7 +7,7 @@ using System.ComponentModel.Composition; using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json.Converters; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/src/Microsoft.VisualStudio.LiveShare.Razor/Serialization/LiveShareJsonConverterCollectionExtensions.cs b/src/Razor/src/Microsoft.VisualStudio.LiveShare.Razor/Serialization/LiveShareJsonConverterCollectionExtensions.cs index f2750c3a32..873971846e 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LiveShare.Razor/Serialization/LiveShareJsonConverterCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LiveShare.Razor/Serialization/LiveShareJsonConverterCollectionExtensions.cs @@ -3,7 +3,7 @@ using System; using Newtonsoft.Json; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; namespace Microsoft.VisualStudio.LiveShare.Razor.Serialization; diff --git a/src/Razor/src/Microsoft.VisualStudio.LiveShare.Razor/Serialization/ProjectSnapshotHandleProxyJsonConverter.cs b/src/Razor/src/Microsoft.VisualStudio.LiveShare.Razor/Serialization/ProjectSnapshotHandleProxyJsonConverter.cs index 0367688aba..af117bd438 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LiveShare.Razor/Serialization/ProjectSnapshotHandleProxyJsonConverter.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LiveShare.Razor/Serialization/ProjectSnapshotHandleProxyJsonConverter.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; namespace Microsoft.VisualStudio.LiveShare.Razor.Serialization; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/LanguageServerTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/LanguageServerTestBase.cs index 8d5803c4a2..d04c806b84 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/LanguageServerTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/LanguageServerTestBase.cs @@ -14,8 +14,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.LanguageServer.Serialization; using Microsoft.AspNetCore.Razor.LanguageServer.Test.Common; -using Microsoft.AspNetCore.Razor.Serialization; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs index e52c48d20d..e2e1e2dbc1 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs @@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Razor.Language.IntegrationTests; using Microsoft.AspNetCore.Razor.LanguageServer.Extensions; using Microsoft.AspNetCore.Razor.LanguageServer.Protocol; using Microsoft.AspNetCore.Razor.LanguageServer.Test.Common; -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs index 71578cfd57..6bd800fdff 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Utilities; using Xunit; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/ProjectSnapshotHandleSerializationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/ProjectSnapshotHandleSerializationTest.cs index cb75dad6f9..81b4bc52fa 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/ProjectSnapshotHandleSerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/ProjectSnapshotHandleSerializationTest.cs @@ -4,7 +4,7 @@ using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Serialization; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor.ProjectSystem; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/TagHelperDeltaResultSerializationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/TagHelperDeltaResultSerializationTest.cs index 3c599f11bc..5a1e97e6d0 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/TagHelperDeltaResultSerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/TagHelperDeltaResultSerializationTest.cs @@ -9,7 +9,8 @@ using System.Text; using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Serialization; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; +using Microsoft.AspNetCore.Razor.Serialization.Json.Converters; using Microsoft.AspNetCore.Razor.Test.Common; using Newtonsoft.Json; using Xunit; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs index 83c359d2b0..183eb87632 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs @@ -6,7 +6,8 @@ using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Serialization; -using Microsoft.AspNetCore.Razor.Serialization.Converters; +using Microsoft.AspNetCore.Razor.Serialization.Json; +using Microsoft.AspNetCore.Razor.Serialization.Json.Converters; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.CodeAnalysis.CSharp; using Newtonsoft.Json; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/RazorConfigurationSerializationTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/RazorConfigurationSerializationTest.cs index 90d2434671..222ea230e3 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/RazorConfigurationSerializationTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/RazorConfigurationSerializationTest.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Xunit; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/TagHelperDescriptorSerializationTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/TagHelperDescriptorSerializationTest.cs index a2e2800ef0..76f9ea3fd1 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/TagHelperDescriptorSerializationTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/TagHelperDescriptorSerializationTest.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; using Xunit; using Xunit.Abstractions; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/TagHelperDescriptorCacheTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/TagHelperDescriptorCacheTest.cs index e7449e724b..47695539b9 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/TagHelperDescriptorCacheTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/TagHelperDescriptorCacheTest.cs @@ -6,7 +6,7 @@ using System.Collections.Immutable; using System.IO; using System.Linq; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Serialization; +using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Utilities; using Xunit; From 56f201c9c77995d59476e65abdb7dabc25061904 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Mon, 28 Aug 2023 09:10:25 -0700 Subject: [PATCH 2/8] Add package reference to MessagePack --- eng/Signing.props | 2 ++ eng/Versions.props | 1 + .../Microsoft.AspNetCore.Razor.ProjectEngineHost.csproj | 1 + 3 files changed, 4 insertions(+) diff --git a/eng/Signing.props b/eng/Signing.props index 6b23722cdb..5755536b06 100644 --- a/eng/Signing.props +++ b/eng/Signing.props @@ -20,6 +20,8 @@ + + diff --git a/eng/Versions.props b/eng/Versions.props index 9f64e29afd..bca199faed 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -147,6 +147,7 @@ 1.3.8 1.0.15 4.16.0 + 2.5.108 13.0.3 2.9.116 4.8.0 diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Microsoft.AspNetCore.Razor.ProjectEngineHost.csproj b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Microsoft.AspNetCore.Razor.ProjectEngineHost.csproj index 070360aa3c..75155780e9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Microsoft.AspNetCore.Razor.ProjectEngineHost.csproj +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Microsoft.AspNetCore.Razor.ProjectEngineHost.csproj @@ -14,6 +14,7 @@ + From 4b5d979ad69b8c0d065473c62d0d1bf0119fe7dd Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Mon, 28 Aug 2023 09:30:07 -0700 Subject: [PATCH 3/8] Add MessagePack formatters and resolvers --- .../Resources/SR.resx | 6 + .../Resources/xlf/SR.cs.xlf | 10 ++ .../Resources/xlf/SR.de.xlf | 10 ++ .../Resources/xlf/SR.es.xlf | 10 ++ .../Resources/xlf/SR.fr.xlf | 10 ++ .../Resources/xlf/SR.it.xlf | 10 ++ .../Resources/xlf/SR.ja.xlf | 10 ++ .../Resources/xlf/SR.ko.xlf | 10 ++ .../Resources/xlf/SR.pl.xlf | 10 ++ .../Resources/xlf/SR.pt-BR.xlf | 10 ++ .../Resources/xlf/SR.ru.xlf | 10 ++ .../Resources/xlf/SR.tr.xlf | 10 ++ .../Resources/xlf/SR.zh-Hans.xlf | 10 ++ .../Resources/xlf/SR.zh-Hant.xlf | 10 ++ .../Serialization/MessagePack/ArgKind.cs | 14 ++ .../MessagePack/DocumentationKind.cs | 10 ++ .../Formatters/ChecksumFormatter.cs | 38 +++++ .../Formatters/DocumentSnapshotFormatter.cs | 31 ++++ ...MessagePackFormatter`1.AllowNullWrapper.cs | 32 ++++ .../Formatters/MessagePackFormatter`1.cs | 85 ++++++++++ .../Formatters/ProjectRazorJsonFormatter.cs | 51 ++++++ .../ProjectSnapshotHandleFormatter.cs | 45 ++++++ .../ProjectWorkspaceStateFormatter.cs | 37 +++++ .../Formatters/RazorConfigurationFormatter.cs | 73 +++++++++ .../Formatters/RazorDiagnosticFormatter.cs | 55 +++++++ .../TagHelperDeltaResultFormatter.cs | 39 +++++ .../TagHelpers/AllowChildTagFormatter.cs | 33 ++++ .../TagHelpers/BoundAttributeFormatter.cs | 60 +++++++ .../BoundAttributeParameterFormatter.cs | 49 ++++++ .../DocumentationObjectFormatter.cs | 151 ++++++++++++++++++ .../Formatters/TagHelpers/Extensions.cs | 55 +++++++ .../TagHelpers/MetadataCollectionFormatter.cs | 72 +++++++++ .../TagHelpers/RequiredAttributeFormatter.cs | 49 ++++++ .../TagHelpers/TagHelperFormatter.cs | 58 +++++++ .../TagHelpers/TagHelperObjectFormatter`1.cs | 95 +++++++++++ .../TagHelperSerializationCache.Policy.cs | 37 +++++ ...HelperSerializationCache.ReferenceMap`1.cs | 55 +++++++ .../TagHelpers/TagHelperSerializationCache.cs | 33 ++++ .../TagHelpers/TagMatchingRuleFormatter.cs | 41 +++++ .../MessagePack/Resolvers/ChecksumResolver.cs | 36 +++++ .../Resolvers/ProjectRazoJsonResolver.cs | 36 +++++ .../ProjectSnapshotHandleResolver.cs | 35 ++++ .../MessagePack/Resolvers/RazorResolvers.cs | 17 ++ .../Resolvers/TagHelperDeltaResultResolver.cs | 35 ++++ 44 files changed, 1593 insertions(+) create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/ArgKind.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/DocumentationKind.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ChecksumFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/DocumentSnapshotFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/MessagePackFormatter`1.AllowNullWrapper.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/MessagePackFormatter`1.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectSnapshotHandleFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectWorkspaceStateFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorDiagnosticFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelperDeltaResultFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/AllowChildTagFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/BoundAttributeFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/BoundAttributeParameterFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/DocumentationObjectFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/Extensions.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/MetadataCollectionFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/RequiredAttributeFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperObjectFormatter`1.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.Policy.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.ReferenceMap`1.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagMatchingRuleFormatter.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ChecksumResolver.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ProjectRazoJsonResolver.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ProjectSnapshotHandleResolver.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/RazorResolvers.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/TagHelperDeltaResultResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/SR.resx b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/SR.resx index 66936baab5..27c42adf26 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/SR.resx +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/SR.resx @@ -135,6 +135,12 @@ Expected JSON token '{0}', but it was '{1}'. + + Unsupported argument kind: '{0}'. + + + Unsupported argument type: '{0}'. + Unsupported project.razor.json version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.cs.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.cs.xlf index a13216d7f3..556584e4e1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.cs.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.cs.xlf @@ -32,6 +32,16 @@ V řetězci JSON se očekával token {0}, ale byl {1}. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Byla zjištěna nepodporovaná verze project.razor.json. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.de.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.de.xlf index a0cf0d4cea..d735e645d6 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.de.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.de.xlf @@ -32,6 +32,16 @@ Erwartet wurde das JSON-Token '{0}', es lautete jedoch '{1}'. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Nicht unterstützte Version von "project.razor.json" festgestellt. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.es.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.es.xlf index e3e0413073..3cc0fc8ebc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.es.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.es.xlf @@ -32,6 +32,16 @@ Se esperaba un token JSON ''{0}'', pero era {1}. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Se encontró una versión de project.razor.json no admitida. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.fr.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.fr.xlf index 9d9f39a5cc..7353d924f5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.fr.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.fr.xlf @@ -32,6 +32,16 @@ Jeton JSON {0} attendu, mais il a été {1}. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Version de project.razor.json non prise en charge. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.it.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.it.xlf index fcb30a8315..2a83d73260 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.it.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.it.xlf @@ -32,6 +32,16 @@ Previsto token JSON '{0}', ma era '{1}'. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Incontrata versione project.razor.json non supportata. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ja.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ja.xlf index b9cea8640a..a9da0790b0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ja.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ja.xlf @@ -32,6 +32,16 @@ JSON トークン '{0}' が必要ですが、'{1}' でした。 + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. サポートされていない project.razor.json バージョンが検出されました。 diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ko.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ko.xlf index 649d1dc3fc..026cd4db70 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ko.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ko.xlf @@ -32,6 +32,16 @@ JSON 토큰 '{0}'이(가) 필요하지만 '{1}'입니다. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. 지원되지 않는 project.razor.json 버전이 있음. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pl.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pl.xlf index 1d63cac466..5d0118067b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pl.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pl.xlf @@ -32,6 +32,16 @@ Oczekiwano tokenu JSON „{0}”, ale to był „{1}”. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Napotkano nieobsługiwaną wersję pliku project.razor.json. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pt-BR.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pt-BR.xlf index e38c5a9d07..cc99086fb9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pt-BR.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pt-BR.xlf @@ -32,6 +32,16 @@ Token JSON esperado '{0}', mas foi '{1}'. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Versão project.razor.json sem suporte encontrada. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ru.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ru.xlf index 7d9b98d75a..652bf0f648 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ru.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ru.xlf @@ -32,6 +32,16 @@ Ожидался токен JSON "{0}", но он имел значение "{1}". + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Обнаружена неподдерживаемая версия project.razor.json. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.tr.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.tr.xlf index b4aa5c460e..744bf149d5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.tr.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.tr.xlf @@ -32,6 +32,16 @@ '{0}' JSON belirteci bekleniyordu ancak '{1}' idi. + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. Desteklenmeyen project.razor.json sürümü hesaplandı. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hans.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hans.xlf index 37a9ee0586..5ea6fb4618 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hans.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hans.xlf @@ -32,6 +32,16 @@ 预期为 JSON 令牌“{0}”,但实际为“{1}”。 + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. 遇到不支持的 project.razor.json 版本。 diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hant.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hant.xlf index e54138a72f..b363bc6b0e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hant.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hant.xlf @@ -32,6 +32,16 @@ 必須是 JSON 權杖 '{0}',但卻是 '{1}'。 + + Unsupported argument kind: '{0}'. + Unsupported argument kind: '{0}'. + + + + Unsupported argument type: '{0}'. + Unsupported argument type: '{0}'. + + Unsupported project.razor.json version encounted. 遇到不受支援的 project.razor.json 版本。 diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/ArgKind.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/ArgKind.cs new file mode 100644 index 0000000000..646663eeb7 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/ArgKind.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Razor.Serialization; + +internal enum ArgKind +{ + Integer, + String, + Null, + True, + False, + Boolean +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/DocumentationKind.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/DocumentationKind.cs new file mode 100644 index 0000000000..9bd23b63f3 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/DocumentationKind.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Razor.Serialization; + +internal enum DocumentationKind +{ + Descriptor, + String +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ChecksumFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ChecksumFormatter.cs new file mode 100644 index 0000000000..18c7e30074 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ChecksumFormatter.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.Utilities; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal sealed class ChecksumFormatter : MessagePackFormatter +{ + public static readonly MessagePackFormatter Instance = new ChecksumFormatter(); + + private ChecksumFormatter() + { + } + + public override Checksum Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + var data1 = reader.ReadInt64(); + var data2 = reader.ReadInt64(); + var data3 = reader.ReadInt64(); + var data4 = reader.ReadInt64(); + + var hashData = new Checksum.HashData(data1, data2, data3, data4); + + return new Checksum(hashData); + } + + public override void Serialize(ref MessagePackWriter writer, Checksum value, MessagePackSerializerOptions options) + { + var hashData = value.Data; + + writer.Write(hashData.Data1); + writer.Write(hashData.Data2); + writer.Write(hashData.Data3); + writer.Write(hashData.Data4); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/DocumentSnapshotFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/DocumentSnapshotFormatter.cs new file mode 100644 index 0000000000..5486fc0899 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/DocumentSnapshotFormatter.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal sealed class DocumentSnapshotHandleFormatter : MessagePackFormatter +{ + public static readonly MessagePackFormatter Instance = new DocumentSnapshotHandleFormatter(); + + private DocumentSnapshotHandleFormatter() + { + } + + public override DocumentSnapshotHandle Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + var filePath = DeserializeString(ref reader, options); + var targetPath = DeserializeString(ref reader, options); + var fileKind = DeserializeString(ref reader, options); + + return new DocumentSnapshotHandle(filePath, targetPath, fileKind); + } + + public override void Serialize(ref MessagePackWriter writer, DocumentSnapshotHandle value, MessagePackSerializerOptions options) + { + writer.Write(value.FilePath); + writer.Write(value.TargetPath); + writer.Write(value.FileKind); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/MessagePackFormatter`1.AllowNullWrapper.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/MessagePackFormatter`1.AllowNullWrapper.cs new file mode 100644 index 0000000000..0d2198c2a4 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/MessagePackFormatter`1.AllowNullWrapper.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal abstract partial class MessagePackFormatter +{ + public readonly ref struct AllowNullWrapper(MessagePackFormatter formatter) + { + private readonly MessagePackFormatter _formatter = formatter; + + public T? Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + => reader.TryReadNil() ? default : _formatter.Deserialize(ref reader, options); + + public void Serialize(ref MessagePackWriter writer, T? value, MessagePackSerializerOptions options) + { + if (value is null) + { + writer.WriteNil(); + } + else + { + _formatter.Serialize(ref writer, value, options); + } + } + + public string? DeserializeString(ref MessagePackReader reader, MessagePackSerializerOptions options) + => s_stringFormatter.Deserialize(ref reader, options); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/MessagePackFormatter`1.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/MessagePackFormatter`1.cs new file mode 100644 index 0000000000..cabc3a37df --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/MessagePackFormatter`1.cs @@ -0,0 +1,85 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using MessagePack; +using MessagePack.Formatters; +using Microsoft.AspNetCore.Razor.PooledObjects; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal abstract partial class MessagePackFormatter : IMessagePackFormatter +{ + private static readonly StringInterningFormatter s_stringFormatter = new(); + + public AllowNullWrapper AllowNull => new(this); + + public abstract T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options); + public abstract void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options); + + public static string DeserializeString(ref MessagePackReader reader, MessagePackSerializerOptions options) + => s_stringFormatter.Deserialize(ref reader, options).AssumeNotNull(); + + public virtual T[] DeserializeArray(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + var count = reader.ReadArrayHeader(); + + if (count == 0) + { + return Array.Empty(); + } + + using var builder = new PooledArrayBuilder(capacity: count); + + for (var i = 0; i < count; i++) + { + var item = Deserialize(ref reader, options); + builder.Add(item); + } + + return builder.ToArray(); + } + + public virtual ImmutableArray DeserializeImmutableArray(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + var count = reader.ReadArrayHeader(); + + if (count == 0) + { + return ImmutableArray.Empty; + } + + using var builder = new PooledArrayBuilder(capacity: count); + + for (var i = 0; i < count; i++) + { + var item = Deserialize(ref reader, options); + builder.Add(item); + } + + return builder.DrainToImmutable(); + } + + public virtual void SerializeArray(ref MessagePackWriter writer, IReadOnlyList array, MessagePackSerializerOptions options) + { + var count = array.Count; + writer.WriteArrayHeader(count); + + for (var i = 0; i < count; i++) + { + Serialize(ref writer, array[i], options); + } + } + + public virtual void SerializeArray(ref MessagePackWriter writer, ImmutableArray array, MessagePackSerializerOptions options) + { + writer.WriteArrayHeader(array.Length); + + foreach (var item in array) + { + Serialize(ref writer, item, options); + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs new file mode 100644 index 0000000000..224291e8d2 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs @@ -0,0 +1,51 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.ProjectSystem; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal sealed class ProjectRazorJsonFormatter : MessagePackFormatter +{ + public static readonly MessagePackFormatter Instance = new ProjectRazorJsonFormatter(); + + private ProjectRazorJsonFormatter() + { + } + + public override ProjectRazorJson Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + if (reader.NextMessagePackType != MessagePackType.Integer) + { + throw new ProjectRazorJsonSerializationException(SR.Unsupported_project_razor_json_version_encountered); + } + + var version = reader.ReadInt32(); + + if (version != ProjectRazorJson.Version) + { + throw new ProjectRazorJsonSerializationException(SR.Unsupported_project_razor_json_version_encountered); + } + + var serializedFilePath = DeserializeString(ref reader, options); + var filePath = DeserializeString(ref reader, options); + var configuration = RazorConfigurationFormatter.Instance.AllowNull.Deserialize(ref reader, options); + var projectWorkspaceState = ProjectWorkspaceStateFormatter.Instance.AllowNull.Deserialize(ref reader, options); + var rootNamespace = AllowNull.DeserializeString(ref reader, options); + var documents = DocumentSnapshotHandleFormatter.Instance.DeserializeImmutableArray(ref reader, options); + + return new ProjectRazorJson(serializedFilePath, filePath, configuration, rootNamespace, projectWorkspaceState, documents); + } + + public override void Serialize(ref MessagePackWriter writer, ProjectRazorJson value, MessagePackSerializerOptions options) + { + writer.Write(ProjectRazorJson.Version); + writer.Write(value.SerializedFilePath); + writer.Write(value.FilePath); + RazorConfigurationFormatter.Instance.AllowNull.Serialize(ref writer, value.Configuration, options); + ProjectWorkspaceStateFormatter.Instance.AllowNull.Serialize(ref writer, value.ProjectWorkspaceState, options); + writer.Write(value.RootNamespace); + DocumentSnapshotHandleFormatter.Instance.SerializeArray(ref writer, value.Documents, options); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectSnapshotHandleFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectSnapshotHandleFormatter.cs new file mode 100644 index 0000000000..3852c0a91c --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectSnapshotHandleFormatter.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using MessagePack; +using Microsoft.CodeAnalysis; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal sealed class ProjectSnapshotHandleFormatter : MessagePackFormatter +{ + public static readonly MessagePackFormatter Instance = new ProjectSnapshotHandleFormatter(); + + private ProjectSnapshotHandleFormatter() + { + } + + public override ProjectSnapshotHandle Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + var projectIdString = DeserializeString(ref reader, options); + var configuration = RazorConfigurationFormatter.Instance.AllowNull.Deserialize(ref reader, options); + + var rootNamespace = AllowNull.DeserializeString(ref reader, options); + + var projectId = ProjectId.CreateFromSerialized(Guid.Parse(projectIdString)); + + return new(projectId, configuration, rootNamespace); + } + + public override void Serialize(ref MessagePackWriter writer, ProjectSnapshotHandle value, MessagePackSerializerOptions options) + { + writer.Write(value.ProjectId.Id.ToString()); + + if (value.Configuration is { } configuration) + { + RazorConfigurationFormatter.Instance.Serialize(ref writer, configuration, options); + } + else + { + writer.WriteNil(); + } + + writer.Write(value.RootNamespace); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectWorkspaceStateFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectWorkspaceStateFormatter.cs new file mode 100644 index 0000000000..e52788b52e --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectWorkspaceStateFormatter.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.AspNetCore.Razor.ProjectSystem; +using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; +using Microsoft.CodeAnalysis.CSharp; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal sealed class ProjectWorkspaceStateFormatter : MessagePackFormatter +{ + public static readonly MessagePackFormatter Instance = new ProjectWorkspaceStateFormatter(); + + private ProjectWorkspaceStateFormatter() + { + } + + public override ProjectWorkspaceState Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + using var _ = TagHelperSerializationCache.Pool.GetPooledObject(out var cache); + + var tagHelpers = TagHelperFormatter.Instance.DeserializeImmutableArray(ref reader, options, cache); + var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32(); + + return new ProjectWorkspaceState(tagHelpers, csharpLanguageVersion); + } + + public override void Serialize(ref MessagePackWriter writer, ProjectWorkspaceState value, MessagePackSerializerOptions options) + { + using var _ = TagHelperSerializationCache.Pool.GetPooledObject(out var cache); + + TagHelperFormatter.Instance.SerializeArray(ref writer, value.TagHelpers, options, cache); + writer.Write((int)value.CSharpLanguageVersion); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs new file mode 100644 index 0000000000..754d80075f --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.PooledObjects; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal sealed class RazorConfigurationFormatter : MessagePackFormatter +{ + public static readonly MessagePackFormatter Instance = new RazorConfigurationFormatter(); + + private RazorConfigurationFormatter() + { + } + + public override RazorConfiguration Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + var configurationName = DeserializeString(ref reader, options); + var languageVersionText = DeserializeString(ref reader, options); + + var count = reader.ReadArrayHeader(); + + var extensions = count > 0 + ? ReadExtensions(ref reader, count, options) + : Array.Empty(); + + var languageVersion = RazorLanguageVersion.TryParse(languageVersionText, out var version) + ? version + : RazorLanguageVersion.Version_2_1; + + return RazorConfiguration.Create(languageVersion, configurationName, extensions); + } + + private RazorExtension[] ReadExtensions(ref MessagePackReader reader, int count, MessagePackSerializerOptions options) + { + using var builder = new PooledArrayBuilder(); + + for (var i = 0; i < count; i++) + { + var extensionName = DeserializeString(ref reader, options); + builder.Add(new SerializedRazorExtension(extensionName)); + } + + return builder.ToArray(); + } + + public override void Serialize(ref MessagePackWriter writer, RazorConfiguration value, MessagePackSerializerOptions options) + { + writer.Write(value.ConfigurationName); + + if (value.LanguageVersion == RazorLanguageVersion.Experimental) + { + writer.Write(nameof(RazorLanguageVersion.Experimental)); + } + else + { + writer.Write(value.LanguageVersion.ToString()); + } + + var extensions = value.Extensions; + var count = extensions.Count; + + writer.WriteArrayHeader(count); + + for (var i = 0; i < count; i++) + { + writer.Write(extensions[i].ExtensionName); + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorDiagnosticFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorDiagnosticFormatter.cs new file mode 100644 index 0000000000..7c161639a9 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorDiagnosticFormatter.cs @@ -0,0 +1,55 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Globalization; +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal sealed class RazorDiagnosticFormatter : MessagePackFormatter +{ + public static readonly MessagePackFormatter Instance = new RazorDiagnosticFormatter(); + + private RazorDiagnosticFormatter() + { + } + + public override RazorDiagnostic Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + var id = DeserializeString(ref reader, options); + var severity = (RazorDiagnosticSeverity)reader.ReadInt32(); + var message = DeserializeString(ref reader, options); + + var filePath = AllowNull.DeserializeString(ref reader, options); + var absoluteIndex = reader.ReadInt32(); + var lineIndex = reader.ReadInt32(); + var characterIndex = reader.ReadInt32(); + var length = reader.ReadInt32(); + + var descriptor = new RazorDiagnosticDescriptor(id, MessageFormat(message), severity); + var span = new SourceSpan(filePath, absoluteIndex, lineIndex, characterIndex, length); + + return RazorDiagnostic.Create(descriptor, span); + + static Func MessageFormat(string message) + { + return () => message; + } + } + + public override void Serialize(ref MessagePackWriter writer, RazorDiagnostic value, MessagePackSerializerOptions options) + { + writer.Write(value.Id); + writer.Write((int)value.Severity); + writer.Write(value.GetMessage(CultureInfo.CurrentCulture)); + + var span = value.Span; + writer.Write(span.FilePath); + writer.Write(span.AbsoluteIndex); + writer.Write(span.LineIndex); + writer.Write(span.CharacterIndex); + writer.Write(span.Length); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelperDeltaResultFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelperDeltaResultFormatter.cs new file mode 100644 index 0000000000..3a70735276 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelperDeltaResultFormatter.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +internal sealed class TagHelperDeltaResultFormatter : MessagePackFormatter +{ + public static readonly MessagePackFormatter Instance = new TagHelperDeltaResultFormatter(); + + private TagHelperDeltaResultFormatter() + { + } + + public override TagHelperDeltaResult Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + { + using var _ = TagHelperSerializationCache.Pool.GetPooledObject(out var cache); + + var delta = reader.ReadBoolean(); + var resultId = reader.ReadInt32(); + var added = TagHelperFormatter.Instance.DeserializeImmutableArray(ref reader, options, cache); + var removed = TagHelperFormatter.Instance.DeserializeImmutableArray(ref reader, options, cache); + + return new(delta, resultId, added, removed); + } + + public override void Serialize(ref MessagePackWriter writer, TagHelperDeltaResult value, MessagePackSerializerOptions options) + { + using var _ = TagHelperSerializationCache.Pool.GetPooledObject(out var cache); + + writer.Write(value.Delta); + writer.Write(value.ResultId); + TagHelperFormatter.Instance.SerializeArray(ref writer, value.Added, options, cache); + TagHelperFormatter.Instance.SerializeArray(ref writer, value.Removed, options, cache); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/AllowChildTagFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/AllowChildTagFormatter.cs new file mode 100644 index 0000000000..d0a045741d --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/AllowChildTagFormatter.cs @@ -0,0 +1,33 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed class AllowedChildTagFormatter : TagHelperObjectFormatter +{ + public static readonly TagHelperObjectFormatter Instance = new AllowedChildTagFormatter(); + + private AllowedChildTagFormatter() + { + } + + public override AllowedChildTagDescriptor Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var name = reader.ReadString(cache); + var displayName = reader.ReadString(cache); + var diagnostics = RazorDiagnosticFormatter.Instance.DeserializeArray(ref reader, options); + + return new DefaultAllowedChildTagDescriptor(name, displayName, diagnostics); + } + + public override void Serialize(ref MessagePackWriter writer, AllowedChildTagDescriptor value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + writer.Write(value.Name, cache); + writer.Write(value.DisplayName, cache); + + RazorDiagnosticFormatter.Instance.SerializeArray(ref writer, value.Diagnostics, options); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/BoundAttributeFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/BoundAttributeFormatter.cs new file mode 100644 index 0000000000..79c9f4281d --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/BoundAttributeFormatter.cs @@ -0,0 +1,60 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed class BoundAttributeFormatter : TagHelperObjectFormatter +{ + public static readonly TagHelperObjectFormatter Instance = new BoundAttributeFormatter(); + + private BoundAttributeFormatter() + { + } + + public override BoundAttributeDescriptor Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var kind = reader.ReadString(cache).AssumeNotNull(); + var name = reader.ReadString(cache); + var typeName = reader.ReadString(cache); + var isEnum = reader.ReadBoolean(); + var hasIndexer = reader.ReadBoolean(); + var indexerNamePrefix = reader.ReadString(cache); + var indexerTypeName = reader.ReadString(cache); + var displayName = reader.ReadString(cache); + var documentationObject = DocumentationObjectFormatter.Instance.Deserialize(ref reader, options, cache); + var caseSensitive = reader.ReadBoolean(); + var isEditorRequired = reader.ReadBoolean(); + var parameters = BoundAttributeParameterFormatter.Instance.DeserializeArray(ref reader, options, cache); + + var metadata = MetadataCollectionFormatter.Instance.Deserialize(ref reader, options, cache); + var diagnostics = RazorDiagnosticFormatter.Instance.DeserializeArray(ref reader, options); + + return new DefaultBoundAttributeDescriptor( + kind, name, typeName, isEnum, + hasIndexer, indexerNamePrefix, indexerTypeName, + documentationObject, displayName, caseSensitive, isEditorRequired, + parameters, metadata, diagnostics); + } + + public override void Serialize(ref MessagePackWriter writer, BoundAttributeDescriptor value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + writer.Write(value.Kind, cache); + writer.Write(value.Name, cache); + writer.Write(value.TypeName, cache); + writer.Write(value.IsEnum); + writer.Write(value.HasIndexer); + writer.Write(value.IndexerNamePrefix, cache); + writer.Write(value.IndexerTypeName, cache); + writer.Write(value.DisplayName, cache); + DocumentationObjectFormatter.Instance.Serialize(ref writer, value.DocumentationObject, options, cache); + writer.Write(value.CaseSensitive); + writer.Write(value.IsEditorRequired); + BoundAttributeParameterFormatter.Instance.SerializeArray(ref writer, value.BoundAttributeParameters, options, cache); + + MetadataCollectionFormatter.Instance.Serialize(ref writer, (MetadataCollection)value.Metadata, options, cache); + RazorDiagnosticFormatter.Instance.SerializeArray(ref writer, value.Diagnostics, options); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/BoundAttributeParameterFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/BoundAttributeParameterFormatter.cs new file mode 100644 index 0000000000..ad96e6b6c3 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/BoundAttributeParameterFormatter.cs @@ -0,0 +1,49 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed class BoundAttributeParameterFormatter : TagHelperObjectFormatter +{ + public static readonly TagHelperObjectFormatter Instance = new BoundAttributeParameterFormatter(); + + private BoundAttributeParameterFormatter() + { + } + + public override BoundAttributeParameterDescriptor Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var kind = reader.ReadString(cache).AssumeNotNull(); + var name = reader.ReadString(cache); + var typeName = reader.ReadString(cache); + var isEnum = reader.ReadBoolean(); + var displayName = reader.ReadString(cache); + var documentationObject = DocumentationObjectFormatter.Instance.Deserialize(ref reader, options, cache); + var caseSensitive = reader.ReadBoolean(); + + var metadata = MetadataCollectionFormatter.Instance.Deserialize(ref reader, options, cache); + var diagnostics = RazorDiagnosticFormatter.Instance.DeserializeArray(ref reader, options); + + return new DefaultBoundAttributeParameterDescriptor( + kind, name, typeName, + isEnum, documentationObject, displayName, caseSensitive, + metadata, diagnostics); + } + + public override void Serialize(ref MessagePackWriter writer, BoundAttributeParameterDescriptor value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + writer.Write(value.Kind, cache); + writer.Write(value.Name, cache); + writer.Write(value.TypeName, cache); + writer.Write(value.IsEnum); + writer.Write(value.DisplayName, cache); + DocumentationObjectFormatter.Instance.Serialize(ref writer, value.DocumentationObject, options, cache); + writer.Write(value.CaseSensitive); + + MetadataCollectionFormatter.Instance.Serialize(ref writer, (MetadataCollection)value.Metadata, options, cache); + RazorDiagnosticFormatter.Instance.SerializeArray(ref writer, value.Diagnostics, options); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/DocumentationObjectFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/DocumentationObjectFormatter.cs new file mode 100644 index 0000000000..ef34a9e30d --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/DocumentationObjectFormatter.cs @@ -0,0 +1,151 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.PooledObjects; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed class DocumentationObjectFormatter : TagHelperObjectFormatter +{ + public static readonly TagHelperObjectFormatter Instance = new DocumentationObjectFormatter(); + + private DocumentationObjectFormatter() + { + } + + public override DocumentationObject Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + if (reader.TryReadNil()) + { + return default; + } + + var documentationKind = (DocumentationKind)reader.ReadInt32(); + + switch (documentationKind) + { + case DocumentationKind.Descriptor: + var id = (DocumentationId)reader.ReadInt32(); + + var count = reader.ReadArrayHeader(); + var args = count > 0 + ? ReadArgs(ref reader, count, cache) + : Array.Empty(); + + return DocumentationDescriptor.From(id, args); + + case DocumentationKind.String: + return reader.ReadString(cache).AssumeNotNull(); + + default: + throw new NotSupportedException(SR.FormatUnsupported_argument_kind(documentationKind)); + } + } + + private object?[] ReadArgs(ref MessagePackReader reader, int count, TagHelperSerializationCache? cache) + { + using var builder = new PooledArrayBuilder(capacity: count); + + for (var i = 0; i < count; i++) + { + var item = ReadArg(ref reader, cache); + builder.Add(item); + } + + return builder.ToArray(); + } + + private object? ReadArg(ref MessagePackReader reader, TagHelperSerializationCache? cache) + { + if (reader.TryReadNil()) + { + return null; + } + + var argKind = (ArgKind)reader.ReadInt32(); + + return argKind switch + { + ArgKind.String => reader.ReadString(cache), + ArgKind.Integer => reader.ReadInt32(), + ArgKind.Boolean => reader.ReadBoolean(), + + _ => throw new NotSupportedException(SR.FormatUnsupported_argument_kind(argKind)), + }; + } + + public override void Serialize(ref MessagePackWriter writer, DocumentationObject value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + switch (value.Object) + { + case DocumentationDescriptor descriptor: + writer.Write((int)DocumentationKind.Descriptor); + writer.Write((int)descriptor.Id); + + var args = descriptor.Args; + var count = args.Length; + writer.WriteArrayHeader(count); + + foreach (var arg in args) + { + WriteArg(ref writer, arg, cache); + } + + break; + + case string text: + writer.Write((int)DocumentationKind.String); + writer.Write(text, cache); + break; + + case null: + writer.WriteNil(); + break; + + default: + Debug.Fail($"Documentation objects should only be of type {nameof(DocumentationDescriptor)}, string, or null."); + break; + } + + static void WriteArg(ref MessagePackWriter writer, object? value, TagHelperSerializationCache? cache) + { + switch (value) + { + case string s: + writer.Write((int)ArgKind.String); + writer.Write(s, cache); + break; + + case int i: + writer.Write((int)ArgKind.Integer); + writer.Write(i); + break; + + case bool b: + writer.Write((int)ArgKind.Boolean); + writer.Write(b); + break; + + case null: + writer.WriteNil(); + break; + + case var arg: + ThrowNotSupported(arg.GetType()); + break; + } + + [DoesNotReturn] + static void ThrowNotSupported(Type type) + { + throw new NotSupportedException( + SR.FormatUnsupported_argument_type(type.FullName)); + } + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/Extensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/Extensions.cs new file mode 100644 index 0000000000..c1e8dded2b --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/Extensions.cs @@ -0,0 +1,55 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal static class Extensions +{ + public static string? ReadString(this ref MessagePackReader reader, TagHelperSerializationCache? cache) + { + if (cache is null) + { + return reader.ReadString(); + } + + if (reader.NextMessagePackType == MessagePackType.Integer) + { + var referenceId = reader.ReadInt32(); + return cache.Strings.GetValue(referenceId); + } + + var result = reader.ReadString(); + + if (result is not null) + { + cache.Strings.Add(result); + } + + return result; + } + + public static void Write(this ref MessagePackWriter writer, string? value, TagHelperSerializationCache? cache) + { + if (cache is null) + { + writer.Write(value); + return; + } + + if (value is null) + { + writer.WriteNil(); + } + else if (cache.Strings.TryGetReferenceId(value, out var referenceId)) + { + writer.Write(referenceId); + } + else + { + writer.Write(value); + cache.Strings.Add(value); + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/MetadataCollectionFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/MetadataCollectionFormatter.cs new file mode 100644 index 0000000000..f7650da8ec --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/MetadataCollectionFormatter.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; + +#if !NET +using System.Collections.Generic; +#endif + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed class MetadataCollectionFormatter : TagHelperObjectFormatter +{ + public static readonly TagHelperObjectFormatter Instance = new MetadataCollectionFormatter(); + + private MetadataCollectionFormatter() + { + } + + public override MetadataCollection Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + if (cache is not null && reader.NextMessagePackType == MessagePackType.Integer) + { + var referenceId = reader.ReadInt32(); + return cache.Metadata.GetValue(referenceId); + } + + // Divide the number of array elements by two because each key/value pair is stored as two elements. + var count = reader.ReadArrayHeader() / 2; + + using var builder = new MetadataBuilder(); + + for (var i = 0; i < count; i++) + { + var key = reader.ReadString(cache).AssumeNotNull(); + var value = reader.ReadString(cache); + + builder.Add(key, value); + } + + var result = builder.Build(); + + cache?.Metadata.Add(result); + + return result; + } + + public override void Serialize(ref MessagePackWriter writer, MetadataCollection value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + if (cache is not null) + { + if (cache.Metadata.TryGetReferenceId(value, out var referenceId)) + { + writer.Write(referenceId); + return; + } + else + { + cache.Metadata.Add(value); + } + } + + writer.WriteArrayHeader(value.Count * 2); + + foreach (var (k, v) in value) + { + writer.Write(k, cache); + writer.Write(v, cache); + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/RequiredAttributeFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/RequiredAttributeFormatter.cs new file mode 100644 index 0000000000..11a9ab5cc3 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/RequiredAttributeFormatter.cs @@ -0,0 +1,49 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; +using static Microsoft.AspNetCore.Razor.Language.RequiredAttributeDescriptor; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed class RequiredAttributeFormatter : TagHelperObjectFormatter +{ + public static readonly TagHelperObjectFormatter Instance = new RequiredAttributeFormatter(); + + private RequiredAttributeFormatter() + { + } + + public override RequiredAttributeDescriptor Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var name = reader.ReadString(cache); + var nameComparison = (NameComparisonMode)reader.ReadInt32(); + var caseSensitive = reader.ReadBoolean(); + var value = reader.ReadString(cache); + var valueComparison = (ValueComparisonMode)reader.ReadInt32(); + var displayName = reader.ReadString(cache); + + var metadata = MetadataCollectionFormatter.Instance.Deserialize(ref reader, options, cache); + var diagnostics = RazorDiagnosticFormatter.Instance.DeserializeArray(ref reader, options); + + return new DefaultRequiredAttributeDescriptor( + name, nameComparison, + caseSensitive, + value, valueComparison, + displayName!, diagnostics, metadata); + } + + public override void Serialize(ref MessagePackWriter writer, RequiredAttributeDescriptor value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + writer.Write(value.Name, cache); + writer.Write((int)value.NameComparison); + writer.Write(value.CaseSensitive); + writer.Write(value.Value, cache); + writer.Write((int)value.ValueComparison); + writer.Write(value.DisplayName, cache); + + MetadataCollectionFormatter.Instance.Serialize(ref writer, (MetadataCollection)value.Metadata, options, cache); + RazorDiagnosticFormatter.Instance.SerializeArray(ref writer, value.Diagnostics, options); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperFormatter.cs new file mode 100644 index 0000000000..27d4b3b9d8 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperFormatter.cs @@ -0,0 +1,58 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed class TagHelperFormatter : TagHelperObjectFormatter +{ + public static readonly TagHelperObjectFormatter Instance = new TagHelperFormatter(); + + private TagHelperFormatter() + { + } + + public override TagHelperDescriptor Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var kind = reader.ReadString(cache).AssumeNotNull(); + var name = reader.ReadString(cache).AssumeNotNull(); + var assemblyName = reader.ReadString(cache).AssumeNotNull(); + + var displayName = reader.ReadString(cache); + var documentationObject = DocumentationObjectFormatter.Instance.Deserialize(ref reader, options, cache); + var tagOutputHint = reader.ReadString(cache); + var caseSensitive = reader.ReadBoolean(); + + var tagMatchingRules = TagMatchingRuleFormatter.Instance.DeserializeArray(ref reader, options, cache); + var boundAttributes = BoundAttributeFormatter.Instance.DeserializeArray(ref reader, options, cache); + var allowedChildTags = AllowedChildTagFormatter.Instance.DeserializeArray(ref reader, options, cache); + + var metadata = MetadataCollectionFormatter.Instance.Deserialize(ref reader, options, cache); + var diagnostics = RazorDiagnosticFormatter.Instance.DeserializeArray(ref reader, options); + + return new DefaultTagHelperDescriptor( + kind, name, assemblyName, + displayName!, documentationObject, + tagOutputHint, caseSensitive, + tagMatchingRules, boundAttributes, allowedChildTags, + metadata, diagnostics); + } + + public override void Serialize(ref MessagePackWriter writer, TagHelperDescriptor value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + writer.Write(value.Kind, cache); + writer.Write(value.Name, cache); + writer.Write(value.AssemblyName, cache); + writer.Write(value.DisplayName, cache); + DocumentationObjectFormatter.Instance.Serialize(ref writer, value.DocumentationObject, options, cache); + writer.Write(value.TagOutputHint, cache); + writer.Write(value.CaseSensitive); + TagMatchingRuleFormatter.Instance.SerializeArray(ref writer, value.TagMatchingRules, options, cache); + BoundAttributeFormatter.Instance.SerializeArray(ref writer, value.BoundAttributes, options, cache); + AllowedChildTagFormatter.Instance.SerializeArray(ref writer, value.AllowedChildTags, options, cache); + MetadataCollectionFormatter.Instance.Serialize(ref writer, (MetadataCollection)value.Metadata, options, cache); + RazorDiagnosticFormatter.Instance.SerializeArray(ref writer, value.Diagnostics, options); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperObjectFormatter`1.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperObjectFormatter`1.cs new file mode 100644 index 0000000000..6c7dcd3713 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperObjectFormatter`1.cs @@ -0,0 +1,95 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using MessagePack; +using Microsoft.AspNetCore.Razor.PooledObjects; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal abstract class TagHelperObjectFormatter : MessagePackFormatter +{ + public sealed override T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + => Deserialize(ref reader, options, cache: null); + + public sealed override void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options) + => Serialize(ref writer, value, options, cache: null); + + public sealed override T[] DeserializeArray(ref MessagePackReader reader, MessagePackSerializerOptions options) + => DeserializeArray(ref reader, options, cache: null); + + public sealed override ImmutableArray DeserializeImmutableArray(ref MessagePackReader reader, MessagePackSerializerOptions options) + => DeserializeImmutableArray(ref reader, options, cache: null); + + public sealed override void SerializeArray(ref MessagePackWriter writer, ImmutableArray array, MessagePackSerializerOptions options) + => SerializeArray(ref writer, array, options, cache: null); + + public sealed override void SerializeArray(ref MessagePackWriter writer, IReadOnlyList array, MessagePackSerializerOptions options) + => SerializeArray(ref writer, array, options, cache: null); + + public abstract T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache); + public abstract void Serialize(ref MessagePackWriter writer, T value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache); + + public T[] DeserializeArray(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var count = reader.ReadArrayHeader(); + + if (count == 0) + { + return Array.Empty(); + } + + using var builder = new PooledArrayBuilder(capacity: count); + + for (var i = 0; i < count; i++) + { + var item = Deserialize(ref reader, options, cache); + builder.Add(item); + } + + return builder.ToArray(); + } + + public virtual ImmutableArray DeserializeImmutableArray(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var count = reader.ReadArrayHeader(); + + if (count == 0) + { + return ImmutableArray.Empty; + } + + using var builder = new PooledArrayBuilder(capacity: count); + + for (var i = 0; i < count; i++) + { + var item = Deserialize(ref reader, options, cache); + builder.Add(item); + } + + return builder.DrainToImmutable(); + } + + public virtual void SerializeArray(ref MessagePackWriter writer, IReadOnlyList array, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var count = array.Count; + writer.WriteArrayHeader(count); + + for (var i = 0; i < count; i++) + { + Serialize(ref writer, array[i], options, cache); + } + } + + public virtual void SerializeArray(ref MessagePackWriter writer, ImmutableArray array, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + writer.WriteArrayHeader(array.Length); + + foreach (var item in array) + { + Serialize(ref writer, item, options, cache); + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.Policy.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.Policy.cs new file mode 100644 index 0000000000..36d637cfc2 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.Policy.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using Microsoft.Extensions.ObjectPool; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed partial class TagHelperSerializationCache +{ + private sealed class Policy : IPooledObjectPolicy + { + public static readonly Policy Instance = new(); + + private Policy() + { + } + + public TagHelperSerializationCache Create() => new(); + + public bool Return(TagHelperSerializationCache cache) + { + if (cache._metadataMap is { } metadataMap) + { + metadataMap.Dispose(); + cache._metadataMap = null; + } + + if (cache._stringMap is { } stringMap) + { + stringMap.Dispose(); + cache._stringMap = null; + } + + return true; + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.ReferenceMap`1.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.ReferenceMap`1.cs new file mode 100644 index 0000000000..8278a0ff8b --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.ReferenceMap`1.cs @@ -0,0 +1,55 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.Extensions.ObjectPool; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed partial class TagHelperSerializationCache +{ + public struct ReferenceMap : IDisposable + where T : notnull + { + private readonly ObjectPool> _dictionaryPool; + private List _values; + private Dictionary _valueToIdMap; + + public ReferenceMap(ObjectPool> dictionaryPool) + { + _dictionaryPool = dictionaryPool; + _values = ListPool.Default.Get(); + _valueToIdMap = _dictionaryPool.Get(); + } + + public void Dispose() + { + if (_values is { } values) + { + ListPool.Default.Return(values); + _values = null!; + } + + if (_valueToIdMap is { } valueToIdMap) + { + _dictionaryPool.Return(valueToIdMap); + _valueToIdMap = null!; + } + } + + public T GetValue(int referenceId) + => _values[referenceId]; + + public readonly bool TryGetReferenceId(T value, out int referenceId) + => _valueToIdMap.TryGetValue(value, out referenceId); + + public void Add(T value) + { + var id = _values.Count; + _values.Add(value); + _valueToIdMap.Add(value, id); + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.cs new file mode 100644 index 0000000000..0f4fc6699e --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagHelperSerializationCache.cs @@ -0,0 +1,33 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Collections.Generic; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.Extensions.ObjectPool; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed partial class TagHelperSerializationCache +{ + public static readonly ObjectPool Pool = DefaultPool.Create(Policy.Instance); + + private static readonly ObjectPool> s_metadataPool + = DictionaryPool.Default; + + private static readonly ObjectPool> s_stringPool + = StringDictionaryPool.Ordinal; + + private ReferenceMap? _metadataMap; + private ReferenceMap? _stringMap; + + private TagHelperSerializationCache() + { + } + + public ReferenceMap Metadata + => _metadataMap ??= new ReferenceMap(s_metadataPool); + + public ReferenceMap Strings + => _stringMap ??= new ReferenceMap(s_stringPool); +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagMatchingRuleFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagMatchingRuleFormatter.cs new file mode 100644 index 0000000000..787185c519 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/TagHelpers/TagMatchingRuleFormatter.cs @@ -0,0 +1,41 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; + +internal sealed class TagMatchingRuleFormatter : TagHelperObjectFormatter +{ + public static readonly TagHelperObjectFormatter Instance = new TagMatchingRuleFormatter(); + + private TagMatchingRuleFormatter() + { + } + + public override TagMatchingRuleDescriptor Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + var tagName = reader.ReadString(cache).AssumeNotNull(); + var parentTag = reader.ReadString(cache); + var tagStructure = (TagStructure)reader.ReadInt32(); + var caseSensitive = reader.ReadBoolean(); + var attributes = RequiredAttributeFormatter.Instance.DeserializeArray(ref reader, options, cache); + var diagnostics = RazorDiagnosticFormatter.Instance.DeserializeArray(ref reader, options); + + return new DefaultTagMatchingRuleDescriptor( + tagName, parentTag, + tagStructure, caseSensitive, + attributes, diagnostics); + } + + public override void Serialize(ref MessagePackWriter writer, TagMatchingRuleDescriptor value, MessagePackSerializerOptions options, TagHelperSerializationCache? cache) + { + writer.Write(value.TagName, cache); + writer.Write(value.ParentTag, cache); + writer.Write((int)value.TagStructure); + writer.Write(value.CaseSensitive); + RequiredAttributeFormatter.Instance.SerializeArray(ref writer, value.Attributes, options, cache); + RazorDiagnosticFormatter.Instance.SerializeArray(ref writer, value.Diagnostics, options); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ChecksumResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ChecksumResolver.cs new file mode 100644 index 0000000000..6eeff228ae --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ChecksumResolver.cs @@ -0,0 +1,36 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using MessagePack.Formatters; +using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; +using Microsoft.AspNetCore.Razor.Utilities; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Resolvers; + +internal sealed class ChecksumResolver : IFormatterResolver +{ + public static readonly ChecksumResolver Instance = new(); + + private ChecksumResolver() + { + } + + public IMessagePackFormatter? GetFormatter() + { + return Cache.Formatter; + } + + private static class Cache + { + public static readonly IMessagePackFormatter? Formatter; + + static Cache() + { + if (typeof(T) == typeof(Checksum)) + { + Formatter = (IMessagePackFormatter)ChecksumFormatter.Instance; + } + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ProjectRazoJsonResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ProjectRazoJsonResolver.cs new file mode 100644 index 0000000000..b5e5958760 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ProjectRazoJsonResolver.cs @@ -0,0 +1,36 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using MessagePack.Formatters; +using Microsoft.AspNetCore.Razor.ProjectSystem; +using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Resolvers; + +internal sealed class ProjectRazorJsonResolver : IFormatterResolver +{ + public static readonly ProjectRazorJsonResolver Instance = new(); + + private ProjectRazorJsonResolver() + { + } + + public IMessagePackFormatter? GetFormatter() + { + return Cache.Formatter; + } + + private static class Cache + { + public static readonly IMessagePackFormatter? Formatter; + + static Cache() + { + if (typeof(T) == typeof(ProjectRazorJson)) + { + Formatter = (IMessagePackFormatter)ProjectRazorJsonFormatter.Instance; + } + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ProjectSnapshotHandleResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ProjectSnapshotHandleResolver.cs new file mode 100644 index 0000000000..cf8ed199d7 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/ProjectSnapshotHandleResolver.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using MessagePack.Formatters; +using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Resolvers; + +internal sealed class ProjectSnapshotHandleResolver : IFormatterResolver +{ + public static readonly ProjectSnapshotHandleResolver Instance = new(); + + private ProjectSnapshotHandleResolver() + { + } + + public IMessagePackFormatter? GetFormatter() + { + return Cache.Formatter; + } + + private static class Cache + { + public static readonly IMessagePackFormatter? Formatter; + + static Cache() + { + if (typeof(T) == typeof(ProjectSnapshotHandle)) + { + Formatter = (IMessagePackFormatter)ProjectSnapshotHandleFormatter.Instance; + } + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/RazorResolvers.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/RazorResolvers.cs new file mode 100644 index 0000000000..3e491054e9 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/RazorResolvers.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack.Resolvers; +using MessagePack; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Resolvers; + +internal static class RazorResolvers +{ + public static readonly IFormatterResolver All = CompositeResolver.Create( + ChecksumResolver.Instance, + ProjectRazorJsonResolver.Instance, + ProjectSnapshotHandleResolver.Instance, + TagHelperDeltaResultResolver.Instance, + StandardResolver.Instance); +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/TagHelperDeltaResultResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/TagHelperDeltaResultResolver.cs new file mode 100644 index 0000000000..b7fd34c326 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/TagHelperDeltaResultResolver.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using MessagePack; +using MessagePack.Formatters; +using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; + +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Resolvers; + +internal sealed class TagHelperDeltaResultResolver : IFormatterResolver +{ + public static readonly TagHelperDeltaResultResolver Instance = new(); + + private TagHelperDeltaResultResolver() + { + } + + public IMessagePackFormatter? GetFormatter() + { + return Cache.Formatter; + } + + private static class Cache + { + public static readonly IMessagePackFormatter? Formatter; + + static Cache() + { + if (typeof(T) == typeof(TagHelperDeltaResult)) + { + Formatter = (IMessagePackFormatter)TagHelperDeltaResultFormatter.Instance; + } + } + } +} From d2fbda87f05cebf807c9218479353dae28ff6e8c Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Mon, 28 Aug 2023 09:56:52 -0700 Subject: [PATCH 4/8] Refactor how tests read in tag helpers --- .../LanguageServerTestBase.cs | 21 +++------------- .../RazorTranslateDiagnosticsEndpointTest.cs | 21 +++++----------- .../Formatting/FormattingTestBase.cs | 17 ++----------- .../RazorLanguageEndpointTest.cs | 3 ++- .../ChecksumTests.cs | 9 +------ .../TagHelperDeltaResultSerializationTest.cs | 12 +-------- .../RazorTestResources.cs | 25 +++++++++++++++++++ .../TagHelperDescriptorSerializationTest.cs | 22 ++++------------ .../TagHelperDescriptorCacheTest.cs | 19 ++------------ 9 files changed, 48 insertions(+), 101 deletions(-) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/LanguageServerTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/LanguageServerTestBase.cs index d04c806b84..a6689f52bf 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/LanguageServerTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test.Common/LanguageServerTestBase.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -73,13 +72,14 @@ public abstract class LanguageServerTestBase : TestBase return requestContext; } - protected static RazorCodeDocument CreateCodeDocument(string text, IReadOnlyList? tagHelpers = null, string? filePath = null) + protected static RazorCodeDocument CreateCodeDocument(string text, ImmutableArray tagHelpers = default, string? filePath = null) { var fileKind = FileKinds.GetFileKindFromFilePath(filePath ?? "test.cshtml"); - tagHelpers ??= Array.Empty(); + tagHelpers = tagHelpers.NullToEmpty(); + if (fileKind == FileKinds.Component) { - tagHelpers = tagHelpers.Concat(GetDefaultRuntimeComponents()).ToArray(); + tagHelpers = tagHelpers.AddRange(RazorTestResources.BlazorServerAppTagHelpers); } var sourceDocument = TestRazorSourceDocument.Create(text, filePath: filePath); @@ -144,19 +144,6 @@ public abstract class LanguageServerTestBase : TestBase return monitor.Object; } - private static IReadOnlyList GetDefaultRuntimeComponents() - { - var bytes = RazorTestResources.GetResourceBytes(RazorTestResources.BlazorServerAppTagHelpersJson); - - using var stream = new MemoryStream(bytes); - using var reader = new StreamReader(stream); - - return JsonDataConvert.DeserializeData(reader, - static r => r.ReadArray( - static r => ObjectReaders.ReadTagHelper(r, useCache: false))) - ?? Array.Empty(); - } - [Obsolete("Use " + nameof(LSPProjectSnapshotManagerDispatcher))] private class TestProjectSnapshotManagerDispatcher : ProjectSnapshotManagerDispatcher { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorTranslateDiagnosticsEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorTranslateDiagnosticsEndpointTest.cs index f8ad2a83da..8026cf83ff 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorTranslateDiagnosticsEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorTranslateDiagnosticsEndpointTest.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; @@ -776,10 +777,7 @@ public class RazorTranslateDiagnosticsEndpointTest : LanguageServerTestBase var addTagHelper = $"@addTagHelper *, TestAssembly{Environment.NewLine}"; var codeDocument = CreateCodeDocument( $"{addTagHelper}", - new[] - { - GetButtonTagHelperDescriptor().Build() - }); + ImmutableArray.Create(GetButtonTagHelperDescriptor().Build())); var documentContext = CreateDocumentContext(documentPath, codeDocument); var diagnosticsService = new RazorTranslateDiagnosticsService(_mappingService, LoggerFactory); var diagnosticsEndpoint = new RazorTranslateDiagnosticsEndpoint(diagnosticsService, LoggerFactory); @@ -808,10 +806,7 @@ public class RazorTranslateDiagnosticsEndpointTest : LanguageServerTestBase var addTagHelper = $"@addTagHelper *, TestAssembly{Environment.NewLine}"; var codeDocument = CreateCodeDocument( $"{addTagHelper}", - new[] - { - GetButtonTagHelperDescriptor().Build() - }); + ImmutableArray.Create(GetButtonTagHelperDescriptor().Build())); var documentContext = CreateDocumentContext(documentPath, codeDocument); var diagnosticsService = new RazorTranslateDiagnosticsService(_mappingService, LoggerFactory); var diagnosticsEndpoint = new RazorTranslateDiagnosticsEndpoint(diagnosticsService, LoggerFactory); @@ -928,9 +923,7 @@ public class RazorTranslateDiagnosticsEndpointTest : LanguageServerTestBase new SourceSpan(addTagHelper.Length + 38, 9), new SourceSpan(addTagHelper.Length + 25, 9)) }, - new[] { - descriptor.Build() - }); + ImmutableArray.Create(descriptor.Build())); var documentContext = CreateDocumentContext(documentPath, codeDocument); var diagnosticsService = new RazorTranslateDiagnosticsService(_mappingService, LoggerFactory); var diagnosticsEndpoint = new RazorTranslateDiagnosticsEndpoint(diagnosticsService, LoggerFactory); @@ -977,9 +970,7 @@ public class RazorTranslateDiagnosticsEndpointTest : LanguageServerTestBase ", projectedCSharpSource: string.Empty, sourceMappings: Array.Empty(), - new[] { - descriptor.Build() - }); + ImmutableArray.Create(descriptor.Build())); var documentContext = CreateDocumentContext(documentPath, codeDocument); var diagnosticsService = new RazorTranslateDiagnosticsService(_mappingService, LoggerFactory); var diagnosticsEndpoint = new RazorTranslateDiagnosticsEndpoint(diagnosticsService, LoggerFactory); @@ -1207,7 +1198,7 @@ public class RazorTranslateDiagnosticsEndpointTest : LanguageServerTestBase string razorSource, string projectedCSharpSource, IEnumerable sourceMappings, - IReadOnlyList? tagHelpers = null) + ImmutableArray tagHelpers = default) { var codeDocument = CreateCodeDocument(razorSource, tagHelpers); var csharpDocument = RazorCSharpDocument.Create( diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs index e2e1e2dbc1..edb2e225d6 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Razor.Language.IntegrationTests; using Microsoft.AspNetCore.Razor.LanguageServer.Extensions; using Microsoft.AspNetCore.Razor.LanguageServer.Protocol; using Microsoft.AspNetCore.Razor.LanguageServer.Test.Common; -using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor; @@ -40,7 +39,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; public class FormattingTestBase : RazorIntegrationTestBase { private static readonly AsyncLocal s_fileName = new(); - private static readonly ImmutableArray s_defaultComponents = GetDefaultRuntimeComponents(); public FormattingTestBase(ITestOutputHelper testOutput) : base(testOutput) @@ -238,9 +236,10 @@ public class FormattingTestBase : RazorIntegrationTestBase { fileKind ??= FileKinds.Component; tagHelpers = tagHelpers.NullToEmpty(); + if (fileKind == FileKinds.Component) { - tagHelpers = tagHelpers.AddRange(s_defaultComponents); + tagHelpers = tagHelpers.AddRange(RazorTestResources.BlazorServerAppTagHelpers); } var sourceDocument = text.GetRazorSourceDocument(path, path); @@ -338,16 +337,4 @@ public class FormattingTestBase : RazorIntegrationTestBase return null; } - - private static ImmutableArray GetDefaultRuntimeComponents() - { - var bytes = RazorTestResources.GetResourceBytes(RazorTestResources.BlazorServerAppTagHelpersJson); - - using var stream = new MemoryStream(bytes); - using var reader = new StreamReader(stream); - - return JsonDataConvert.DeserializeData(reader, - static r => r.ReadImmutableArray( - static r => ObjectReaders.ReadTagHelper(r, useCache: false))); - } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageEndpointTest.cs index 80c31a37cf..7c220d7961 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLanguageEndpointTest.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; @@ -364,7 +365,7 @@ public class RazorLanguageEndpointTest : LanguageServerTestBase private static RazorCodeDocument CreateCodeDocumentWithCSharpProjection(string razorSource, string projectedCSharpSource, IEnumerable sourceMappings) { - var codeDocument = CreateCodeDocument(razorSource, Array.Empty()); + var codeDocument = CreateCodeDocument(razorSource, ImmutableArray.Empty); var csharpDocument = RazorCSharpDocument.Create( codeDocument, projectedCSharpSource, diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs index 6bd800fdff..4449e1f597 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ChecksumTests.cs @@ -124,14 +124,7 @@ public class ChecksumTests(ITestOutputHelper testOutput) : TestBase(testOutput) [Fact] public void TestTagHelperEquality() { - var bytes = RazorTestResources.GetResourceBytes(RazorTestResources.BlazorServerAppTagHelpersJson); - - using var stream = new MemoryStream(bytes); - using var reader = new StreamReader(stream); - - var tagHelpers = JsonDataConvert.DeserializeData(reader, - static r => r.ReadImmutableArray( - static r => ObjectReaders.ReadTagHelper(r, useCache: false))); + var tagHelpers = RazorTestResources.BlazorServerAppTagHelpers; for (var i = 0; i < tagHelpers.Length; i++) { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/TagHelperDeltaResultSerializationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/TagHelperDeltaResultSerializationTest.cs index 5a1e97e6d0..036f1925d1 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/TagHelperDeltaResultSerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/TagHelperDeltaResultSerializationTest.cs @@ -9,7 +9,6 @@ using System.Text; using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Serialization; -using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Serialization.Json.Converters; using Microsoft.AspNetCore.Razor.Test.Common; using Newtonsoft.Json; @@ -25,16 +24,7 @@ public class TagHelperDeltaResultSerializationTest(ITestOutputHelper testOutput) public void TagHelperResolutionResult_DefaultBlazorServerProject_RoundTrips() { // Arrange - var bytes = RazorTestResources.GetResourceBytes(RazorTestResources.BlazorServerAppTagHelpersJson); - - ImmutableArray tagHelpers; - using (var stream = new MemoryStream(bytes)) - using (var reader = new StreamReader(stream)) - { - tagHelpers = JsonDataConvert.DeserializeData(reader, - static r => r.ReadImmutableArray( - static r => ObjectReaders.ReadTagHelper(r, useCache: false))); - } + var tagHelpers = RazorTestResources.BlazorServerAppTagHelpers; var expectedResult = new TagHelperDeltaResult( Delta: true, diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/RazorTestResources.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/RazorTestResources.cs index a33f5670b2..6a5585a4bd 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/RazorTestResources.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/RazorTestResources.cs @@ -3,8 +3,11 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.IO; using System.Reflection; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Serialization.Json; namespace Microsoft.AspNetCore.Razor.Test.Common; @@ -12,6 +15,8 @@ internal static class RazorTestResources { public const string BlazorServerAppTagHelpersJson = "BlazorServerApp.TagHelpers.json"; + private static ImmutableArray? s_blazorServerAppTagHelpers; + private readonly static Dictionary<(string Name, string? Folder), string> s_textMap = new(); private readonly static Dictionary<(string Name, string? Folder), byte[]> s_bytesMap = new(); @@ -71,4 +76,24 @@ internal static class RazorTestResources return value; } } + + public static ImmutableArray BlazorServerAppTagHelpers + { + get + { + return s_blazorServerAppTagHelpers ??= ReadBlazorServerAppTagHelpers(); + + static ImmutableArray ReadBlazorServerAppTagHelpers() + { + var bytes = GetResourceBytes(BlazorServerAppTagHelpersJson); + + using var stream = new MemoryStream(bytes); + using var reader = new StreamReader(stream); + + return JsonDataConvert.DeserializeData(reader, + static r => r.ReadImmutableArray( + static r => ObjectReaders.ReadTagHelper(r, useCache: false))); + } + } + } } diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/TagHelperDescriptorSerializationTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/TagHelperDescriptorSerializationTest.cs index 76f9ea3fd1..dca2515e53 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/TagHelperDescriptorSerializationTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Serialization/TagHelperDescriptorSerializationTest.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.IO; using System.Text; using Microsoft.AspNetCore.Razor.Language; @@ -25,22 +26,10 @@ public class TagHelperDescriptorSerializationTest : TestBase public void TagHelperDescriptor_DefaultBlazorServerProject_RoundTrips() { // Arrange - var bytes = RazorTestResources.GetResourceBytes(RazorTestResources.BlazorServerAppTagHelpersJson); + var expectedTagHelpers = RazorTestResources.BlazorServerAppTagHelpers; // Act - // Read in the tag helpers - IReadOnlyList expectedTagHelpers; - - using (var stream = new MemoryStream(bytes)) - using (var reader = new StreamReader(stream)) - { - expectedTagHelpers = JsonDataConvert.DeserializeData(reader, - static r => r.ReadArray( - static r => ObjectReaders.ReadTagHelper(r, useCache: false))) - ?? Array.Empty(); - } - using var writeStream = new MemoryStream(); // Serialize the tag helpers to a stream @@ -53,14 +42,13 @@ public class TagHelperDescriptorSerializationTest : TestBase // Deserialize the tag helpers from the stream we just serialized to. writeStream.Seek(0, SeekOrigin.Begin); - IReadOnlyList actualTagHelpers; + ImmutableArray actualTagHelpers; using (var reader = new StreamReader(writeStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 4096, leaveOpen: true)) { actualTagHelpers = JsonDataConvert.DeserializeData(reader, - static r => r.ReadArray( - static r => ObjectReaders.ReadTagHelper(r, useCache: false))) - ?? Array.Empty(); + static r => r.ReadImmutableArray( + static r => ObjectReaders.ReadTagHelper(r, useCache: false))); } // Assert diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/TagHelperDescriptorCacheTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/TagHelperDescriptorCacheTest.cs index 47695539b9..3887819af9 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/TagHelperDescriptorCacheTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/TagHelperDescriptorCacheTest.cs @@ -2,11 +2,8 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System.Collections.Generic; -using System.Collections.Immutable; -using System.IO; using System.Linq; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Utilities; using Xunit; @@ -60,7 +57,7 @@ public class TagHelperDescriptorCacheTest(ITestOutputHelper testOutput) : TestBa // Reads 5 copies of the TagHelpers (with 5x references) for (var i = 0; i < 5; ++i) { - var tagHelpersBatch = ReadTagHelpers(); + var tagHelpersBatch = RazorTestResources.BlazorServerAppTagHelpers; tagHelpers.AddRange(tagHelpersBatch); tagHelpersPerBatch = tagHelpersBatch.Length; } @@ -77,7 +74,7 @@ public class TagHelperDescriptorCacheTest(ITestOutputHelper testOutput) : TestBa public void GetHashCode_AllTagHelpers_NoCacheIdCollisions() { // Arrange - var tagHelpers = ReadTagHelpers(); + var tagHelpers = RazorTestResources.BlazorServerAppTagHelpers; // Act var hashes = new HashSet(tagHelpers.Select(TagHelperDescriptorCache.GetTagHelperDescriptorCacheId)); @@ -85,16 +82,4 @@ public class TagHelperDescriptorCacheTest(ITestOutputHelper testOutput) : TestBa // Assert Assert.Equal(hashes.Count, tagHelpers.Length); } - - private static ImmutableArray ReadTagHelpers() - { - var bytes = RazorTestResources.GetResourceBytes(RazorTestResources.BlazorServerAppTagHelpersJson); - - using var stream = new MemoryStream(bytes); - using var reader = new StreamReader(stream); - - return JsonDataConvert.DeserializeData(reader, - static r => r.ReadImmutableArray( - static r => ObjectReaders.ReadTagHelper(r, useCache: false))); - } } From 16586ba87f1b37c0541aa462efd94cfbbe184304 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Mon, 28 Aug 2023 09:58:56 -0700 Subject: [PATCH 5/8] Separate ProjectRazorJson version between Json and MessagePack --- .../ProjectSystem/ProjectRazorJson.cs | 6 ------ .../Serialization/Json/ObjectReaders.cs | 10 +++++----- .../Serialization/Json/ObjectWriters.cs | 2 +- .../Serialization/Json/SerializationFormat.cs | 13 +++++++++++++ .../Serialization/MessagePack/ArgKind.cs | 2 +- .../Serialization/MessagePack/DocumentationKind.cs | 2 +- .../Formatters/ProjectRazorJsonFormatter.cs | 4 ++-- .../MessagePack/SerializationFormat.cs | 13 +++++++++++++ 8 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/SerializationFormat.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectRazorJson.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectRazorJson.cs index f25ec1d3b7..e10d449777 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectRazorJson.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectRazorJson.cs @@ -9,12 +9,6 @@ namespace Microsoft.AspNetCore.Razor.ProjectSystem; internal sealed class ProjectRazorJson { - // This version number must be incremented if the serialization format for ProjectRazorJson - // or any of the types that compose it changes. This includes: RazorConfiguration, - // ProjectWorkspaceState, TagHelperDescriptor, and DocumentSnapshotHandle. - // NOTE: If this version is changed, a coordinated insertion is required between Roslyn and Razor for the C# extension. - public const int Version = 2; - public string SerializedFilePath { get; } public string FilePath { get; } public RazorConfiguration? Configuration { get; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs index b848c5eff4..6a72fe0125 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs @@ -333,7 +333,7 @@ internal static partial class ObjectReaders public static ProjectRazorJson ReadProjectRazorJsonFromProperties(JsonDataReader reader) { - if (!reader.TryReadInt32(WellKnownPropertyNames.Version, out var version) || version != ProjectRazorJson.Version) + if (!reader.TryReadInt32(WellKnownPropertyNames.Version, out var version) || version != SerializationFormat.Version) { throw new ProjectRazorJsonSerializationException(SR.Unsupported_project_razor_json_version_encountered); } @@ -353,10 +353,10 @@ internal static partial class ObjectReaders public static Checksum ReadChecksumFromProperties(JsonDataReader reader) { - var data1 = reader.ReadInt64(); - var data2 = reader.ReadInt64(); - var data3 = reader.ReadInt64(); - var data4 = reader.ReadInt64(); + var data1 = reader.ReadInt64(nameof(Checksum.HashData.Data1)); + var data2 = reader.ReadInt64(nameof(Checksum.HashData.Data2)); + var data3 = reader.ReadInt64(nameof(Checksum.HashData.Data3)); + var data4 = reader.ReadInt64(nameof(Checksum.HashData.Data4)); var hashData = new Checksum.HashData(data1, data2, data3, data4); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs index 51e42222a0..0a9788f42a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs @@ -235,7 +235,7 @@ internal static class ObjectWriters public static void WriteProperties(JsonDataWriter writer, ProjectRazorJson value) { - writer.Write(WellKnownPropertyNames.Version, ProjectRazorJson.Version); + writer.Write(WellKnownPropertyNames.Version, SerializationFormat.Version); writer.Write(nameof(value.SerializedFilePath), value.SerializedFilePath); writer.Write(nameof(value.FilePath), value.FilePath); writer.WriteObject(nameof(value.Configuration), value.Configuration, WriteProperties); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/SerializationFormat.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/SerializationFormat.cs new file mode 100644 index 0000000000..829965e464 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/SerializationFormat.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Razor.Serialization.Json; + +internal static class SerializationFormat +{ + // This version number must be incremented if the serialization format for ProjectRazorJson + // or any of the types that compose it changes. This includes: RazorConfiguration, + // ProjectWorkspaceState, TagHelperDescriptor, and DocumentSnapshotHandle. + // NOTE: If this version is changed, a coordinated insertion is required between Roslyn and Razor for the C# extension. + public const int Version = 2; +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/ArgKind.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/ArgKind.cs index 646663eeb7..a54bd88567 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/ArgKind.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/ArgKind.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack; internal enum ArgKind { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/DocumentationKind.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/DocumentationKind.cs index 9bd23b63f3..d6ca105fb8 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/DocumentationKind.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/DocumentationKind.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.Serialization; +namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack; internal enum DocumentationKind { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs index 224291e8d2..c7e5c7cedc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs @@ -23,7 +23,7 @@ internal sealed class ProjectRazorJsonFormatter : MessagePackFormatter Date: Mon, 28 Aug 2023 10:30:12 -0700 Subject: [PATCH 6/8] Rename ProjectRazorJson to RazorProjectInfo --- .../CommonResources.cs | 8 +- ...RazorProjectInfoSerializationBenchmark.cs} | 38 +++--- .../PublicAPI.Unshipped.txt | 2 +- ...lizer.cs => RazorProjectInfoSerializer.cs} | 12 +- .../RazorWorkspaceListener.cs | 14 +-- ...ProjectConfigurationFileChangeEventArgs.cs | 22 ++-- .../ProjectConfigurationStateSynchronizer.cs | 44 +++---- ...rojectRazorJson.cs => RazorProjectInfo.cs} | 4 +- .../Resources/SR.resx | 4 +- .../Resources/xlf/SR.cs.xlf | 6 +- .../Resources/xlf/SR.de.xlf | 6 +- .../Resources/xlf/SR.es.xlf | 6 +- .../Resources/xlf/SR.fr.xlf | 6 +- .../Resources/xlf/SR.it.xlf | 6 +- .../Resources/xlf/SR.ja.xlf | 6 +- .../Resources/xlf/SR.ko.xlf | 6 +- .../Resources/xlf/SR.pl.xlf | 6 +- .../Resources/xlf/SR.pt-BR.xlf | 6 +- .../Resources/xlf/SR.ru.xlf | 6 +- .../Resources/xlf/SR.tr.xlf | 6 +- .../Resources/xlf/SR.zh-Hans.xlf | 6 +- .../Resources/xlf/SR.zh-Hant.xlf | 6 +- ...er.cs => RazorProjectInfoJsonConverter.cs} | 12 +- .../Json/JsonConverterCollectionExtensions.cs | 2 +- .../Serialization/Json/ObjectReaders.cs | 18 +-- .../Serialization/Json/ObjectWriters.cs | 4 +- ...matter.cs => RazorProjectInfoFormatter.cs} | 16 +-- ...esolver.cs => RazorProjectInfoResolver.cs} | 10 +- .../MessagePack/Resolvers/RazorResolvers.cs | 2 +- ...RazorProjectInfoSerializationException.cs} | 2 +- .../IProjectSnapshotExtensions.cs | 4 +- ...lisher.cs => RazorProjectInfoPublisher.cs} | 10 +- ...ectConfigurationFileChangeEventArgsTest.cs | 32 ++--- ...ojectConfigurationStateSynchronizerTest.cs | 118 +++++++++--------- .../SerializationTest.cs | 48 +++---- ...st.cs => RazorProjectInfoPublisherTest.cs} | 42 +++---- 36 files changed, 273 insertions(+), 273 deletions(-) rename src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/{ProjectRazorJsonSerializationBenchmark.cs => RazorProjectInfoSerializationBenchmark.cs} (55%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/{RazorProjectJsonSerializer.cs => RazorProjectInfoSerializer.cs} (95%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/{ProjectRazorJson.cs => RazorProjectInfo.cs} (94%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/{ProjectRazorJsonJsonConverter.cs => RazorProjectInfoJsonConverter.cs} (71%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/{ProjectRazorJsonFormatter.cs => RazorProjectInfoFormatter.cs} (73%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/{ProjectRazoJsonResolver.cs => RazorProjectInfoResolver.cs} (69%) rename src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/{ProjectRazorJsonSerializationException.cs => RazorProjectInfoSerializationException.cs} (79%) rename src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/{ProjectRazorJsonPublisher.cs => RazorProjectInfoPublisher.cs} (97%) rename src/Razor/test/Microsoft.VisualStudio.LanguageServerClient.Razor.Test/{ProjectRazorJsonPublisherTest.cs => RazorProjectInfoPublisherTest.cs} (95%) diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs index 1bfbc600d1..59cdd15af3 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs @@ -15,13 +15,13 @@ internal static class CommonResources public static readonly ImmutableArray LegacyTagHelpers = LoadTagHelpers(LegacyTagHelperBytes); public static readonly byte[] LegacyProjectRazorJsonBytes = Resources.GetResourceBytes("project.razor.json"); - public static readonly ProjectRazorJson LegacyProjectRazorJson = LoadProjectRazorJson(LegacyProjectRazorJsonBytes); + public static readonly RazorProjectInfo LegacyProjectInfo = LoadProjectInfo(LegacyProjectRazorJsonBytes); public static readonly byte[] TelerikTagHelperBytes = Resources.GetResourceBytes("Kendo.Mvc.Examples.taghelpers.json", folder: "Telerik"); public static readonly ImmutableArray TelerikTagHelpers = LoadTagHelpers(TelerikTagHelperBytes); public static readonly byte[] TelerikProjectRazorJsonBytes = Resources.GetResourceBytes("Kendo.Mvc.Examples.project.razor.json", folder: "Telerik"); - public static readonly ProjectRazorJson TelerikProjectRazorJson = LoadProjectRazorJson(TelerikProjectRazorJsonBytes); + public static readonly RazorProjectInfo TelerikProjectInfo = LoadProjectInfo(TelerikProjectRazorJsonBytes); private static ImmutableArray LoadTagHelpers(byte[] bytes) { @@ -33,12 +33,12 @@ internal static class CommonResources static r => ObjectReaders.ReadTagHelper(r, useCache: false))).NullToEmpty(); } - private static ProjectRazorJson LoadProjectRazorJson(byte[] bytes) + private static RazorProjectInfo LoadProjectInfo(byte[] bytes) { using var stream = new MemoryStream(bytes); using var reader = new StreamReader(stream); return JsonDataConvert.DeserializeData(reader, - static r => r.ReadNonNullObject(ObjectReaders.ReadProjectRazorJsonFromProperties)); + static r => r.ReadNonNullObject(ObjectReaders.ReadRazorProjectInfoFromProperties)); } } diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/ProjectRazorJsonSerializationBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/RazorProjectInfoSerializationBenchmark.cs similarity index 55% rename from src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/ProjectRazorJsonSerializationBenchmark.cs rename to src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/RazorProjectInfoSerializationBenchmark.cs index 03328f7b50..64e0d5fb76 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/ProjectRazorJsonSerializationBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/RazorProjectInfoSerializationBenchmark.cs @@ -9,16 +9,16 @@ using Microsoft.AspNetCore.Razor.Serialization.Json; namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Serialization; -public class ProjectRazorJsonSerializationBenchmark +public class RazorProjectInfoSerializationBenchmark { [ParamsAllValues] public ResourceSet ResourceSet { get; set; } - private ProjectRazorJson ProjectRazorJson + private RazorProjectInfo ProjectInfo => ResourceSet switch { - ResourceSet.Telerik => CommonResources.TelerikProjectRazorJson, - _ => CommonResources.LegacyProjectRazorJson + ResourceSet.Telerik => CommonResources.TelerikProjectInfo, + _ => CommonResources.LegacyProjectInfo }; private byte[] ProjectRazorJsonBytes @@ -28,58 +28,58 @@ public class ProjectRazorJsonSerializationBenchmark _ => CommonResources.LegacyProjectRazorJsonBytes }; - private static ProjectRazorJson DeserializeProjectRazorJson(TextReader reader) + private static RazorProjectInfo DeserializeProjectInfo(TextReader reader) { return JsonDataConvert.DeserializeData(reader, - static r => r.ReadNonNullObject(ObjectReaders.ReadProjectRazorJsonFromProperties)); + static r => r.ReadNonNullObject(ObjectReaders.ReadRazorProjectInfoFromProperties)); } - private static void SerializeProjectRazorJson(TextWriter writer, ProjectRazorJson projectRazorJson) + private static void SerializeProjectInfo(TextWriter writer, RazorProjectInfo projectInfo) { - JsonDataConvert.SerializeObject(writer, projectRazorJson, ObjectWriters.WriteProperties); + JsonDataConvert.SerializeObject(writer, projectInfo, ObjectWriters.WriteProperties); } - [Benchmark(Description = "Serialize ProjectRazorJson")] + [Benchmark(Description = "Serialize RazorProjectInfo")] public void Serialize() { using var stream = new MemoryStream(); using var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 4096); - SerializeProjectRazorJson(writer, ProjectRazorJson); + SerializeProjectInfo(writer, ProjectInfo); } - [Benchmark(Description = "Deserialize ProjectRazorJson")] + [Benchmark(Description = "Deserialize RazorProjectInfo")] public void Deserialize() { using var stream = new MemoryStream(ProjectRazorJsonBytes); using var reader = new StreamReader(stream); - var projectRazorJson = DeserializeProjectRazorJson(reader); + var projectInfo = DeserializeProjectInfo(reader); - if (projectRazorJson.ProjectWorkspaceState is null || - projectRazorJson.ProjectWorkspaceState.TagHelpers.Length != ProjectRazorJson.ProjectWorkspaceState?.TagHelpers.Length) + if (projectInfo.ProjectWorkspaceState is null || + projectInfo.ProjectWorkspaceState.TagHelpers.Length != ProjectInfo.ProjectWorkspaceState?.TagHelpers.Length) { throw new InvalidDataException(); } } - [Benchmark(Description = "RoundTrip ProjectRazorJson")] + [Benchmark(Description = "RoundTrip RazorProjectInfo")] public void RoundTrip() { using var stream = new MemoryStream(); using (var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 4096, leaveOpen: true)) { - SerializeProjectRazorJson(writer, ProjectRazorJson); + SerializeProjectInfo(writer, ProjectInfo); } stream.Seek(0, SeekOrigin.Begin); using var reader = new StreamReader(stream); - var projectRazorJson = DeserializeProjectRazorJson(reader); + var projectInfo = DeserializeProjectInfo(reader); - if (projectRazorJson.ProjectWorkspaceState is null || - projectRazorJson.ProjectWorkspaceState.TagHelpers.Length != ProjectRazorJson.ProjectWorkspaceState?.TagHelpers.Length) + if (projectInfo.ProjectWorkspaceState is null || + projectInfo.ProjectWorkspaceState.TagHelpers.Length != ProjectInfo.ProjectWorkspaceState?.TagHelpers.Length) { throw new InvalidDataException(); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/PublicAPI.Unshipped.txt b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/PublicAPI.Unshipped.txt index ae30bacad8..e62f368980 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/PublicAPI.Unshipped.txt +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/PublicAPI.Unshipped.txt @@ -1,7 +1,7 @@ #nullable enable Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.RazorWorkspaceListener Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.RazorWorkspaceListener.Dispose() -> void -Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.RazorWorkspaceListener.EnsureInitialized(Microsoft.CodeAnalysis.Workspace! workspace, string! projectRazorJsonFileName) -> void +Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.RazorWorkspaceListener.EnsureInitialized(Microsoft.CodeAnalysis.Workspace! workspace, string! projectInfoFileName) -> void Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.RazorWorkspaceListener.NotifyDynamicFile(Microsoft.CodeAnalysis.ProjectId! projectId) -> void Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.RazorWorkspaceListener.RazorWorkspaceListener(Microsoft.Extensions.Logging.ILoggerFactory! loggerFactory) -> void virtual Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.RazorWorkspaceListener.SerializeProjectAsync(Microsoft.CodeAnalysis.ProjectId! projectId, System.Threading.CancellationToken ct) -> System.Threading.Tasks.Task! \ No newline at end of file diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectJsonSerializer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs similarity index 95% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectJsonSerializer.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs index 33cbe9d8c2..5f12d19afa 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectJsonSerializer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs @@ -20,14 +20,14 @@ using Newtonsoft.Json; namespace Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace; -internal static class RazorProjectJsonSerializer +internal static class RazorProjectInfoSerializer { private static readonly JsonSerializer s_serializer; private static readonly EmptyProjectEngineFactory s_fallbackProjectEngineFactory; private static readonly StringComparison s_stringComparison; private static readonly (IProjectEngineFactory Value, ICustomProjectEngineFactoryMetadata)[] s_projectEngineFactories; - static RazorProjectJsonSerializer() + static RazorProjectInfoSerializer() { s_serializer = new JsonSerializer() { @@ -99,7 +99,7 @@ internal static class RazorProjectJsonSerializer var jsonFilePath = Path.Combine(intermediateOutputPath, projectRazorJsonFileName); - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( serializedFilePath: jsonFilePath, filePath: project.FilePath!, configuration: configuration, @@ -107,7 +107,7 @@ internal static class RazorProjectJsonSerializer projectWorkspaceState: projectWorkspaceState, documents: documents); - WriteJsonFile(jsonFilePath, projectRazorJson); + WriteJsonFile(jsonFilePath, projectInfo); } private static RazorConfiguration ComputeRazorConfigurationOptions(AnalyzerConfigOptionsProvider options, out string defaultNamespace) @@ -135,7 +135,7 @@ internal static class RazorProjectJsonSerializer return razorConfiguration; } - private static void WriteJsonFile(string publishFilePath, ProjectRazorJson projectRazorJson) + private static void WriteJsonFile(string publishFilePath, RazorProjectInfo projectInfo) { // We need to avoid having an incomplete file at any point, but our // project configuration is large enough that it will be written as multiple operations. @@ -152,7 +152,7 @@ internal static class RazorProjectJsonSerializer // by the time we move the temp file into its place using (var writer = tempFileInfo.CreateText()) { - s_serializer.Serialize(writer, projectRazorJson); + s_serializer.Serialize(writer, projectInfo); } var fileInfo = new FileInfo(publishFilePath); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorWorkspaceListener.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorWorkspaceListener.cs index 427a7a01ec..7f7b7aa919 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorWorkspaceListener.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorWorkspaceListener.cs @@ -13,7 +13,7 @@ public class RazorWorkspaceListener : IDisposable private readonly ILogger _logger; - private string? _projectRazorJsonFileName; + private string? _projectInfoFileName; private Workspace? _workspace; private ImmutableDictionary _workQueues = ImmutableDictionary.Empty; @@ -22,15 +22,15 @@ public class RazorWorkspaceListener : IDisposable _logger = loggerFactory.CreateLogger(nameof(RazorWorkspaceListener)); } - public void EnsureInitialized(Workspace workspace, string projectRazorJsonFileName) + public void EnsureInitialized(Workspace workspace, string projectInfoFileName) { // Make sure we don't hook up the event handler multiple times - if (_projectRazorJsonFileName is not null) + if (_projectInfoFileName is not null) { return; } - _projectRazorJsonFileName = projectRazorJsonFileName; + _projectInfoFileName = projectInfoFileName; _workspace = workspace; _workspace.WorkspaceChanged += Workspace_WorkspaceChanged; } @@ -140,7 +140,7 @@ public class RazorWorkspaceListener : IDisposable private void EnqueueUpdate(Project? project) { - if (_projectRazorJsonFileName is null || + if (_projectInfoFileName is null || project is not { Language: LanguageNames.CSharp @@ -161,7 +161,7 @@ public class RazorWorkspaceListener : IDisposable // Protected for testing protected virtual Task SerializeProjectAsync(ProjectId projectId, CancellationToken ct) { - if (_projectRazorJsonFileName is null || _workspace is null) + if (_projectInfoFileName is null || _workspace is null) { return Task.CompletedTask; } @@ -173,7 +173,7 @@ public class RazorWorkspaceListener : IDisposable } _logger.LogTrace("{projectId} writing json file", projectId); - return RazorProjectJsonSerializer.SerializeAsync(project, _projectRazorJsonFileName, ct); + return RazorProjectInfoSerializer.SerializeAsync(project, _projectInfoFileName, ct); } public void Dispose() diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs index e0c9038d7c..3c98f41626 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; internal class ProjectConfigurationFileChangeEventArgs { private readonly JsonFileDeserializer _jsonFileDeserializer; - private ProjectRazorJson? _projectRazorJson; + private RazorProjectInfo? _projectInfo; private readonly object _projectSnapshotHandleLock; private bool _deserialized; @@ -50,12 +50,12 @@ internal class ProjectConfigurationFileChangeEventArgs public RazorFileChangeKind Kind { get; } - public bool TryDeserialize([NotNullWhen(true)] out ProjectRazorJson? projectRazorJson) + public bool TryDeserialize([NotNullWhen(true)] out RazorProjectInfo? projectInfo) { if (Kind == RazorFileChangeKind.Removed) { // There's no file to represent the snapshot handle. - projectRazorJson = null; + projectInfo = null; return false; } @@ -66,31 +66,31 @@ internal class ProjectConfigurationFileChangeEventArgs // We use a deserialized flag instead of checking if _projectSnapshotHandle is null because if we're reading an old snapshot // handle that doesn't deserialize properly it could be expected that it would be null. _deserialized = true; - var deserializedProjectRazorJson = _jsonFileDeserializer.Deserialize(ConfigurationFilePath); - if (deserializedProjectRazorJson is null) + var deserializedProjectInfo = _jsonFileDeserializer.Deserialize(ConfigurationFilePath); + if (deserializedProjectInfo is null) { - projectRazorJson = null; + projectInfo = null; return false; } - var normalizedSerializedFilePath = FilePathNormalizer.Normalize(deserializedProjectRazorJson.SerializedFilePath); + var normalizedSerializedFilePath = FilePathNormalizer.Normalize(deserializedProjectInfo.SerializedFilePath); var normalizedDetectedFilePath = FilePathNormalizer.Normalize(ConfigurationFilePath); if (string.Equals(normalizedSerializedFilePath, normalizedDetectedFilePath, FilePathComparison.Instance)) { - _projectRazorJson = deserializedProjectRazorJson; + _projectInfo = deserializedProjectInfo; } else { // Stale project configuration file, most likely a user copy & pasted the project configuration file and it hasn't // been re-computed yet. Fail deserialization. - projectRazorJson = null; + projectInfo = null; return false; } } } - projectRazorJson = _projectRazorJson; - if (projectRazorJson is null) + projectInfo = _projectInfo; + if (projectInfo is null) { // Deserialization failed return false; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs index 27a181fbea..f28c3f0c49 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs @@ -52,7 +52,7 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile case RazorFileChangeKind.Changed: { var configurationFilePath = FilePathNormalizer.Normalize(args.ConfigurationFilePath); - if (!args.TryDeserialize(out var projectRazorJson)) + if (!args.TryDeserialize(out var projectInfo)) { if (!_configurationToProjectMap.TryGetValue(configurationFilePath, out var lastAssociatedProjectKey)) { @@ -68,7 +68,7 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile // We found the last associated project file for the configuration file. Reset the project since we can't // accurately determine its configurations. - EnqueueUpdateProject(lastAssociatedProjectKey, projectRazorJson: null); + EnqueueUpdateProject(lastAssociatedProjectKey, projectInfo: null); return; } @@ -76,19 +76,19 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile { _logger.LogWarning("Found no project key for configuration file. Assuming new project. Configuration file path: '{0}'", configurationFilePath); - AddProject(configurationFilePath, projectRazorJson); + AddProject(configurationFilePath, projectInfo); return; } _logger.LogInformation("Project configuration file changed for project '{0}': '{1}'", associatedProjectKey.Id, configurationFilePath); - EnqueueUpdateProject(associatedProjectKey, projectRazorJson); + EnqueueUpdateProject(associatedProjectKey, projectInfo); break; } case RazorFileChangeKind.Added: { var configurationFilePath = FilePathNormalizer.Normalize(args.ConfigurationFilePath); - if (!args.TryDeserialize(out var projectRazorJson)) + if (!args.TryDeserialize(out var projectInfo)) { // Given that this is the first time we're seeing this configuration file if we can't deserialize it // then we have to noop. @@ -96,7 +96,7 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile return; } - AddProject(configurationFilePath, projectRazorJson); + AddProject(configurationFilePath, projectInfo); break; } case RazorFileChangeKind.Removed: @@ -113,38 +113,38 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile _logger.LogInformation("Project configuration file removed for project '{0}': '{1}'", projectFilePath, configurationFilePath); - EnqueueUpdateProject(projectFilePath, projectRazorJson: null); + EnqueueUpdateProject(projectFilePath, projectInfo: null); break; } } - void AddProject(string configurationFilePath, ProjectRazorJson projectRazorJson) + void AddProject(string configurationFilePath, RazorProjectInfo projectInfo) { - var projectFilePath = FilePathNormalizer.Normalize(projectRazorJson.FilePath); + var projectFilePath = FilePathNormalizer.Normalize(projectInfo.FilePath); var intermediateOutputPath = Path.GetDirectoryName(configurationFilePath).AssumeNotNull(); - var rootNamespace = projectRazorJson.RootNamespace; + var rootNamespace = projectInfo.RootNamespace; - var projectKey = _projectService.AddProject(projectFilePath, intermediateOutputPath, projectRazorJson.Configuration, rootNamespace); + var projectKey = _projectService.AddProject(projectFilePath, intermediateOutputPath, projectInfo.Configuration, rootNamespace); _configurationToProjectMap[configurationFilePath] = projectKey; _logger.LogInformation("Project configuration file added for project '{0}': '{1}'", projectFilePath, configurationFilePath); - EnqueueUpdateProject(projectKey, projectRazorJson); + EnqueueUpdateProject(projectKey, projectInfo); } - void UpdateProject(ProjectKey projectKey, ProjectRazorJson? projectRazorJson) + void UpdateProject(ProjectKey projectKey, RazorProjectInfo? projectInfo) { - if (projectRazorJson is null) + if (projectInfo is null) { ResetProject(projectKey); return; } - var projectWorkspaceState = projectRazorJson.ProjectWorkspaceState ?? ProjectWorkspaceState.Default; - var documents = projectRazorJson.Documents; + var projectWorkspaceState = projectInfo.ProjectWorkspaceState ?? ProjectWorkspaceState.Default; + var documents = projectInfo.Documents; _projectService.UpdateProject( projectKey, - projectRazorJson.Configuration, - projectRazorJson.RootNamespace, + projectInfo.Configuration, + projectInfo.RootNamespace, projectWorkspaceState, documents); } @@ -154,10 +154,10 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile await Task.Delay(EnqueueDelay).ConfigureAwait(true); var delayedProjectInfo = ProjectInfoMap[projectKey]; - UpdateProject(projectKey, delayedProjectInfo.ProjectRazorJson); + UpdateProject(projectKey, delayedProjectInfo.ProjectInfo); } - void EnqueueUpdateProject(ProjectKey projectKey, ProjectRazorJson? projectRazorJson) + void EnqueueUpdateProject(ProjectKey projectKey, RazorProjectInfo? projectInfo) { if (!ProjectInfoMap.ContainsKey(projectKey)) { @@ -165,7 +165,7 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile } var delayedProjectInfo = ProjectInfoMap[projectKey]; - delayedProjectInfo.ProjectRazorJson = projectRazorJson; + delayedProjectInfo.ProjectInfo = projectInfo; if (delayedProjectInfo.ProjectUpdateTask is null || delayedProjectInfo.ProjectUpdateTask.IsCompleted) { @@ -188,6 +188,6 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile { public Task? ProjectUpdateTask { get; set; } - public ProjectRazorJson? ProjectRazorJson { get; set; } + public RazorProjectInfo? ProjectInfo { get; set; } } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectRazorJson.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs similarity index 94% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectRazorJson.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs index e10d449777..148a7b5a7a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectRazorJson.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Razor.Serialization; namespace Microsoft.AspNetCore.Razor.ProjectSystem; -internal sealed class ProjectRazorJson +internal sealed class RazorProjectInfo { public string SerializedFilePath { get; } public string FilePath { get; } @@ -16,7 +16,7 @@ internal sealed class ProjectRazorJson public ProjectWorkspaceState? ProjectWorkspaceState { get; } public ImmutableArray Documents { get; } - public ProjectRazorJson( + public RazorProjectInfo( string serializedFilePath, string filePath, RazorConfiguration? configuration, diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/SR.resx b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/SR.resx index 27c42adf26..d0c66ead4b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/SR.resx +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/SR.resx @@ -141,7 +141,7 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. + + Unsupported razor project info version encounted. \ No newline at end of file diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.cs.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.cs.xlf index 556584e4e1..bb9be7b9fb 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.cs.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.cs.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Byla zjištěna nepodporovaná verze project.razor.json. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.de.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.de.xlf index d735e645d6..bde347e219 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.de.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.de.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Nicht unterstützte Version von "project.razor.json" festgestellt. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.es.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.es.xlf index 3cc0fc8ebc..6b158941c5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.es.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.es.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Se encontró una versión de project.razor.json no admitida. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.fr.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.fr.xlf index 7353d924f5..5349a2aba2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.fr.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.fr.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Version de project.razor.json non prise en charge. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.it.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.it.xlf index 2a83d73260..4fe6a1b5c2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.it.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.it.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Incontrata versione project.razor.json non supportata. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ja.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ja.xlf index a9da0790b0..26a48b5a7b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ja.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ja.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - サポートされていない project.razor.json バージョンが検出されました。 + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ko.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ko.xlf index 026cd4db70..e3e4152c6b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ko.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ko.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - 지원되지 않는 project.razor.json 버전이 있음. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pl.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pl.xlf index 5d0118067b..bf8c83d66d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pl.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pl.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Napotkano nieobsługiwaną wersję pliku project.razor.json. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pt-BR.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pt-BR.xlf index cc99086fb9..2a04d17384 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pt-BR.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.pt-BR.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Versão project.razor.json sem suporte encontrada. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ru.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ru.xlf index 652bf0f648..17b8ae189d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ru.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.ru.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Обнаружена неподдерживаемая версия project.razor.json. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.tr.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.tr.xlf index 744bf149d5..f9af59b2e9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.tr.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.tr.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - Desteklenmeyen project.razor.json sürümü hesaplandı. + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hans.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hans.xlf index 5ea6fb4618..68cee91f4a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hans.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hans.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - 遇到不支持的 project.razor.json 版本。 + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hant.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hant.xlf index b363bc6b0e..9d21070428 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hant.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Resources/xlf/SR.zh-Hant.xlf @@ -42,9 +42,9 @@ Unsupported argument type: '{0}'. - - Unsupported project.razor.json version encounted. - 遇到不受支援的 project.razor.json 版本。 + + Unsupported razor project info version encounted. + Unsupported razor project info version encounted. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectRazorJsonJsonConverter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/RazorProjectInfoJsonConverter.cs similarity index 71% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectRazorJsonJsonConverter.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/RazorProjectInfoJsonConverter.cs index bc20eda461..d21f4e9e6f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/ProjectRazorJsonJsonConverter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/RazorProjectInfoJsonConverter.cs @@ -18,17 +18,17 @@ using Microsoft.AspNetCore.Razor.ProjectSystem; namespace Microsoft.AspNetCore.Razor.Serialization.Json.Converters; -internal class ProjectRazorJsonJsonConverter : ObjectJsonConverter +internal class RazorProjectInfoJsonConverter : ObjectJsonConverter { - public static readonly ProjectRazorJsonJsonConverter Instance = new(); + public static readonly RazorProjectInfoJsonConverter Instance = new(); - private ProjectRazorJsonJsonConverter() + private RazorProjectInfoJsonConverter() { } - protected override ProjectRazorJson ReadFromProperties(JsonDataReader reader) - => ObjectReaders.ReadProjectRazorJsonFromProperties(reader); + protected override RazorProjectInfo ReadFromProperties(JsonDataReader reader) + => ObjectReaders.ReadRazorProjectInfoFromProperties(reader); - protected override void WriteProperties(JsonDataWriter writer, ProjectRazorJson value) + protected override void WriteProperties(JsonDataWriter writer, RazorProjectInfo value) => ObjectWriters.WriteProperties(writer, value); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonConverterCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonConverterCollectionExtensions.cs index 6a758cab3e..6185bfb368 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonConverterCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/JsonConverterCollectionExtensions.cs @@ -15,7 +15,7 @@ internal static class JsonConverterCollectionExtensions new JsonConverter[] { ChecksumJsonConverter.Instance, - ProjectRazorJsonJsonConverter.Instance, + RazorProjectInfoJsonConverter.Instance, ProjectSnapshotHandleJsonConverter.Instance, TagHelperDeltaResultJsonConverter.Instance, }); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs index 6a72fe0125..47cccfabce 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectReaders.cs @@ -331,21 +331,21 @@ internal static partial class ObjectReaders } } - public static ProjectRazorJson ReadProjectRazorJsonFromProperties(JsonDataReader reader) + public static RazorProjectInfo ReadRazorProjectInfoFromProperties(JsonDataReader reader) { if (!reader.TryReadInt32(WellKnownPropertyNames.Version, out var version) || version != SerializationFormat.Version) { - throw new ProjectRazorJsonSerializationException(SR.Unsupported_project_razor_json_version_encountered); + throw new RazorProjectInfoSerializationException(SR.Unsupported_razor_project_info_version_encountered); } - var serializedFilePath = reader.ReadNonNullString(nameof(ProjectRazorJson.SerializedFilePath)); - var filePath = reader.ReadNonNullString(nameof(ProjectRazorJson.FilePath)); - var configuration = reader.ReadObject(nameof(ProjectRazorJson.Configuration), ReadConfigurationFromProperties); - var projectWorkspaceState = reader.ReadObject(nameof(ProjectRazorJson.ProjectWorkspaceState), ReadProjectWorkspaceStateFromProperties); - var rootNamespace = reader.ReadString(nameof(ProjectRazorJson.RootNamespace)); - var documents = reader.ReadImmutableArray(nameof(ProjectRazorJson.Documents), static r => r.ReadNonNullObject(ReadDocumentSnapshotHandleFromProperties)); + var serializedFilePath = reader.ReadNonNullString(nameof(RazorProjectInfo.SerializedFilePath)); + var filePath = reader.ReadNonNullString(nameof(RazorProjectInfo.FilePath)); + var configuration = reader.ReadObject(nameof(RazorProjectInfo.Configuration), ReadConfigurationFromProperties); + var projectWorkspaceState = reader.ReadObject(nameof(RazorProjectInfo.ProjectWorkspaceState), ReadProjectWorkspaceStateFromProperties); + var rootNamespace = reader.ReadString(nameof(RazorProjectInfo.RootNamespace)); + var documents = reader.ReadImmutableArray(nameof(RazorProjectInfo.Documents), static r => r.ReadNonNullObject(ReadDocumentSnapshotHandleFromProperties)); - return new ProjectRazorJson(serializedFilePath, filePath, configuration, rootNamespace, projectWorkspaceState, documents); + return new RazorProjectInfo(serializedFilePath, filePath, configuration, rootNamespace, projectWorkspaceState, documents); } public static Checksum ReadChecksum(JsonDataReader reader) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs index 0a9788f42a..fef69657f2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/ObjectWriters.cs @@ -230,10 +230,10 @@ internal static class ObjectWriters } } - public static void Write(JsonDataWriter writer, ProjectRazorJson value) + public static void Write(JsonDataWriter writer, RazorProjectInfo value) => writer.WriteObject(value, WriteProperties); - public static void WriteProperties(JsonDataWriter writer, ProjectRazorJson value) + public static void WriteProperties(JsonDataWriter writer, RazorProjectInfo value) { writer.Write(WellKnownPropertyNames.Version, SerializationFormat.Version); writer.Write(nameof(value.SerializedFilePath), value.SerializedFilePath); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorProjectInfoFormatter.cs similarity index 73% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorProjectInfoFormatter.cs index c7e5c7cedc..afdb71206c 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectRazorJsonFormatter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorProjectInfoFormatter.cs @@ -6,26 +6,26 @@ using Microsoft.AspNetCore.Razor.ProjectSystem; namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; -internal sealed class ProjectRazorJsonFormatter : MessagePackFormatter +internal sealed class RazorProjectInfoFormatter : MessagePackFormatter { - public static readonly MessagePackFormatter Instance = new ProjectRazorJsonFormatter(); + public static readonly MessagePackFormatter Instance = new RazorProjectInfoFormatter(); - private ProjectRazorJsonFormatter() + private RazorProjectInfoFormatter() { } - public override ProjectRazorJson Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + public override RazorProjectInfo Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.NextMessagePackType != MessagePackType.Integer) { - throw new ProjectRazorJsonSerializationException(SR.Unsupported_project_razor_json_version_encountered); + throw new RazorProjectInfoSerializationException(SR.Unsupported_razor_project_info_version_encountered); } var version = reader.ReadInt32(); if (version != SerializationFormat.Version) { - throw new ProjectRazorJsonSerializationException(SR.Unsupported_project_razor_json_version_encountered); + throw new RazorProjectInfoSerializationException(SR.Unsupported_razor_project_info_version_encountered); } var serializedFilePath = DeserializeString(ref reader, options); @@ -35,10 +35,10 @@ internal sealed class ProjectRazorJsonFormatter : MessagePackFormatter)ProjectRazorJsonFormatter.Instance; + Formatter = (IMessagePackFormatter)RazorProjectInfoFormatter.Instance; } } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/RazorResolvers.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/RazorResolvers.cs index 3e491054e9..6f3dcc7d29 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/RazorResolvers.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Resolvers/RazorResolvers.cs @@ -10,7 +10,7 @@ internal static class RazorResolvers { public static readonly IFormatterResolver All = CompositeResolver.Create( ChecksumResolver.Instance, - ProjectRazorJsonResolver.Instance, + RazorProjectInfoResolver.Instance, ProjectSnapshotHandleResolver.Instance, TagHelperDeltaResultResolver.Instance, StandardResolver.Instance); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ProjectRazorJsonSerializationException.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/RazorProjectInfoSerializationException.cs similarity index 79% rename from src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ProjectRazorJsonSerializationException.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/RazorProjectInfoSerializationException.cs index 3ee3ebcca4..44496b2162 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ProjectRazorJsonSerializationException.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/RazorProjectInfoSerializationException.cs @@ -5,6 +5,6 @@ using System; namespace Microsoft.AspNetCore.Razor.Serialization; -internal class ProjectRazorJsonSerializationException(string? message) : Exception(message) +internal class RazorProjectInfoSerializationException(string? message) : Exception(message) { } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs index 9b9dc8eb53..7854efbe44 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces.ProjectSystem; internal static class IProjectSnapshotExtensions { - public static ProjectRazorJson ToProjectRazorJson(this IProjectSnapshot project, string serializedFilePath) + public static RazorProjectInfo ToRazorProjectInfo(this IProjectSnapshot project, string serializedFilePath) { using var documents = new PooledArrayBuilder(); @@ -24,7 +24,7 @@ internal static class IProjectSnapshotExtensions } } - return new ProjectRazorJson( + return new RazorProjectInfo( serializedFilePath: serializedFilePath, filePath: project.FilePath, configuration: project.Configuration, diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/ProjectRazorJsonPublisher.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorProjectInfoPublisher.cs similarity index 97% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/ProjectRazorJsonPublisher.cs rename to src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorProjectInfoPublisher.cs index c7d9c961e1..c200835f82 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/ProjectRazorJsonPublisher.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorProjectInfoPublisher.cs @@ -22,7 +22,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor; /// [Shared] [Export(typeof(IProjectSnapshotChangeTrigger))] -internal class ProjectRazorJsonPublisher : IProjectSnapshotChangeTrigger +internal class RazorProjectInfoPublisher : IProjectSnapshotChangeTrigger { internal readonly Dictionary DeferredPublishTasks; @@ -54,7 +54,7 @@ internal class ProjectRazorJsonPublisher : IProjectSnapshotChangeTrigger } [ImportingConstructor] - public ProjectRazorJsonPublisher( + public RazorProjectInfoPublisher( LSPEditorFeatureDetector lSPEditorFeatureDetector, ProjectConfigurationFilePathStore projectConfigurationFilePathStore, RazorLogger logger) @@ -86,7 +86,7 @@ internal class ProjectRazorJsonPublisher : IProjectSnapshotChangeTrigger #if DEBUG _serializer.Formatting = Formatting.Indented; #endif - _serializer.Converters.Add(ProjectRazorJsonJsonConverter.Instance); + _serializer.Converters.Add(RazorProjectInfoJsonConverter.Instance); } // Internal settable for testing @@ -284,8 +284,8 @@ internal class ProjectRazorJsonPublisher : IProjectSnapshotChangeTrigger // by the time we move the tempfile into its place using (var writer = tempFileInfo.CreateText()) { - var projectRazorJson = projectSnapshot.ToProjectRazorJson(publishFilePath); - _serializer.Serialize(writer, projectRazorJson); + var projectInfo = projectSnapshot.ToRazorProjectInfo(publishFilePath); + _serializer.Serialize(writer, projectInfo); } var fileInfo = new FileInfo(publishFilePath); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs index 68e0de4840..5614184703 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs @@ -20,8 +20,8 @@ public class ProjectConfigurationFileChangeEventArgsTest(ITestOutputHelper testO { // Arrange var jsonFileDeserializer = new Mock(MockBehavior.Strict); - jsonFileDeserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) - .Returns(new ProjectRazorJson( + jsonFileDeserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) + .Returns(new RazorProjectInfo( "/path/to/obj/project.razor.json", "c:/path/to/project.csproj", configuration: null, @@ -44,23 +44,23 @@ public class ProjectConfigurationFileChangeEventArgsTest(ITestOutputHelper testO { // Arrange var jsonFileDeserializer = new Mock(MockBehavior.Strict); - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/ORIGINAL/obj/project.razor.json", "c:/path/to/project.csproj", configuration: null, rootNamespace: null, projectWorkspaceState: null, documents: ImmutableArray.Empty); - jsonFileDeserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) - .Returns(projectRazorJson); + jsonFileDeserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) + .Returns(projectInfo); var args = new ProjectConfigurationFileChangeEventArgs("/path/to/DIFFERENT/obj/project.razor.json", RazorFileChangeKind.Added, jsonFileDeserializer.Object); // Act - var result = args.TryDeserialize(out var deserializedProjectRazorJson); + var result = args.TryDeserialize(out var deserializedProjectInfo); // Assert Assert.False(result); - Assert.Null(deserializedProjectRazorJson); + Assert.Null(deserializedProjectInfo); } [Fact] @@ -68,26 +68,26 @@ public class ProjectConfigurationFileChangeEventArgsTest(ITestOutputHelper testO { // Arrange var jsonFileDeserializer = new Mock(MockBehavior.Strict); - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "c:/path/to/project.csproj", configuration: null, rootNamespace: null, projectWorkspaceState: null, documents: ImmutableArray.Empty); - jsonFileDeserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) - .Returns(projectRazorJson); + jsonFileDeserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) + .Returns(projectInfo); var args = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.json", RazorFileChangeKind.Added, jsonFileDeserializer.Object); // Act - var result1 = args.TryDeserialize(out var projectRazorJson1); - var result2 = args.TryDeserialize(out var projectRazorJson2); + var result1 = args.TryDeserialize(out var projectInfo1); + var result2 = args.TryDeserialize(out var projectInfo2); // Assert Assert.True(result1); Assert.True(result2); - Assert.Same(projectRazorJson, projectRazorJson1); - Assert.Same(projectRazorJson, projectRazorJson2); + Assert.Same(projectInfo, projectInfo1); + Assert.Same(projectInfo, projectInfo2); } [Fact] @@ -96,9 +96,9 @@ public class ProjectConfigurationFileChangeEventArgsTest(ITestOutputHelper testO // Arrange var jsonFileDeserializer = new Mock(MockBehavior.Strict); var callCount = 0; - jsonFileDeserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) + jsonFileDeserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) .Callback(() => callCount++) - .Returns(null); + .Returns(null); var args = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.json", RazorFileChangeKind.Changed, jsonFileDeserializer.Object); // Act diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs index 0bc7371cfb..96a2aeed69 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs @@ -51,24 +51,24 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase public async Task ProjectConfigurationFileChanged_Removed_NonNormalizedPaths() { // Arrange - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace", new ProjectWorkspaceState(ImmutableArray.Empty, LanguageVersion.CSharp5), ImmutableArray.Empty); - var intermediateOutputPath = Path.GetDirectoryName(projectRazorJson.SerializedFilePath); + var intermediateOutputPath = Path.GetDirectoryName(projectInfo.SerializedFilePath); var projectKey = TestProjectKey.Create(intermediateOutputPath); var projectService = new Mock(MockBehavior.Strict); - projectService.Setup(service => service.AddProject(projectRazorJson.FilePath, @"path\to\obj", projectRazorJson.Configuration, projectRazorJson.RootNamespace)) + projectService.Setup(service => service.AddProject(projectInfo.FilePath, @"path\to\obj", projectInfo.Configuration, projectInfo.RootNamespace)) .Returns(projectKey); projectService.Setup(service => service.UpdateProject( projectKey, - projectRazorJson.Configuration, - projectRazorJson.RootNamespace, - projectRazorJson.ProjectWorkspaceState, - projectRazorJson.Documents)).Verifiable(); + projectInfo.Configuration, + projectInfo.RootNamespace, + projectInfo.ProjectWorkspaceState, + projectInfo.Documents)).Verifiable(); projectService.Setup(service => service.UpdateProject( projectKey, null, @@ -76,7 +76,7 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase ProjectWorkspaceState.Default, ImmutableArray.Empty)).Verifiable(); var synchronizer = GetSynchronizer(projectService.Object); - var jsonFileDeserializer = CreateJsonFileDeserializer(projectRazorJson); + var jsonFileDeserializer = CreateJsonFileDeserializer(projectInfo); var addArgs = new ProjectConfigurationFileChangeEventArgs("/path/to\\obj/project.razor.json", RazorFileChangeKind.Added, jsonFileDeserializer); var enqueueTask = await Dispatcher.RunOnDispatcherThreadAsync(async () => { @@ -105,7 +105,7 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase // Arrange var projectService = new Mock(MockBehavior.Strict); var synchronizer = GetSynchronizer(projectService.Object); - var jsonFileDeserializer = Mock.Of(d => d.Deserialize(It.IsAny()) == null, MockBehavior.Strict); + var jsonFileDeserializer = Mock.Of(d => d.Deserialize(It.IsAny()) == null, MockBehavior.Strict); var args = new ProjectConfigurationFileChangeEventArgs("/path/to/project.razor.json", RazorFileChangeKind.Added, jsonFileDeserializer); // Act @@ -120,25 +120,25 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase public async Task ProjectConfigurationFileChanged_Added_AddAndUpdatesProject() { // Arrange - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace", new ProjectWorkspaceState(ImmutableArray.Empty, LanguageVersion.CSharp5), ImmutableArray.Empty); - var projectKey = TestProjectKey.Create(Path.GetDirectoryName(projectRazorJson.SerializedFilePath)); + var projectKey = TestProjectKey.Create(Path.GetDirectoryName(projectInfo.SerializedFilePath)); var projectService = new Mock(MockBehavior.Strict); - projectService.Setup(service => service.AddProject(projectRazorJson.FilePath, @"path\to\obj", projectRazorJson.Configuration, projectRazorJson.RootNamespace)) + projectService.Setup(service => service.AddProject(projectInfo.FilePath, @"path\to\obj", projectInfo.Configuration, projectInfo.RootNamespace)) .Returns(projectKey); projectService.Setup(service => service.UpdateProject( projectKey, - projectRazorJson.Configuration, - projectRazorJson.RootNamespace, - projectRazorJson.ProjectWorkspaceState, - projectRazorJson.Documents)).Verifiable(); + projectInfo.Configuration, + projectInfo.RootNamespace, + projectInfo.ProjectWorkspaceState, + projectInfo.Documents)).Verifiable(); var synchronizer = GetSynchronizer(projectService.Object); - var jsonFileDeserializer = CreateJsonFileDeserializer(projectRazorJson); + var jsonFileDeserializer = CreateJsonFileDeserializer(projectInfo); var args = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.json", RazorFileChangeKind.Added, jsonFileDeserializer); // Act @@ -157,23 +157,23 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase public async Task ProjectConfigurationFileChanged_Removed_ResetsProject() { // Arrange - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace", new ProjectWorkspaceState(ImmutableArray.Empty, LanguageVersion.CSharp5), ImmutableArray.Empty); - var projectKey = TestProjectKey.Create(Path.GetDirectoryName(projectRazorJson.SerializedFilePath)); + var projectKey = TestProjectKey.Create(Path.GetDirectoryName(projectInfo.SerializedFilePath)); var projectService = new Mock(MockBehavior.Strict); - projectService.Setup(service => service.AddProject(projectRazorJson.FilePath, @"path\to\obj", projectRazorJson.Configuration, projectRazorJson.RootNamespace)) + projectService.Setup(service => service.AddProject(projectInfo.FilePath, @"path\to\obj", projectInfo.Configuration, projectInfo.RootNamespace)) .Returns(projectKey); projectService.Setup(service => service.UpdateProject( projectKey, - projectRazorJson.Configuration, - projectRazorJson.RootNamespace, - projectRazorJson.ProjectWorkspaceState, - projectRazorJson.Documents)).Verifiable(); + projectInfo.Configuration, + projectInfo.RootNamespace, + projectInfo.ProjectWorkspaceState, + projectInfo.Documents)).Verifiable(); projectService.Setup(service => service.UpdateProject( projectKey, null, @@ -181,7 +181,7 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase ProjectWorkspaceState.Default, Array.Empty())).Verifiable(); var synchronizer = GetSynchronizer(projectService.Object); - var jsonFileDeserializer = CreateJsonFileDeserializer(projectRazorJson); + var jsonFileDeserializer = CreateJsonFileDeserializer(projectInfo); var addArgs = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.json", RazorFileChangeKind.Added, jsonFileDeserializer); var enqueueTask = await Dispatcher.RunOnDispatcherThreadAsync(async () => { @@ -208,24 +208,24 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase public async Task ProjectConfigurationFileChanged_Changed_UpdatesProject() { // Arrange - var initialProjectRazorJson = new ProjectRazorJson( + var initialProjectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace", new ProjectWorkspaceState(ImmutableArray.Empty, LanguageVersion.CSharp5), ImmutableArray.Empty); - var projectKey = TestProjectKey.Create(Path.GetDirectoryName(initialProjectRazorJson.SerializedFilePath)); + var projectKey = TestProjectKey.Create(Path.GetDirectoryName(initialProjectInfo.SerializedFilePath)); var projectService = new Mock(MockBehavior.Strict); - projectService.Setup(service => service.AddProject(initialProjectRazorJson.FilePath, @"path\to\obj", initialProjectRazorJson.Configuration, initialProjectRazorJson.RootNamespace)) + projectService.Setup(service => service.AddProject(initialProjectInfo.FilePath, @"path\to\obj", initialProjectInfo.Configuration, initialProjectInfo.RootNamespace)) .Returns(projectKey); projectService.Setup(service => service.UpdateProject( projectKey, - initialProjectRazorJson.Configuration, - initialProjectRazorJson.RootNamespace, - initialProjectRazorJson.ProjectWorkspaceState, - initialProjectRazorJson.Documents)).Verifiable(); - var changedProjectRazorJson = new ProjectRazorJson( + initialProjectInfo.Configuration, + initialProjectInfo.RootNamespace, + initialProjectInfo.ProjectWorkspaceState, + initialProjectInfo.Documents)).Verifiable(); + var changedProjectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "path/to/project.csproj", RazorConfiguration.Create( @@ -237,12 +237,12 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase ImmutableArray.Empty); projectService.Setup(service => service.UpdateProject( projectKey, - changedProjectRazorJson.Configuration, - changedProjectRazorJson.RootNamespace, - changedProjectRazorJson.ProjectWorkspaceState, - changedProjectRazorJson.Documents)).Verifiable(); + changedProjectInfo.Configuration, + changedProjectInfo.RootNamespace, + changedProjectInfo.ProjectWorkspaceState, + changedProjectInfo.Documents)).Verifiable(); var synchronizer = GetSynchronizer(projectService.Object); - var addDeserializer = CreateJsonFileDeserializer(initialProjectRazorJson); + var addDeserializer = CreateJsonFileDeserializer(initialProjectInfo); var addArgs = new ProjectConfigurationFileChangeEventArgs("path/to/obj/project.razor.json", RazorFileChangeKind.Added, addDeserializer); var enqueueTask = await Dispatcher.RunOnDispatcherThreadAsync(async () => @@ -252,7 +252,7 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase }, DisposalToken); await enqueueTask; - var changedDeserializer = CreateJsonFileDeserializer(changedProjectRazorJson); + var changedDeserializer = CreateJsonFileDeserializer(changedProjectInfo); var changedArgs = new ProjectConfigurationFileChangeEventArgs("path/to/obj/project.razor.json", RazorFileChangeKind.Changed, changedDeserializer); // Act @@ -271,24 +271,24 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase public async Task ProjectConfigurationFileChanged_Changed_CantDeserialize_ResetsProject() { // Arrange - var initialProjectRazorJson = new ProjectRazorJson( + var initialProjectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace", new ProjectWorkspaceState(ImmutableArray.Empty, LanguageVersion.CSharp5), ImmutableArray.Empty); - var projectKey = TestProjectKey.Create(Path.GetDirectoryName(initialProjectRazorJson.SerializedFilePath)); + var projectKey = TestProjectKey.Create(Path.GetDirectoryName(initialProjectInfo.SerializedFilePath)); var projectService = new Mock(MockBehavior.Strict); - projectService.Setup(service => service.AddProject(initialProjectRazorJson.FilePath, @"path\to\obj", initialProjectRazorJson.Configuration, initialProjectRazorJson.RootNamespace)) + projectService.Setup(service => service.AddProject(initialProjectInfo.FilePath, @"path\to\obj", initialProjectInfo.Configuration, initialProjectInfo.RootNamespace)) .Returns(projectKey); projectService.Setup(service => service.UpdateProject( projectKey, - initialProjectRazorJson.Configuration, - initialProjectRazorJson.RootNamespace, - initialProjectRazorJson.ProjectWorkspaceState, - initialProjectRazorJson.Documents)).Verifiable(); - var changedProjectRazorJson = new ProjectRazorJson( + initialProjectInfo.Configuration, + initialProjectInfo.RootNamespace, + initialProjectInfo.ProjectWorkspaceState, + initialProjectInfo.Documents)).Verifiable(); + var changedProjectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "path/to/project.csproj", RazorConfiguration.Create( @@ -307,7 +307,7 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase ProjectWorkspaceState.Default, Array.Empty())).Verifiable(); var synchronizer = GetSynchronizer(projectService.Object); - var addDeserializer = CreateJsonFileDeserializer(initialProjectRazorJson); + var addDeserializer = CreateJsonFileDeserializer(initialProjectInfo); var addArgs = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.json", RazorFileChangeKind.Added, addDeserializer); var enqueueTask = await Dispatcher.RunOnDispatcherThreadAsync(async () => { @@ -316,7 +316,7 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase }, DisposalToken); await enqueueTask; - var changedDeserializer = Mock.Of(d => d.Deserialize(It.IsAny()) == null, MockBehavior.Strict); + var changedDeserializer = Mock.Of(d => d.Deserialize(It.IsAny()) == null, MockBehavior.Strict); var changedArgs = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.json", RazorFileChangeKind.Changed, changedDeserializer); // Act @@ -337,7 +337,7 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase // Arrange var projectService = new Mock(MockBehavior.Strict); var synchronizer = GetSynchronizer(projectService.Object); - var changedDeserializer = Mock.Of(d => d.Deserialize(It.IsAny()) == null, MockBehavior.Strict); + var changedDeserializer = Mock.Of(d => d.Deserialize(It.IsAny()) == null, MockBehavior.Strict); var changedArgs = new ProjectConfigurationFileChangeEventArgs("/path/to/project.razor.json", RazorFileChangeKind.Changed, changedDeserializer); // Act @@ -356,16 +356,16 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase public async Task ProjectConfigurationFileChanged_RemoveThenAdd_OnlyAdds() { // Arrange - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace", new ProjectWorkspaceState(ImmutableArray.Empty, LanguageVersion.CSharp5), ImmutableArray.Empty); - var projectKey = TestProjectKey.Create(Path.GetDirectoryName(projectRazorJson.SerializedFilePath)); + var projectKey = TestProjectKey.Create(Path.GetDirectoryName(projectInfo.SerializedFilePath)); var projectService = new Mock(MockBehavior.Strict); - projectService.Setup(service => service.AddProject(projectRazorJson.FilePath, @"path\to\obj", projectRazorJson.Configuration, projectRazorJson.RootNamespace)) + projectService.Setup(service => service.AddProject(projectInfo.FilePath, @"path\to\obj", projectInfo.Configuration, projectInfo.RootNamespace)) .Returns(projectKey); projectService.Setup(p => p.UpdateProject( projectKey, @@ -375,10 +375,10 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase It.IsAny>())); var synchronizer = GetSynchronizer(projectService.Object); - var changedDeserializer = CreateJsonFileDeserializer(projectRazorJson); - var removedArgs = new ProjectConfigurationFileChangeEventArgs(projectRazorJson.SerializedFilePath, RazorFileChangeKind.Removed, changedDeserializer); - var addedArgs = new ProjectConfigurationFileChangeEventArgs(projectRazorJson.SerializedFilePath, RazorFileChangeKind.Added, changedDeserializer); - var changedArgs = new ProjectConfigurationFileChangeEventArgs(projectRazorJson.SerializedFilePath, RazorFileChangeKind.Changed, changedDeserializer); + var changedDeserializer = CreateJsonFileDeserializer(projectInfo); + var removedArgs = new ProjectConfigurationFileChangeEventArgs(projectInfo.SerializedFilePath, RazorFileChangeKind.Removed, changedDeserializer); + var addedArgs = new ProjectConfigurationFileChangeEventArgs(projectInfo.SerializedFilePath, RazorFileChangeKind.Added, changedDeserializer); + var changedArgs = new ProjectConfigurationFileChangeEventArgs(projectInfo.SerializedFilePath, RazorFileChangeKind.Changed, changedDeserializer); // Act var enqueueTask = await Dispatcher.RunOnDispatcherThreadAsync(async () => @@ -422,10 +422,10 @@ public class ProjectConfigurationStateSynchronizerTest : LanguageServerTestBase return synchronizer; } - private static JsonFileDeserializer CreateJsonFileDeserializer(ProjectRazorJson deserializedHandle) + private static JsonFileDeserializer CreateJsonFileDeserializer(RazorProjectInfo deserializedHandle) { var deserializer = new Mock(MockBehavior.Strict); - deserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) + deserializer.Setup(deserializer => deserializer.Deserialize(It.IsAny())) .Returns(deserializedHandle); return deserializer.Object; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs index 183eb87632..802dcc7966 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs @@ -38,10 +38,10 @@ public class SerializationTest : TestBase } [Fact] - public void ProjectRazorJson_InvalidVersionThrows() + public void RazorProjectInfo_InvalidVersionThrows() { // Arrange - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "/path/to/project.csproj", _configuration, @@ -49,7 +49,7 @@ public class SerializationTest : TestBase _projectWorkspaceState, ImmutableArray.Empty); - var jsonText = JsonConvert.SerializeObject(projectRazorJson, ProjectRazorJsonJsonConverter.Instance); + var jsonText = JsonConvert.SerializeObject(projectInfo, RazorProjectInfoJsonConverter.Instance); Assert.NotNull(jsonText); var serializedJObject = JObject.Parse(jsonText); @@ -59,21 +59,21 @@ public class SerializationTest : TestBase Assert.NotNull(updatedJsonText); // Act - ProjectRazorJson? deserializedProjectRazorJson = null; - Assert.Throws(() => + RazorProjectInfo? deserializedProjectInfo = null; + Assert.Throws(() => { - deserializedProjectRazorJson = JsonConvert.DeserializeObject(updatedJsonText, ProjectRazorJsonJsonConverter.Instance); + deserializedProjectInfo = JsonConvert.DeserializeObject(updatedJsonText, RazorProjectInfoJsonConverter.Instance); }); // Assert - Assert.Null(deserializedProjectRazorJson); + Assert.Null(deserializedProjectInfo); } [Fact] - public void ProjectRazorJson_MissingVersionThrows() + public void RazorProjectInfo_MissingVersionThrows() { // Arrange - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "/path/to/project.csproj", _configuration, @@ -81,7 +81,7 @@ public class SerializationTest : TestBase _projectWorkspaceState, ImmutableArray.Empty); - var jsonText = JsonConvert.SerializeObject(projectRazorJson, ProjectRazorJsonJsonConverter.Instance); + var jsonText = JsonConvert.SerializeObject(projectInfo, RazorProjectInfoJsonConverter.Instance); Assert.NotNull(jsonText); var serializedJObject = JObject.Parse(jsonText); @@ -91,23 +91,23 @@ public class SerializationTest : TestBase Assert.NotNull(updatedJsonText); // Act - ProjectRazorJson? deserializedProjectRazorJson = null; - Assert.Throws(() => + RazorProjectInfo? deserializedProjectInfo = null; + Assert.Throws(() => { - deserializedProjectRazorJson = JsonConvert.DeserializeObject(updatedJsonText, ProjectRazorJsonJsonConverter.Instance); + deserializedProjectInfo = JsonConvert.DeserializeObject(updatedJsonText, RazorProjectInfoJsonConverter.Instance); }); // Assert - Assert.Null(deserializedProjectRazorJson); + Assert.Null(deserializedProjectInfo); } [Fact] - public void ProjectRazorJson_CanRoundTrip() + public void RazorProjectInfo_CanRoundTrip() { // Arrange var legacyDocument = new DocumentSnapshotHandle("/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy); var componentDocument = new DocumentSnapshotHandle("/path/to/otherfile.razor", "otherfile.razor", FileKinds.Component); - var projectRazorJson = new ProjectRazorJson( + var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.json", "/path/to/project.csproj", _configuration, @@ -115,19 +115,19 @@ public class SerializationTest : TestBase _projectWorkspaceState, ImmutableArray.Create(legacyDocument, componentDocument)); - var jsonText = JsonConvert.SerializeObject(projectRazorJson, ProjectRazorJsonJsonConverter.Instance); + var jsonText = JsonConvert.SerializeObject(projectInfo, RazorProjectInfoJsonConverter.Instance); Assert.NotNull(jsonText); // Act - var deserializedProjectRazorJson = JsonConvert.DeserializeObject(jsonText, ProjectRazorJsonJsonConverter.Instance); - Assert.NotNull(deserializedProjectRazorJson); + var deserializedProjectInfo = JsonConvert.DeserializeObject(jsonText, RazorProjectInfoJsonConverter.Instance); + Assert.NotNull(deserializedProjectInfo); // Assert - Assert.Equal(projectRazorJson.FilePath, deserializedProjectRazorJson.FilePath); - Assert.Equal(projectRazorJson.Configuration, deserializedProjectRazorJson.Configuration); - Assert.Equal(projectRazorJson.RootNamespace, deserializedProjectRazorJson.RootNamespace); - Assert.Equal(projectRazorJson.ProjectWorkspaceState, deserializedProjectRazorJson.ProjectWorkspaceState); - Assert.Collection(projectRazorJson.Documents.OrderBy(doc => doc.FilePath), + Assert.Equal(projectInfo.FilePath, deserializedProjectInfo.FilePath); + Assert.Equal(projectInfo.Configuration, deserializedProjectInfo.Configuration); + Assert.Equal(projectInfo.RootNamespace, deserializedProjectInfo.RootNamespace); + Assert.Equal(projectInfo.ProjectWorkspaceState, deserializedProjectInfo.ProjectWorkspaceState); + Assert.Collection(projectInfo.Documents.OrderBy(doc => doc.FilePath), document => { Assert.Equal(legacyDocument.FilePath, document.FilePath); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServerClient.Razor.Test/ProjectRazorJsonPublisherTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServerClient.Razor.Test/RazorProjectInfoPublisherTest.cs similarity index 95% rename from src/Razor/test/Microsoft.VisualStudio.LanguageServerClient.Razor.Test/ProjectRazorJsonPublisherTest.cs rename to src/Razor/test/Microsoft.VisualStudio.LanguageServerClient.Razor.Test/RazorProjectInfoPublisherTest.cs index 27d7247307..9a69eb1b1e 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServerClient.Razor.Test/ProjectRazorJsonPublisherTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServerClient.Razor.Test/RazorProjectInfoPublisherTest.cs @@ -20,12 +20,12 @@ using Xunit.Sdk; namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Test; -public class ProjectRazorJsonPublisherTest : LanguageServerTestBase +public class RazorProjectInfoPublisherTest : LanguageServerTestBase { private readonly ProjectSnapshotManagerBase _projectSnapshotManager; private readonly ProjectConfigurationFilePathStore _projectConfigurationFilePathStore; - public ProjectRazorJsonPublisherTest(ITestOutputHelper testOutput) + public RazorProjectInfoPublisherTest(ITestOutputHelper testOutput) : base(testOutput) { _projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true); @@ -45,7 +45,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var initialProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(tagHelpers, CodeAnalysis.CSharp.LanguageVersion.Preview)); var expectedProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray.Empty, CodeAnalysis.CSharp.LanguageVersion.Preview)); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -80,7 +80,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var hostProject = new HostProject(@"C:\path\to\project.csproj", @"C:\path\to\obj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace"); var hostDocument = new HostDocument(@"C:\path\to\file.razor", "file.razor"); _projectSnapshotManager.ProjectAdded(hostProject); - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true) { @@ -105,7 +105,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var hostDocument = new HostDocument(@"C:\path\to\file.razor", "file.razor"); _projectSnapshotManager.ProjectAdded(hostProject); _projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath)); - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true) { @@ -134,7 +134,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var projectSnapshot = _projectSnapshotManager.GetProjects()[0]; var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; _projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath); - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -164,7 +164,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var serializationSuccessful = false; var projectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray.Empty, CodeAnalysis.CSharp.LanguageVersion.CSharp7_3)); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -198,7 +198,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var changedProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray.Empty, CodeAnalysis.CSharp.LanguageVersion.CSharp8)); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; var aboutToChange = false; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -243,7 +243,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var attemptedToSerialize = false; var projectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj"); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true) { @@ -273,7 +273,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var firstSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj"); var secondSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new[] { @"C:\path\to\file.cshtml" }); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -306,7 +306,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var firstSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj"); var secondSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new[] { @"C:\path\to\file.cshtml" }); var expectedConfigurationFilePath = @"C:\path\to\objbin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -345,7 +345,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase "FileName.razor" }); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -374,7 +374,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase public void Publish_UnsetConfigurationFilePath_Noops() { // Arrange - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore) { _active = true, @@ -393,7 +393,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var serializationSuccessful = false; var omniSharpProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj"); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -421,7 +421,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var serializationSuccessful = false; var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -455,7 +455,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var serializationSuccessful = false; var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -482,7 +482,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase public async Task ProjectRemoved_UnSetPublishFilePath_NoopsAsync() { // Arrange - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore) { _active = true, @@ -504,7 +504,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase var serializationSuccessful = false; var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; - var publisher = new TestProjectRazorJsonPublisher( + var publisher = new TestRazorProjectInfoPublisher( _projectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { @@ -574,7 +574,7 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase func, DisposalToken); - private class TestProjectRazorJsonPublisher : ProjectRazorJsonPublisher + private class TestRazorProjectInfoPublisher : RazorProjectInfoPublisher { private static readonly Mock s_lspEditorFeatureDetector = new(MockBehavior.Strict); @@ -583,14 +583,14 @@ public class ProjectRazorJsonPublisherTest : LanguageServerTestBase private readonly bool _shouldSerialize; private readonly bool _useRealShouldSerialize; - static TestProjectRazorJsonPublisher() + static TestRazorProjectInfoPublisher() { s_lspEditorFeatureDetector .Setup(t => t.IsLSPEditorAvailable()) .Returns(true); } - public TestProjectRazorJsonPublisher( + public TestRazorProjectInfoPublisher( ProjectConfigurationFilePathStore projectStatePublishFilePathStore, Action onSerializeToFile = null, bool shouldSerialize = true, From 81397e48553b49a8e97914ca4fe682e849e86545 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Mon, 28 Aug 2023 10:48:12 -0700 Subject: [PATCH 7/8] Rework serialization benchmarks to run both JSON and Message Pack --- .../CommonResources.cs | 16 +- .../RazorProjectInfoSerializationBenchmark.cs | 93 +++++-- .../TagHelperSerializationBenchmark.cs | 108 ++++++-- .../ArrayBufferWriter`1.cs | 251 ++++++++++++++++++ .../Resources/SR.resx | 62 +++-- .../Resources/xlf/SR.cs.xlf | 10 + .../Resources/xlf/SR.de.xlf | 10 + .../Resources/xlf/SR.es.xlf | 10 + .../Resources/xlf/SR.fr.xlf | 10 + .../Resources/xlf/SR.it.xlf | 10 + .../Resources/xlf/SR.ja.xlf | 10 + .../Resources/xlf/SR.ko.xlf | 10 + .../Resources/xlf/SR.pl.xlf | 10 + .../Resources/xlf/SR.pt-BR.xlf | 10 + .../Resources/xlf/SR.ru.xlf | 10 + .../Resources/xlf/SR.tr.xlf | 10 + .../Resources/xlf/SR.zh-Hans.xlf | 10 + .../Resources/xlf/SR.zh-Hant.xlf | 10 + 18 files changed, 583 insertions(+), 77 deletions(-) create mode 100644 src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/ArrayBufferWriter`1.cs diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs index 59cdd15af3..4e0c8c1691 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/CommonResources.cs @@ -11,17 +11,17 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks; internal static class CommonResources { - public static readonly byte[] LegacyTagHelperBytes = Resources.GetResourceBytes("taghelpers.json"); - public static readonly ImmutableArray LegacyTagHelpers = LoadTagHelpers(LegacyTagHelperBytes); + public static readonly byte[] LegacyTagHelperJsonBytes = Resources.GetResourceBytes("taghelpers.json"); + public static readonly ImmutableArray LegacyTagHelpers = LoadTagHelpers(LegacyTagHelperJsonBytes); - public static readonly byte[] LegacyProjectRazorJsonBytes = Resources.GetResourceBytes("project.razor.json"); - public static readonly RazorProjectInfo LegacyProjectInfo = LoadProjectInfo(LegacyProjectRazorJsonBytes); + public static readonly byte[] LegacyProjectInfoJsonBytes = Resources.GetResourceBytes("project.razor.json"); + public static readonly RazorProjectInfo LegacyProjectInfo = LoadProjectInfo(LegacyProjectInfoJsonBytes); - public static readonly byte[] TelerikTagHelperBytes = Resources.GetResourceBytes("Kendo.Mvc.Examples.taghelpers.json", folder: "Telerik"); - public static readonly ImmutableArray TelerikTagHelpers = LoadTagHelpers(TelerikTagHelperBytes); + public static readonly byte[] TelerikTagHelperJsonBytes = Resources.GetResourceBytes("Kendo.Mvc.Examples.taghelpers.json", folder: "Telerik"); + public static readonly ImmutableArray TelerikTagHelpers = LoadTagHelpers(TelerikTagHelperJsonBytes); - public static readonly byte[] TelerikProjectRazorJsonBytes = Resources.GetResourceBytes("Kendo.Mvc.Examples.project.razor.json", folder: "Telerik"); - public static readonly RazorProjectInfo TelerikProjectInfo = LoadProjectInfo(TelerikProjectRazorJsonBytes); + public static readonly byte[] TelerikProjectInfoJsonBytes = Resources.GetResourceBytes("Kendo.Mvc.Examples.project.razor.json", folder: "Telerik"); + public static readonly RazorProjectInfo TelerikProjectInfo = LoadProjectInfo(TelerikProjectInfoJsonBytes); private static ImmutableArray LoadTagHelpers(byte[] bytes) { diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/RazorProjectInfoSerializationBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/RazorProjectInfoSerializationBenchmark.cs index 64e0d5fb76..00937ba54d 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/RazorProjectInfoSerializationBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/RazorProjectInfoSerializationBenchmark.cs @@ -1,16 +1,22 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. +using System.Buffers; +using System; using System.IO; using System.Text; using BenchmarkDotNet.Attributes; +using MessagePack; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Serialization.Json; +using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Serialization; public class RazorProjectInfoSerializationBenchmark { + private ReadOnlyMemory _projectInfoMessagePackBytes; + [ParamsAllValues] public ResourceSet ResourceSet { get; set; } @@ -21,40 +27,40 @@ public class RazorProjectInfoSerializationBenchmark _ => CommonResources.LegacyProjectInfo }; - private byte[] ProjectRazorJsonBytes + private byte[] ProjectInfoJsonBytes => ResourceSet switch { - ResourceSet.Telerik => CommonResources.TelerikProjectRazorJsonBytes, - _ => CommonResources.LegacyProjectRazorJsonBytes + ResourceSet.Telerik => CommonResources.TelerikProjectInfoJsonBytes, + _ => CommonResources.LegacyProjectInfoJsonBytes }; - private static RazorProjectInfo DeserializeProjectInfo(TextReader reader) + private static RazorProjectInfo DeserializeProjectInfo_Json(TextReader reader) { return JsonDataConvert.DeserializeData(reader, static r => r.ReadNonNullObject(ObjectReaders.ReadRazorProjectInfoFromProperties)); } - private static void SerializeProjectInfo(TextWriter writer, RazorProjectInfo projectInfo) + private static void SerializeProjectInfo_Json(TextWriter writer, RazorProjectInfo projectInfo) { JsonDataConvert.SerializeObject(writer, projectInfo, ObjectWriters.WriteProperties); } - [Benchmark(Description = "Serialize RazorProjectInfo")] - public void Serialize() + [Benchmark(Description = "Serialize RazorProjectInfo (JSON)")] + public void Serialize_Json() { using var stream = new MemoryStream(); using var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 4096); - SerializeProjectInfo(writer, ProjectInfo); + SerializeProjectInfo_Json(writer, ProjectInfo); } - [Benchmark(Description = "Deserialize RazorProjectInfo")] - public void Deserialize() + [Benchmark(Description = "Deserialize RazorProjectInfo (JSON)")] + public void Deserialize_Json() { - using var stream = new MemoryStream(ProjectRazorJsonBytes); + using var stream = new MemoryStream(ProjectInfoJsonBytes); using var reader = new StreamReader(stream); - var projectInfo = DeserializeProjectInfo(reader); + var projectInfo = DeserializeProjectInfo_Json(reader); if (projectInfo.ProjectWorkspaceState is null || projectInfo.ProjectWorkspaceState.TagHelpers.Length != ProjectInfo.ProjectWorkspaceState?.TagHelpers.Length) @@ -63,20 +69,75 @@ public class RazorProjectInfoSerializationBenchmark } } - [Benchmark(Description = "RoundTrip RazorProjectInfo")] - public void RoundTrip() + [Benchmark(Description = "RoundTrip RazorProjectInfo (JSON)")] + public void RoundTrip_Json() { using var stream = new MemoryStream(); using (var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 4096, leaveOpen: true)) { - SerializeProjectInfo(writer, ProjectInfo); + SerializeProjectInfo_Json(writer, ProjectInfo); } stream.Seek(0, SeekOrigin.Begin); using var reader = new StreamReader(stream); - var projectInfo = DeserializeProjectInfo(reader); + var projectInfo = DeserializeProjectInfo_Json(reader); + + if (projectInfo.ProjectWorkspaceState is null || + projectInfo.ProjectWorkspaceState.TagHelpers.Length != ProjectInfo.ProjectWorkspaceState?.TagHelpers.Length) + { + throw new InvalidDataException(); + } + } + + [GlobalSetup(Targets = new[] { nameof(Serialize_MessagePack), nameof(Deserialize_MessagePack), nameof(RoundTrip_MessagePack) })] + public void GlobalSetup_MessagePack() + { + _projectInfoMessagePackBytes = SerializeProjectInfo_MessagePack(ProjectInfo); + } + + private static RazorProjectInfo DeserializeProjectInfo_MessagePack(ReadOnlyMemory bytes) + { + var reader = new MessagePackReader(bytes); + + return RazorProjectInfoFormatter.Instance.Deserialize(ref reader, MessagePackSerializerOptions.Standard); + } + + private static ReadOnlyMemory SerializeProjectInfo_MessagePack(RazorProjectInfo projectInfo) + { + var buffer = new ArrayBufferWriter(); + var writer = new MessagePackWriter(buffer); + + RazorProjectInfoFormatter.Instance.Serialize(ref writer, projectInfo, MessagePackSerializerOptions.Standard); + writer.Flush(); + + return buffer.WrittenMemory; + } + + [Benchmark(Description = "Serialize ProjectRazorJson (MessagePack)")] + public void Serialize_MessagePack() + { + SerializeProjectInfo_MessagePack(ProjectInfo); + } + + [Benchmark(Description = "Deserialize ProjectRazorJson (MessagePack)")] + public void Deserialize_MessagePack() + { + var projectInfo = DeserializeProjectInfo_MessagePack(_projectInfoMessagePackBytes); + + if (projectInfo.ProjectWorkspaceState is null || + projectInfo.ProjectWorkspaceState.TagHelpers.Length != ProjectInfo.ProjectWorkspaceState?.TagHelpers.Length) + { + throw new InvalidDataException(); + } + } + + [Benchmark(Description = "RoundTrip ProjectRazorJson (MessagePack)")] + public void RoundTrip_MessagePack() + { + var bytes = SerializeProjectInfo_MessagePack(ProjectInfo); + var projectInfo = DeserializeProjectInfo_MessagePack(bytes); if (projectInfo.ProjectWorkspaceState is null || projectInfo.ProjectWorkspaceState.TagHelpers.Length != ProjectInfo.ProjectWorkspaceState?.TagHelpers.Length) diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/TagHelperSerializationBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/TagHelperSerializationBenchmark.cs index 5a9628408c..e67a56e372 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/TagHelperSerializationBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/TagHelperSerializationBenchmark.cs @@ -2,50 +2,58 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; -using System.Collections.Generic; +using System.Buffers; +using System.Collections.Immutable; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text; using BenchmarkDotNet.Attributes; +using MessagePack; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Serialization.Json; +using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Serialization; public class TagHelperSerializationBenchmark { + [AllowNull] + private ArrayBufferWriter _buffer; + private ReadOnlyMemory _tagHelperMessagePackBytes; + [ParamsAllValues] public ResourceSet ResourceSet { get; set; } - private IReadOnlyList TagHelpers + private ImmutableArray TagHelpers => ResourceSet switch { ResourceSet.Telerik => CommonResources.TelerikTagHelpers, _ => CommonResources.LegacyTagHelpers }; - private byte[] TagHelperBytes + private byte[] TagHelperJsonBytes => ResourceSet switch { - ResourceSet.Telerik => CommonResources.TelerikTagHelperBytes, - _ => CommonResources.LegacyTagHelperBytes + ResourceSet.Telerik => CommonResources.TelerikTagHelperJsonBytes, + _ => CommonResources.LegacyTagHelperJsonBytes }; - private static IReadOnlyList DeserializeTagHelpers(TextReader reader) + private static ImmutableArray DeserializeTagHelpers_Json(TextReader reader) { return JsonDataConvert.DeserializeData(reader, - static r => r.ReadArray( - static r => ObjectReaders.ReadTagHelper(r, useCache: false))) - ?? Array.Empty(); + static r => r.ReadImmutableArray( + static r => ObjectReaders.ReadTagHelper(r, useCache: false))); } - private static void SerializeTagHelpers(TextWriter writer, IReadOnlyList tagHelpers) + private static void SerializeTagHelpers(TextWriter writer, ImmutableArray tagHelpers) { JsonDataConvert.SerializeData(writer, w => w.WriteArray(tagHelpers, ObjectWriters.Write)); } - [Benchmark(Description = "Serialize Tag Helpers")] - public void Serialize() + [Benchmark(Description = "Serialize Tag Helpers (JSON)")] + public void Serialize_Json() { using var stream = new MemoryStream(); using var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 4096); @@ -53,22 +61,22 @@ public class TagHelperSerializationBenchmark SerializeTagHelpers(writer, TagHelpers); } - [Benchmark(Description = "Deserialize Tag Helpers")] - public void Deserialize() + [Benchmark(Description = "Deserialize Tag Helpers (JSON)")] + public void Deserialize_Json() { - using var stream = new MemoryStream(TagHelperBytes); + using var stream = new MemoryStream(TagHelperJsonBytes); using var reader = new StreamReader(stream); - var tagHelpers = DeserializeTagHelpers(reader); + var tagHelpers = DeserializeTagHelpers_Json(reader); - if (tagHelpers.Count != TagHelpers.Count) + if (tagHelpers.Length != TagHelpers.Length) { throw new InvalidDataException(); } } - [Benchmark(Description = "RoundTrip Tag Helpers")] - public void RoundTrip() + [Benchmark(Description = "RoundTrip Tag Helpers (JSON)")] + public void RoundTrip_Json() { using var stream = new MemoryStream(); using (var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 4096, leaveOpen: true)) @@ -80,20 +88,70 @@ public class TagHelperSerializationBenchmark using var reader = new StreamReader(stream); - var tagHelpers = DeserializeTagHelpers(reader); + var tagHelpers = DeserializeTagHelpers_Json(reader); - if (tagHelpers.Count != TagHelpers.Count) + if (tagHelpers.Length != TagHelpers.Length) { throw new InvalidDataException(); } } - [Benchmark(Description = "TagHelperDescriptor.GetHashCode()")] - public void TagHelperDescriptor_GetHashCode() + [GlobalSetup(Targets = new[] { nameof(Serialize_MessagePack), nameof(Deserialize_MessagePack), nameof(RoundTrip_MessagePack) })] + public void GlobalSetup_MessagePack() { - foreach (var tagHelper in TagHelpers) + _buffer = new ArrayBufferWriter(initialCapacity: 1024 * 1024); + _tagHelperMessagePackBytes = SerializeTagHelpers_MessagePack(TagHelpers); + } + + private static ImmutableArray DeserializeTagHelpers_MessagePack(ReadOnlyMemory bytes) + { + var reader = new MessagePackReader(bytes); + + using var _ = TagHelperSerializationCache.Pool.GetPooledObject(out var cache); + return TagHelperFormatter.Instance.DeserializeImmutableArray(ref reader, MessagePackSerializerOptions.Standard, cache); + } + + private ReadOnlyMemory SerializeTagHelpers_MessagePack(ImmutableArray tagHelpers) + { + var writer = new MessagePackWriter(_buffer); + + using var _ = TagHelperSerializationCache.Pool.GetPooledObject(out var cache); + + TagHelperFormatter.Instance.SerializeArray(ref writer, tagHelpers, MessagePackSerializerOptions.Standard, cache); + writer.Flush(); + + return _buffer.WrittenMemory; + } + + [Benchmark(Description = "Serialize Tag Helpers (MessagePack)")] + public void Serialize_MessagePack() + { + SerializeTagHelpers_MessagePack(TagHelpers); + _buffer.Clear(); + } + + [Benchmark(Description = "Deserialize Tag Helpers (MessagePack)")] + public void Deserialize_MessagePack() + { + var tagHelpers = DeserializeTagHelpers_MessagePack(_tagHelperMessagePackBytes); + + if (tagHelpers.Length != TagHelpers.Length) { - _ = tagHelper.GetHashCode(); + throw new InvalidDataException(); } } + + [Benchmark(Description = "RoundTrip Tag Helpers (MessagePack)")] + public void RoundTrip_MessagePack() + { + var bytes = SerializeTagHelpers_MessagePack(TagHelpers); + var tagHelpers = DeserializeTagHelpers_MessagePack(bytes); + + if (tagHelpers.Length != TagHelpers.Length) + { + throw new InvalidDataException(); + } + + _buffer.Clear(); + } } diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/ArrayBufferWriter`1.cs b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/ArrayBufferWriter`1.cs new file mode 100644 index 0000000000..4c18040699 --- /dev/null +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/ArrayBufferWriter`1.cs @@ -0,0 +1,251 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +// Copied from https://github.com/dotnet/runtime + +#if !NETCOREAPP3_0_OR_GREATER + +using System.Diagnostics; + +namespace System.Buffers; + +/// +/// Represents a heap-based, array-backed output sink into which data can be written. +/// +internal sealed class ArrayBufferWriter : IBufferWriter +{ + // Copy of Array.MaxLength. + // Used by projects targeting .NET Framework. + private const int ArrayMaxLength = 0x7FFFFFC7; + + private const int DefaultInitialBufferSize = 256; + + private T[] _buffer; + private int _index; + + /// + /// Creates an instance of an , in which data can be written to, + /// with the default initial capacity. + /// + public ArrayBufferWriter() + { + _buffer = Array.Empty(); + _index = 0; + } + + /// + /// Creates an instance of an , in which data can be written to, + /// with an initial capacity specified. + /// + /// The minimum capacity with which to initialize the underlying buffer. + /// + /// Thrown when is not positive (i.e. less than or equal to 0). + /// + public ArrayBufferWriter(int initialCapacity) + { + if (initialCapacity <= 0) + throw new ArgumentException(null, nameof(initialCapacity)); + + _buffer = new T[initialCapacity]; + _index = 0; + } + + /// + /// Returns the data written to the underlying buffer so far, as a . + /// + public ReadOnlyMemory WrittenMemory => _buffer.AsMemory(0, _index); + + /// + /// Returns the data written to the underlying buffer so far, as a . + /// + public ReadOnlySpan WrittenSpan => _buffer.AsSpan(0, _index); + + /// + /// Returns the amount of data written to the underlying buffer so far. + /// + public int WrittenCount => _index; + + /// + /// Returns the total amount of space within the underlying buffer. + /// + public int Capacity => _buffer.Length; + + /// + /// Returns the amount of space available that can still be written into without forcing the underlying buffer to grow. + /// + public int FreeCapacity => _buffer.Length - _index; + + /// + /// Clears the data written to the underlying buffer. + /// + /// + /// + /// You must reset or clear the before trying to re-use it. + /// + /// + /// The method is faster since it only sets to zero the writer's index + /// while the method additionally zeroes the content of the underlying buffer. + /// + /// + /// + public void Clear() + { + Debug.Assert(_buffer.Length >= _index); + _buffer.AsSpan(0, _index).Clear(); + _index = 0; + } + + /// + /// Resets the data written to the underlying buffer without zeroing its content. + /// + /// + /// + /// You must reset or clear the before trying to re-use it. + /// + /// + /// If you reset the writer using the method, the underlying buffer will not be cleared. + /// + /// + /// + public void ResetWrittenCount() => _index = 0; + + /// + /// Notifies that amount of data was written to the output / + /// + /// + /// Thrown when is negative. + /// + /// + /// Thrown when attempting to advance past the end of the underlying buffer. + /// + /// + /// You must request a new buffer after calling Advance to continue writing more data and cannot write to a previously acquired buffer. + /// + public void Advance(int count) + { + if (count < 0) + throw new ArgumentException(null, nameof(count)); + + if (_index > _buffer.Length - count) + ThrowInvalidOperationException_AdvancedTooFar(_buffer.Length); + + _index += count; + } + + /// + /// Returns a to write to that is at least the requested length (specified by ). + /// If no is provided (or it's equal to 0), some non-empty buffer is returned. + /// + /// + /// Thrown when is negative. + /// + /// + /// + /// This will never return an empty . + /// + /// + /// There is no guarantee that successive calls will return the same buffer or the same-sized buffer. + /// + /// + /// You must request a new buffer after calling Advance to continue writing more data and cannot write to a previously acquired buffer. + /// + /// + /// If you reset the writer using the method, this method may return a non-cleared . + /// + /// + /// If you clear the writer using the method, this method will return a with its content zeroed. + /// + /// + public Memory GetMemory(int sizeHint = 0) + { + CheckAndResizeBuffer(sizeHint); + Debug.Assert(_buffer.Length > _index); + return _buffer.AsMemory(_index); + } + + /// + /// Returns a to write to that is at least the requested length (specified by ). + /// If no is provided (or it's equal to 0), some non-empty buffer is returned. + /// + /// + /// Thrown when is negative. + /// + /// + /// + /// This will never return an empty . + /// + /// + /// There is no guarantee that successive calls will return the same buffer or the same-sized buffer. + /// + /// + /// You must request a new buffer after calling Advance to continue writing more data and cannot write to a previously acquired buffer. + /// + /// + /// If you reset the writer using the method, this method may return a non-cleared . + /// + /// + /// If you clear the writer using the method, this method will return a with its content zeroed. + /// + /// + public Span GetSpan(int sizeHint = 0) + { + CheckAndResizeBuffer(sizeHint); + Debug.Assert(_buffer.Length > _index); + return _buffer.AsSpan(_index); + } + + private void CheckAndResizeBuffer(int sizeHint) + { + if (sizeHint < 0) + throw new ArgumentException(nameof(sizeHint)); + + if (sizeHint == 0) + { + sizeHint = 1; + } + + if (sizeHint > FreeCapacity) + { + var currentLength = _buffer.Length; + + // Attempt to grow by the larger of the sizeHint and double the current size. + var growBy = Math.Max(sizeHint, currentLength); + + if (currentLength == 0) + { + growBy = Math.Max(growBy, DefaultInitialBufferSize); + } + + var newSize = currentLength + growBy; + + if ((uint)newSize > int.MaxValue) + { + // Attempt to grow to ArrayMaxLength. + var needed = (uint)(currentLength - FreeCapacity + sizeHint); + Debug.Assert(needed > currentLength); + + if (needed > ArrayMaxLength) + { + ThrowOutOfMemoryException(needed); + } + + newSize = ArrayMaxLength; + } + + Array.Resize(ref _buffer, newSize); + } + + Debug.Assert(FreeCapacity > 0 && FreeCapacity >= sizeHint); + } + + private static void ThrowInvalidOperationException_AdvancedTooFar(int capacity) + { + throw new InvalidOperationException(SR.FormatCannot_advance_past_end_of_the_buffer_which_has_a_size_of_0(capacity)); + } + + private static void ThrowOutOfMemoryException(uint capacity) + { + throw new OutOfMemoryException(SR.FormatCannot_allocate_a_buffer_of_size_0(capacity)); + } +} +#endif diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/SR.resx b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/SR.resx index 11854486c0..fa04ad410b 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/SR.resx +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/SR.resx @@ -1,17 +1,17 @@  - @@ -117,10 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Cannot advance past the end of the buffer, which has a size of {0}. + + + Cannot allocate a buffer of size {0}. + Non-negative number required. This program location is thought to be unreachable. File='{0}', Line={1} - + \ No newline at end of file diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.cs.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.cs.xlf index 2729fe5231..dbc8c2f811 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.cs.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.cs.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. Vyžaduje se nezáporné číslo. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.de.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.de.xlf index 4116cd910f..693dc4e6e4 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.de.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.de.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. Nicht negative Zahl erforderlich. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.es.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.es.xlf index 0e6ba27aec..d2a54d6696 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.es.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.es.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. Se requiere un número no negativo. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.fr.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.fr.xlf index 541e89099a..fd70118724 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.fr.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.fr.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. Nombre non négatif obligatoire. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.it.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.it.xlf index b8c276da29..caa8c920c1 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.it.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.it.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. Numero non negativo obbligatorio. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ja.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ja.xlf index 2d2658d4e8..fd704ec415 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ja.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ja.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. 負でない数値が必要です。 diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ko.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ko.xlf index 3a6820d610..17ea595f30 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ko.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ko.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. 음수가 아닌 수가 필요합니다. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.pl.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.pl.xlf index b75bd955d5..fe78ef93a6 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.pl.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.pl.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. Wymagana jest liczba nieujemna. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.pt-BR.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.pt-BR.xlf index af5f169536..1b447012a8 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.pt-BR.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.pt-BR.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. É necessário um número não negativo. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ru.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ru.xlf index e7155994b2..002c02986d 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ru.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.ru.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. Требуется неотрицательное число. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.tr.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.tr.xlf index a54e8265aa..8d5780d6e2 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.tr.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.tr.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. Negatif olmayan sayı gerekiyor. diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.zh-Hans.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.zh-Hans.xlf index 3e2b4ebfe0..df001eada7 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.zh-Hans.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.zh-Hans.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. 需要提供非负数。 diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.zh-Hant.xlf b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.zh-Hant.xlf index 1760a74670..bbba426816 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.zh-Hant.xlf +++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Resources/xlf/SR.zh-Hant.xlf @@ -2,6 +2,16 @@ + + Cannot advance past the end of the buffer, which has a size of {0}. + Cannot advance past the end of the buffer, which has a size of {0}. + + + + Cannot allocate a buffer of size {0}. + Cannot allocate a buffer of size {0}. + + Non-negative number required. 需要非負數。 From f653fade05afecbd2fce336eaafc25633c14b471 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Wed, 30 Aug 2023 08:16:16 -0700 Subject: [PATCH 8/8] Remove unintented extra comment --- .../Converters/RazorProjectInfoJsonConverter.cs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/RazorProjectInfoJsonConverter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/RazorProjectInfoJsonConverter.cs index d21f4e9e6f..1379fb4c9c 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/RazorProjectInfoJsonConverter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/Json/Converters/RazorProjectInfoJsonConverter.cs @@ -1,19 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. - -/* Unmerged change from project 'Microsoft.AspNetCore.Razor.ProjectEngineHost (net8.0)' -Before: -using Microsoft.AspNetCore.Razor.ProjectSystem; -After: -using Microsoft; -using Microsoft.AspNetCore.Razor; - -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT license. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Razor.ProjectSystem; -*/ using Microsoft.AspNetCore.Razor.ProjectSystem; namespace Microsoft.AspNetCore.Razor.Serialization.Json.Converters;