From 804218384aa6362286326b03080360f49fb57181 Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Tue, 26 Mar 2024 11:48:36 -0700 Subject: [PATCH 01/13] Move feature flags to their own portion of RazorConfiguration --- .../test/InjectDirectiveTest.cs | 2 +- .../CodeGenerationIntegrationTest.cs | 2 +- .../CodeGenerationIntegrationTest.cs | 2 +- .../InstrumentationPassIntegrationTest.cs | 2 +- .../CodeGenerationIntegrationTest.cs | 2 +- .../ComponentCodeGenerationTestBase.cs | 49 +++++-------------- .../src/Language/RazorConfiguration.cs | 12 ++--- .../src/Language/RazorLanguageFeatureFlags.cs | 11 +++++ .../src/Language/RazorProjectEngine.cs | 4 +- .../RazorPageDocumentClassifierPass.cs | 2 +- .../Mvc/RazorPageDocumentClassifierPass.cs | 2 +- .../RazorSourceGenerator.RazorProviders.cs | 2 +- .../RazorProjectInfoSerializer.cs | 2 +- .../UnsupportedRazorConfiguration.cs | 3 +- .../Formatters/RazorConfigurationFormatter.cs | 12 +---- .../MessagePack/SerializationFormat.cs | 2 +- .../FallbackRazorConfiguration.cs | 21 +++++--- .../ProjectSystem/RemoteProjectSnapshot.cs | 2 +- .../DefaultWindowsRazorProjectHost.cs | 2 +- ...ojectConfigurationStateSynchronizerTest.cs | 6 ++- .../RazorProjectServiceTest.cs | 2 +- .../ProjectSnapshotHandleSerializationTest.cs | 2 +- .../SerializationTest.cs | 2 +- .../RazorToolingProjectEngineTestBase.cs | 4 +- .../ProjectStateGeneratedOutputTest.cs | 2 +- .../RazorConfigurationSerializationTest.cs | 3 +- ...ProjectSnapshotProjectEngineFactoryTest.cs | 6 +-- ...ojectSnapshotSynchronizationServiceTest.cs | 2 +- .../Remote/OutOfProcTagHelperResolverTest.cs | 2 +- .../ObjectReaders.cs | 3 +- .../ObjectWriters.cs | 1 - .../SerializationFormat.cs | 2 +- .../Language/RazorProjectEngineTestBase.cs | 4 +- 33 files changed, 80 insertions(+), 97 deletions(-) create mode 100644 src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorLanguageFeatureFlags.cs diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/InjectDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/InjectDirectiveTest.cs index 37874a3c395..1e36de20d59 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/InjectDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/InjectDirectiveTest.cs @@ -175,7 +175,7 @@ private ClassDeclarationIntermediateNode FindClassNode(IntermediateNode node) private RazorEngine CreateEngine() { - var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_1, "test", Extensions: []); + var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_1, "test", Extensions: [], RazorLanguageFeatureFlags.Default); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b => { // Notice we're not registering the InjectDirective.Pass here so we can run it on demand. diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 298cb900381..4e22e461138 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -18,7 +18,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase public CodeGenerationIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X") { - Configuration = new(RazorLanguageVersion.Version_1_1, "MVC-1.1", Extensions: []); + Configuration = new(RazorLanguageVersion.Version_1_1, "MVC-1.1", Extensions: [], RazorLanguageFeatureFlags.Default); } protected override CSharpCompilation BaseCompilation => DefaultBaseCompilation; diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 0a73859b82a..2cdd7a73a2d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -20,7 +20,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase public CodeGenerationIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") { - Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: []); + Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: [], RazorLanguageFeatureFlags.Default); } protected override CSharpCompilation BaseCompilation => DefaultBaseCompilation; diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs index 612436e2661..f92282e040d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs @@ -21,7 +21,7 @@ public class InstrumentationPassIntegrationTest : IntegrationTestBase public InstrumentationPassIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") { - Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: []); + Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: [], RazorLanguageFeatureFlags.Default); } protected override CSharpCompilation BaseCompilation => DefaultBaseCompilation; diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 7adf529b0f4..2739a4c1281 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -20,7 +20,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase public CodeGenerationIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions") { - Configuration = new(RazorLanguageVersion.Latest, "MVC-3.0", Extensions: []); + Configuration = new(RazorLanguageVersion.Latest, "MVC-3.0", Extensions: [], RazorLanguageFeatureFlags.Default); } protected override CSharpCompilation BaseCompilation { get; set; } = DefaultBaseCompilation; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index 953a7b47924..666fb83430b 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -994,7 +994,8 @@ public void IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5() _configuration = new( RazorLanguageVersion.Version_3_0, base.Configuration.ConfigurationName, - base.Configuration.Extensions); + base.Configuration.Extensions, + base.Configuration.RazorLanguageFeatureFlags); // Act var generated = CompileToCSharp(@" @@ -3930,6 +3931,7 @@ public void BindToComponent_WithGetSet_ProducesErrorOnOlderLanguageVersions() RazorLanguageVersion.Version_6_0, "unnamed", Extensions: [], + RazorLanguageFeatureFlags.Default, UseConsolidatedMvcViews: false); // Arrange @@ -9178,10 +9180,7 @@ @preservewhitespace true public void Legacy_3_1_LeadingWhiteSpace_WithDirective() { // Arrange/Act - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; var generated = CompileToCSharp(@" @@ -9199,10 +9198,7 @@ @using System public void Legacy_3_1_LeadingWhiteSpace_WithCSharpExpression() { // Arrange/Act - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; var generated = CompileToCSharp(@" @@ -9220,10 +9216,7 @@ public void Legacy_3_1_LeadingWhiteSpace_WithCSharpExpression() public void Legacy_3_1_LeadingWhiteSpace_WithComponent() { // Arrange - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; AdditionalSyntaxTrees.Add(Parse(@" using Microsoft.AspNetCore.Components; @@ -9256,10 +9249,7 @@ public class SomeOtherComponent : ComponentBase public void Legacy_3_1_TrailingWhiteSpace_WithDirective() { // Arrange/Act - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; var generated = CompileToCSharp(@"

Hello

@@ -9278,10 +9268,7 @@ public void Legacy_3_1_TrailingWhiteSpace_WithDirective() public void Legacy_3_1_TrailingWhiteSpace_WithCSharpExpression() { // Arrange/Act - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; var generated = CompileToCSharp(@"

Hello

@@ -9300,10 +9287,7 @@ public void Legacy_3_1_TrailingWhiteSpace_WithCSharpExpression() public void Legacy_3_1_TrailingWhiteSpace_WithComponent() { // Arrange - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; AdditionalSyntaxTrees.Add(Parse(@" using Microsoft.AspNetCore.Components; @@ -9334,10 +9318,7 @@ public class SomeOtherComponent : ComponentBase public void Legacy_3_1_Whitespace_BetweenElementAndFunctions() { // Arrange - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; // Act var generated = CompileToCSharp(@" @@ -9357,10 +9338,7 @@ public void Legacy_3_1_Whitespace_BetweenElementAndFunctions() public void Legacy_3_1_WhiteSpace_InsideAttribute_InMarkupBlock() { // Arrange - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; // Act var generated = CompileToCSharp(@"
Hello
"); @@ -9375,10 +9353,7 @@ public void Legacy_3_1_WhiteSpace_InsideAttribute_InMarkupBlock() public void Legacy_3_1_WhiteSpace_InMarkupInFunctionsBlock() { // Arrange - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; // Act var generated = CompileToCSharp(@" diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs index 2fc93391036..d9dfac961e1 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs @@ -11,22 +11,22 @@ public sealed record class RazorConfiguration( RazorLanguageVersion LanguageVersion, string ConfigurationName, ImmutableArray Extensions, - bool UseConsolidatedMvcViews = false, - bool ForceRuntimeCodeGeneration = false) + RazorLanguageFeatureFlags RazorLanguageFeatureFlags, + bool UseConsolidatedMvcViews = false) { public static readonly RazorConfiguration Default = new( RazorLanguageVersion.Latest, ConfigurationName: "unnamed", Extensions: [], - UseConsolidatedMvcViews: false, - ForceRuntimeCodeGeneration: false); + RazorLanguageFeatureFlags.Default, + UseConsolidatedMvcViews: false); public bool Equals(RazorConfiguration? other) => other is not null && LanguageVersion == other.LanguageVersion && ConfigurationName == other.ConfigurationName && + RazorLanguageFeatureFlags == other.RazorLanguageFeatureFlags && UseConsolidatedMvcViews == other.UseConsolidatedMvcViews && - ForceRuntimeCodeGeneration == other.ForceRuntimeCodeGeneration && Extensions.SequenceEqual(other.Extensions); public override int GetHashCode() @@ -36,7 +36,7 @@ public override int GetHashCode() hash.Add(ConfigurationName); hash.Add(Extensions); hash.Add(UseConsolidatedMvcViews); - hash.Add(ForceRuntimeCodeGeneration); + hash.Add(RazorLanguageFeatureFlags); return hash; } } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorLanguageFeatureFlags.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorLanguageFeatureFlags.cs new file mode 100644 index 00000000000..3c21696af7a --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorLanguageFeatureFlags.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.AspNetCore.Razor.Language; + +public sealed record class RazorLanguageFeatureFlags( + bool ForceRuntimeCodeGeneration) +{ + public static RazorLanguageFeatureFlags Default = new( + ForceRuntimeCodeGeneration: false); +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs index d334f274fd1..15c6529f985 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs @@ -109,7 +109,7 @@ public RazorCodeDocument ProcessDesignTime(RazorProjectItem projectItem) throw new ArgumentNullException(nameof(projectItem)); } - var codeDocument = Configuration.ForceRuntimeCodeGeneration + var codeDocument = Configuration.RazorLanguageFeatureFlags.ForceRuntimeCodeGeneration ? CreateCodeDocumentCore(projectItem) : CreateCodeDocumentDesignTimeCore(projectItem); ProcessCore(codeDocument); @@ -127,7 +127,7 @@ public RazorCodeDocument ProcessDesignTime( throw new ArgumentNullException(nameof(source)); } - var codeDocument = Configuration.ForceRuntimeCodeGeneration + var codeDocument = Configuration.RazorLanguageFeatureFlags.ForceRuntimeCodeGeneration ? CreateCodeDocumentCore(source, fileKind, importSources, tagHelpers, configureParser: null, configureCodeGeneration: null) : CreateCodeDocumentDesignTimeCore(source, fileKind, importSources, tagHelpers, configureParser: null, configureCodeGeneration: null); ProcessCore(codeDocument); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs index a137cdf5bd0..ecd2a456331 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs @@ -16,7 +16,7 @@ public class RazorPageDocumentClassifierPass : DocumentClassifierPassBase public static readonly string RouteTemplateKey = "RouteTemplate"; private static readonly RazorProjectEngine LeadingDirectiveParsingEngine = RazorProjectEngine.Create( - new(RazorLanguageVersion.Version_2_1, "leading-directive-parser", Extensions: []), + new(RazorLanguageVersion.Version_2_1, "leading-directive-parser", Extensions: [], RazorLanguageFeatureFlags.Default), RazorProjectFileSystem.Create("/"), builder => { diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs index 1706d408e53..9729abe4037 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs @@ -25,7 +25,7 @@ public RazorPageDocumentClassifierPass(bool useConsolidatedMvcViews) } private static readonly RazorProjectEngine LeadingDirectiveParsingEngine = RazorProjectEngine.Create( - new(RazorLanguageVersion.Version_3_0, "leading-directive-parser", []), + new(RazorLanguageVersion.Version_3_0, "leading-directive-parser", [], RazorLanguageFeatureFlags.Default), RazorProjectFileSystem.Create("/"), builder => { diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.RazorProviders.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.RazorProviders.cs index 7daf0ba4abf..77097699513 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.RazorProviders.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.RazorProviders.cs @@ -42,7 +42,7 @@ public partial class RazorSourceGenerator razorLanguageVersion = RazorLanguageVersion.Latest; } - var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName ?? "default", Extensions: [], UseConsolidatedMvcViews: true); + var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName ?? "default", Extensions: [], RazorLanguageFeatureFlags.Default, UseConsolidatedMvcViews: true); var razorSourceGenerationOptions = new RazorSourceGenerationOptions() { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs index 07edb759028..00c0c4968c8 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs @@ -114,7 +114,7 @@ private static RazorConfiguration ComputeRazorConfigurationOptions(AnalyzerConfi razorLanguageVersion = RazorLanguageVersion.Latest; } - var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName, Extensions: [], UseConsolidatedMvcViews: true); + var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName, Extensions: [], RazorLanguageFeatureFlags.Default, UseConsolidatedMvcViews: true); defaultNamespace = rootNamespace ?? "ASP"; // TODO: Source generator does this. Do we want it? diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectEngineHost/UnsupportedRazorConfiguration.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectEngineHost/UnsupportedRazorConfiguration.cs index 5966e5e1fc2..0404483bc4f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectEngineHost/UnsupportedRazorConfiguration.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectEngineHost/UnsupportedRazorConfiguration.cs @@ -10,5 +10,6 @@ internal static class UnsupportedRazorConfiguration public static readonly RazorConfiguration Instance = new( RazorLanguageVersion.Version_1_0, "UnsupportedRazor", - [new("UnsupportedRazorExtension")]); + [new("UnsupportedRazorExtension")], + RazorLanguageFeatureFlags.Default); } 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 index 9b5d8d67313..40c2e4b2240 100644 --- 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 @@ -25,14 +25,6 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser count -= 2; - var forceRuntimeCodeGeneration = false; - - if (reader.NextMessagePackType is MessagePackType.Boolean) - { - forceRuntimeCodeGeneration = reader.ReadBoolean(); - count -= 1; - } - using var builder = new PooledArrayBuilder(); for (var i = 0; i < count; i++) @@ -47,7 +39,7 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser ? version : RazorLanguageVersion.Version_2_1; - return new(languageVersion, configurationName, extensions, ForceRuntimeCodeGeneration: forceRuntimeCodeGeneration); + return new(languageVersion, configurationName, extensions, RazorLanguageFeatureFlags.Default); } public override void Serialize(ref MessagePackWriter writer, RazorConfiguration value, SerializerCachingOptions options) @@ -69,8 +61,6 @@ public override void Serialize(ref MessagePackWriter writer, RazorConfiguration CachedStringFormatter.Instance.Serialize(ref writer, value.LanguageVersion.ToString(), options); } - writer.Write(value.ForceRuntimeCodeGeneration); - count -= 3; for (var i = 0; i < count; i++) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs index 099520cee8d..562eb663dda 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs @@ -9,5 +9,5 @@ internal static class SerializationFormat // 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 = 3; + public const int Version = 4; } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackRazorConfiguration.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackRazorConfiguration.cs index fd08ba17e09..1c6c1342722 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackRazorConfiguration.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackRazorConfiguration.cs @@ -11,39 +11,46 @@ internal static class FallbackRazorConfiguration public static readonly RazorConfiguration MVC_1_0 = new( RazorLanguageVersion.Version_1_0, "MVC-1.0", - [new("MVC-1.0")]); + [new("MVC-1.0")], + RazorLanguageFeatureFlags.Default); public static readonly RazorConfiguration MVC_1_1 = new( RazorLanguageVersion.Version_1_1, "MVC-1.1", - [new("MVC-1.1")]); + [new("MVC-1.1")], + RazorLanguageFeatureFlags.Default); public static readonly RazorConfiguration MVC_2_0 = new( RazorLanguageVersion.Version_2_0, "MVC-2.0", - [new("MVC-2.0")]); + [new("MVC-2.0")], + RazorLanguageFeatureFlags.Default); public static readonly RazorConfiguration MVC_2_1 = new( RazorLanguageVersion.Version_2_1, "MVC-2.1", - [new("MVC-2.1")]); + [new("MVC-2.1")], + RazorLanguageFeatureFlags.Default); public static readonly RazorConfiguration MVC_3_0 = new( RazorLanguageVersion.Version_3_0, "MVC-3.0", - [new("MVC-3.0")]); + [new("MVC-3.0")], + RazorLanguageFeatureFlags.Default); public static readonly RazorConfiguration MVC_5_0 = new( RazorLanguageVersion.Version_5_0, // Razor 5.0 uses MVC 3.0 Razor configuration. "MVC-3.0", - [new("MVC-3.0")]); + [new("MVC-3.0")], + RazorLanguageFeatureFlags.Default); public static readonly RazorConfiguration Latest = new( RazorLanguageVersion.Latest, // Razor latest uses MVC 3.0 Razor configuration. "MVC-3.0", - [new("MVC-3.0")]); + [new("MVC-3.0")], + RazorLanguageFeatureFlags.Default); public static RazorConfiguration SelectConfiguration(Version version) => version switch diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs index f3b701980f7..294674654c5 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs @@ -172,6 +172,6 @@ private RazorConfiguration CreateRazorConfiguration() razorLanguageVersion = RazorLanguageVersion.Latest; } - return new(razorLanguageVersion, configurationName, Extensions: [], UseConsolidatedMvcViews: true); + return new(razorLanguageVersion, configurationName, Extensions: [], RazorLanguageFeatureFlags.Default, UseConsolidatedMvcViews: true); } } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs index 7b2456f6283..6975a3b125b 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs @@ -162,7 +162,7 @@ internal static bool TryGetConfiguration( return false; } - configuration = new(languageVersion, configurationItem.Key, extensions, ForceRuntimeCodeGeneration: forceRuntimeCodeGeneration); + configuration = new(languageVersion, configurationItem.Key, extensions, RazorLanguageFeatureFlags.Default with { ForceRuntimeCodeGeneration = forceRuntimeCodeGeneration }); return true; } 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 f28fb611ea9..6223588e283 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs @@ -290,7 +290,8 @@ public async Task ProjectConfigurationFileChanged_Changed_UpdatesProject() "path/to/project.csproj", new(RazorLanguageVersion.Experimental, "TestConfiguration", - Extensions: []), + Extensions: [], + RazorLanguageFeatureFlags.Default), rootNamespace: "TestRootNamespace2", displayName: "project", ProjectWorkspaceState.Create(LanguageVersion.CSharp6), @@ -373,7 +374,8 @@ public async Task ProjectConfigurationFileChanged_Changed_CantDeserialize_Resets "path/to/project.csproj", new(RazorLanguageVersion.Experimental, "TestConfiguration", - Extensions: []), + Extensions: [], + RazorLanguageFeatureFlags.Default), rootNamespace: "TestRootNamespace2", displayName: "project", ProjectWorkspaceState.Create(LanguageVersion.CSharp6), diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs index 31b27821aa7..babe8121113 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs @@ -1152,7 +1152,7 @@ public async Task AddProject_AddsProjectWithSpecifiedConfiguration() const string IntermediateOutputPath = "C:/path/to/obj"; const string RootNamespace = "My.Root.Namespace"; - var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "TestName", Extensions: []); + var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "TestName", Extensions: [], RazorLanguageFeatureFlags.Default); // Act var projectKey = await RunOnDispatcherAsync(() => 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 818c5c2db16..e77157f6061 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 @@ -31,7 +31,7 @@ public void ProjectSnapshotHandleJsonConverter_Serialization_CanKindaRoundTrip() new(RazorLanguageVersion.Version_1_1, "Test", [new("Test-Extension1"), new("Test-Extension2")], - ForceRuntimeCodeGeneration: false), + RazorLanguageFeatureFlags.Default), "Test"); // Act 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 6c8180b94c8..449653cca4e 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs @@ -25,7 +25,7 @@ public SerializationTest(ITestOutputHelper testOutput) { var languageVersion = RazorLanguageVersion.Experimental; - _configuration = new(languageVersion, "Custom", [new("TestExtension")]); + _configuration = new(languageVersion, "Custom", [new("TestExtension")], RazorLanguageFeatureFlags.Default); _projectWorkspaceState = ProjectWorkspaceState.Create(ImmutableArray.Create( TagHelperDescriptorBuilder.Create("Test", "TestAssembly").Build()), csharpLanguageVersion: LanguageVersion.LatestMajor); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/RazorToolingProjectEngineTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/RazorToolingProjectEngineTestBase.cs index 2cf875bd384..ad082b4d685 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/RazorToolingProjectEngineTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/RazorToolingProjectEngineTestBase.cs @@ -26,13 +26,13 @@ protected virtual void ConfigureProjectEngine(RazorProjectEngineBuilder builder) protected RazorProjectEngine CreateProjectEngine() { - var configuration = new RazorConfiguration(Version, "test", Extensions: []); + var configuration = new RazorConfiguration(Version, "test", Extensions: [], RazorLanguageFeatureFlags.Default); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, ConfigureProjectEngine); } protected RazorProjectEngine CreateProjectEngine(Action configure) { - var configuration = new RazorConfiguration(Version, "test", Extensions: []); + var configuration = new RazorConfiguration(Version, "test", Extensions: [], RazorLanguageFeatureFlags.Default); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b => { ConfigureProjectEngine(b); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs index 0e0f2732f55..32ed085bc3c 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs @@ -191,7 +191,7 @@ public async Task ProjectWorkspaceStateChange_WithTagHelperChange_DoesNotCacheOu public async Task ProjectWorkspaceStateChange_WithProjectWorkspaceState_CSharpLanguageVersionChange_DoesNotCacheOutput() { // Arrange - var csharp8ValidConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_3_0, _hostProject.Configuration.ConfigurationName, _hostProject.Configuration.Extensions); + var csharp8ValidConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_3_0, _hostProject.Configuration.ConfigurationName, _hostProject.Configuration.Extensions, RazorLanguageFeatureFlags.Default); var hostProject = new HostProject(TestProjectData.SomeProject.FilePath, TestProjectData.SomeProject.IntermediateOutputPath, csharp8ValidConfiguration, TestProjectData.SomeProject.RootNamespace); var originalWorkspaceState = ProjectWorkspaceState.Create(_someTagHelpers, LanguageVersion.CSharp7); var original = 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 6f935b2b78d..f42a3332995 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 @@ -19,7 +19,7 @@ public void RazorConfigurationJsonConverter_Serialization_CanRoundTrip() RazorLanguageVersion.Version_1_1, "Test", [new("Test-Extension1"), new("Test-Extension2")], - ForceRuntimeCodeGeneration: true); + RazorLanguageFeatureFlags.Default); // Act var json = JsonDataConvert.SerializeObject(configuration, ObjectWriters.WriteProperties); @@ -35,7 +35,6 @@ public void RazorConfigurationJsonConverter_Serialization_CanRoundTrip() e => Assert.Equal("Test-Extension1", e.ExtensionName), e => Assert.Equal("Test-Extension2", e.ExtensionName)); Assert.Equal(configuration.LanguageVersion, obj.LanguageVersion); - Assert.Equal(configuration.ForceRuntimeCodeGeneration, obj.ForceRuntimeCodeGeneration); } [Fact] diff --git a/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultProjectSnapshotProjectEngineFactoryTest.cs b/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultProjectSnapshotProjectEngineFactoryTest.cs index 937f0c34c91..4a5f32c46bb 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultProjectSnapshotProjectEngineFactoryTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultProjectSnapshotProjectEngineFactoryTest.cs @@ -39,15 +39,15 @@ public DefaultProjectSnapshotProjectEngineFactoryTest(ITestOutputHelper testOutp var hostProject_For_2_1 = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_2_1, "MVC-2.1", Extensions: [], ForceRuntimeCodeGeneration: false), "Test"); + new(RazorLanguageVersion.Version_2_1, "MVC-2.1", Extensions: [], RazorLanguageFeatureFlags.Default), "Test"); var hostProject_For_3_0 = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_3_0, "MVC-3.0", Extensions: [], ForceRuntimeCodeGeneration: false), "Test"); + new(RazorLanguageVersion.Version_3_0, "MVC-3.0", Extensions: [], RazorLanguageFeatureFlags.Default), "Test"); var hostProject_For_UnknownConfiguration = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: [], ForceRuntimeCodeGeneration: false), rootNamespace: null); + new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: [], RazorLanguageFeatureFlags.Default), rootNamespace: null); _snapshot_For_1_0 = new ProjectSnapshot(ProjectState.Create(ProjectEngineFactories.DefaultProvider, hostProject_For_1_0, ProjectWorkspaceState.Default)); _snapshot_For_1_1 = new ProjectSnapshot(ProjectState.Create(ProjectEngineFactories.DefaultProvider, hostProject_For_1_1, ProjectWorkspaceState.Default)); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs index c1a4e476f5f..cedf50ec101 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs @@ -155,7 +155,7 @@ public async Task UpdateGuestProjectManager_ProjectChanged_ConfigurationChange() RazorConfiguration.Default, "project", ProjectWorkspaceState.Default); - var newConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "Custom-1.0", Extensions: []); + var newConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "Custom-1.0", Extensions: [], RazorLanguageFeatureFlags.Default); var newHandle = new ProjectSnapshotHandleProxy( oldHandle.FilePath, oldHandle.IntermediateOutputPath, diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs index f804447b2d5..9ed9c150411 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs @@ -33,7 +33,7 @@ public partial class OutOfProcTagHelperResolverTest : VisualStudioTestBase private static readonly HostProject s_hostProject_For_NonSerializableConfiguration = new( projectFilePath: "Test.csproj", intermediateOutputPath: "/obj", - razorConfiguration: new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: []), + razorConfiguration: new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: [], RazorLanguageFeatureFlags.Default), rootNamespace: null); private readonly Project _workspaceProject; diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs index 8e75fd58b09..cb80efb6dd4 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs @@ -42,7 +42,6 @@ public static RazorConfiguration ReadConfigurationFromProperties(JsonDataReader { var configurationName = reader.ReadNonNullString(nameof(RazorConfiguration.ConfigurationName)); var languageVersionText = reader.ReadNonNullString(nameof(RazorConfiguration.LanguageVersion)); - var forceRuntimeCodeGeneration = reader.ReadBooleanOrFalse(nameof(RazorConfiguration.ForceRuntimeCodeGeneration)); var extensions = reader.ReadImmutableArrayOrEmpty(nameof(RazorConfiguration.Extensions), static r => { @@ -54,7 +53,7 @@ public static RazorConfiguration ReadConfigurationFromProperties(JsonDataReader ? version : RazorLanguageVersion.Version_2_1; - return new(languageVersion, configurationName, extensions, ForceRuntimeCodeGeneration: forceRuntimeCodeGeneration); + return new(languageVersion, configurationName, extensions, RazorLanguageFeatureFlags.Default); } public static RazorDiagnostic ReadDiagnostic(JsonDataReader reader) diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs index 380773f1c21..687a30582b7 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs @@ -34,7 +34,6 @@ public static void WriteProperties(JsonDataWriter writer, RazorConfiguration val : value.LanguageVersion.ToString(); writer.Write(nameof(value.LanguageVersion), languageVersionText); - writer.Write(nameof(value.ForceRuntimeCodeGeneration), value.ForceRuntimeCodeGeneration); writer.WriteArrayIfNotNullOrEmpty(nameof(value.Extensions), value.Extensions, static (w, v) => w.Write(v.ExtensionName)); } diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs index 1d0686678a2..210226d38f4 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs @@ -9,5 +9,5 @@ internal static class SerializationFormat // 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 = 4; + public const int Version = 5; } diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineTestBase.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineTestBase.cs index 6bc3c1de44e..7582a13de5f 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineTestBase.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineTestBase.cs @@ -19,13 +19,13 @@ protected virtual void ConfigureProjectEngine(RazorProjectEngineBuilder builder) protected RazorProjectEngine CreateProjectEngine() { - var configuration = new RazorConfiguration(Version, "test", Extensions: []); + var configuration = new RazorConfiguration(Version, "test", Extensions: [], RazorLanguageFeatureFlags.Default); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, ConfigureProjectEngine); } protected RazorProjectEngine CreateProjectEngine(Action configure) { - var configuration = new RazorConfiguration(Version, "test", Extensions: []); + var configuration = new RazorConfiguration(Version, "test", Extensions: [], RazorLanguageFeatureFlags.Default); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b => { ConfigureProjectEngine(b); From 58cb7744c3c23e7aa68bbececbb2c3bc33fd0412 Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Tue, 26 Mar 2024 13:51:07 -0700 Subject: [PATCH 02/13] Flow feature flag through vscode --- .../ProjectConfigurationFileChangeEventArgs.cs | 12 +++++++++++- .../ProjectConfigurationStateSynchronizer.cs | 10 +++++++--- .../ProjectSystem/RazorProjectInfo.cs | 16 ++++++++-------- .../Formatters/RazorConfigurationFormatter.cs | 10 +++++++++- .../MessagePack/SerializationFormat.cs | 2 +- ...rojectConfigurationFileChangeEventArgsTest.cs | 13 +++++++------ .../ProjectConfigurationStateSynchronizerTest.cs | 3 ++- 7 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs index d32cf5b93f2..39f6e57dba2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.Workspaces; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -32,7 +33,7 @@ public ProjectConfigurationFileChangeEventArgs( _gate = new object(); } - public bool TryDeserialize([NotNullWhen(true)] out RazorProjectInfo? projectInfo) + public bool TryDeserialize(LanguageServerFeatureOptions languageServerFeatureOptions, [NotNullWhen(true)] out RazorProjectInfo? projectInfo) { if (Kind == RazorFileChangeKind.Removed) { @@ -59,6 +60,15 @@ public bool TryDeserialize([NotNullWhen(true)] out RazorProjectInfo? projectInfo var normalizedDetectedFilePath = FilePathNormalizer.Normalize(ConfigurationFilePath); if (string.Equals(normalizedSerializedFilePath, normalizedDetectedFilePath, FilePathComparison.Instance)) { + // Modify the feature flags on the configuration before storing + deserializedProjectInfo = deserializedProjectInfo with + { + Configuration = deserializedProjectInfo.Configuration with + { + RazorLanguageFeatureFlags = new(ForceRuntimeCodeGeneration: languageServerFeatureOptions.ForceRuntimeCodeGeneration) + } + }; + _projectInfo = deserializedProjectInfo; } else diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs index 7d902c4c19e..e56d6043ad1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -22,6 +23,7 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile { private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher; private readonly IRazorProjectService _projectService; + private readonly LanguageServerFeatureOptions _languageServerFeatureOptions; private readonly ILogger _logger; private readonly Dictionary _configurationToProjectMap; internal readonly Dictionary ProjectInfoMap; @@ -29,10 +31,12 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile public ProjectConfigurationStateSynchronizer( ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher, IRazorProjectService projectService, - IRazorLoggerFactory loggerFactory) + IRazorLoggerFactory loggerFactory, + LanguageServerFeatureOptions languageServerFeatureOptions) { _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher; _projectService = projectService; + _languageServerFeatureOptions = languageServerFeatureOptions; _logger = loggerFactory.CreateLogger(); _configurationToProjectMap = new Dictionary(FilePathComparer.Instance); ProjectInfoMap = new Dictionary(); @@ -54,7 +58,7 @@ public void ProjectConfigurationFileChanged(ProjectConfigurationFileChangeEventA case RazorFileChangeKind.Changed: { var configurationFilePath = FilePathNormalizer.Normalize(args.ConfigurationFilePath); - if (!args.TryDeserialize(out var projectInfo)) + if (!args.TryDeserialize(_languageServerFeatureOptions, out var projectInfo)) { if (!_configurationToProjectMap.TryGetValue(configurationFilePath, out var lastAssociatedProjectKey)) { @@ -90,7 +94,7 @@ public void ProjectConfigurationFileChanged(ProjectConfigurationFileChangeEventA case RazorFileChangeKind.Added: { var configurationFilePath = FilePathNormalizer.Normalize(args.ConfigurationFilePath); - if (!args.TryDeserialize(out var projectInfo)) + if (!args.TryDeserialize(_languageServerFeatureOptions, 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. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs index b4072089d05..dbad046ad8b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs @@ -12,20 +12,20 @@ namespace Microsoft.AspNetCore.Razor.ProjectSystem; -internal sealed class RazorProjectInfo +internal sealed record class RazorProjectInfo { private static readonly MessagePackSerializerOptions s_options = MessagePackSerializerOptions.Standard .WithResolver(CompositeResolver.Create( RazorProjectInfoResolver.Instance, StandardResolver.Instance)); - public string SerializedFilePath { get; } - public string FilePath { get; } - public RazorConfiguration Configuration { get; } - public string? RootNamespace { get; } - public string DisplayName { get; } - public ProjectWorkspaceState ProjectWorkspaceState { get; } - public ImmutableArray Documents { get; } + public string SerializedFilePath { get; init; } + public string FilePath { get; init; } + public RazorConfiguration Configuration { get; init; } + public string? RootNamespace { get; init; } + public string DisplayName { get; init; } + public ProjectWorkspaceState ProjectWorkspaceState { get; init; } + public ImmutableArray Documents { get; init; } public RazorProjectInfo( string serializedFilePath, 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 index 40c2e4b2240..17ac742fb13 100644 --- 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 @@ -25,6 +25,14 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser count -= 2; + var forceRuntimeCodeGeneration = false; + + if (reader.NextMessagePackType is MessagePackType.Boolean) + { + forceRuntimeCodeGeneration = reader.ReadBoolean(); + count -= 1; + } + using var builder = new PooledArrayBuilder(); for (var i = 0; i < count; i++) @@ -61,7 +69,7 @@ public override void Serialize(ref MessagePackWriter writer, RazorConfiguration CachedStringFormatter.Instance.Serialize(ref writer, value.LanguageVersion.ToString(), options); } - count -= 3; + count -= 2; for (var i = 0; i < count; i++) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs index 562eb663dda..099520cee8d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs @@ -9,5 +9,5 @@ internal static class SerializationFormat // 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 = 4; + public const int Version = 3; } 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 c17a1b45088..a6694e99415 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Serialization; using Microsoft.AspNetCore.Razor.Test.Common; +using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Moq; using Xunit; using Xunit.Abstractions; @@ -38,7 +39,7 @@ public void TryDeserialize_RemovedKind_ReturnsFalse() projectInfoDeserializer: deserializerMock.Object); // Act - var result = args.TryDeserialize(out var handle); + var result = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle); // Assert Assert.False(result); @@ -70,7 +71,7 @@ public void TryDeserialize_DifferingSerializationPaths_ReturnsFalse() projectInfoDeserializer: deserializerMock.Object); // Act - var result = args.TryDeserialize(out var deserializedProjectInfo); + var result = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var deserializedProjectInfo); // Assert Assert.False(result); @@ -101,8 +102,8 @@ public void TryDeserialize_MemoizesResults() projectInfoDeserializer: deserializerMock.Object); // Act - var result1 = args.TryDeserialize(out var projectInfo1); - var result2 = args.TryDeserialize(out var projectInfo2); + var result1 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var projectInfo1); + var result2 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var projectInfo2); // Assert Assert.True(result1); @@ -125,8 +126,8 @@ public void TryDeserialize_NullFileDeserialization_MemoizesResults_ReturnsFalse( var args = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.bin", RazorFileChangeKind.Changed, deserializerMock.Object); // Act - var result1 = args.TryDeserialize(out var handle1); - var result2 = args.TryDeserialize(out var handle2); + var result1 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle1); + var result2 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle2); // Assert Assert.False(result1); 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 6223588e283..e5899b07df5 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Razor.Serialization; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem; +using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis.CSharp; using Moq; @@ -527,7 +528,7 @@ private async Task WaitForEnqueue_DispatcherThreadAsync(ProjectConfigurationStat private ProjectConfigurationStateSynchronizer GetSynchronizer(IRazorProjectService razorProjectService) { - var synchronizer = new ProjectConfigurationStateSynchronizer(Dispatcher, razorProjectService, LoggerFactory); + var synchronizer = new ProjectConfigurationStateSynchronizer(Dispatcher, razorProjectService, LoggerFactory, new TestLanguageServerFeatureOptions()); synchronizer.EnqueueDelay = 5; return synchronizer; From 5ac1765ff1f0ea6e2332fa39f00dd8c37710a162 Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Tue, 26 Mar 2024 16:45:00 -0700 Subject: [PATCH 03/13] PR Feedback --- .../test/InjectDirectiveTest.cs | 2 +- .../CodeGenerationIntegrationTest.cs | 2 +- .../CodeGenerationIntegrationTest.cs | 2 +- .../InstrumentationPassIntegrationTest.cs | 2 +- .../CodeGenerationIntegrationTest.cs | 2 +- .../ComponentCodeGenerationTestBase.cs | 3 +-- .../src/Language/LanguageServerFlags.cs | 9 ++++++++ .../src/Language/RazorConfiguration.cs | 8 +++---- .../src/Language/RazorLanguageFeatureFlags.cs | 11 ---------- .../src/Language/RazorProjectEngine.cs | 4 ++-- .../RazorPageDocumentClassifierPass.cs | 2 +- .../Mvc/RazorPageDocumentClassifierPass.cs | 2 +- .../RazorSourceGenerator.RazorProviders.cs | 2 +- .../RazorProjectInfoSerializer.cs | 2 +- ...ProjectConfigurationFileChangeEventArgs.cs | 2 +- .../UnsupportedRazorConfiguration.cs | 3 +-- .../Formatters/RazorConfigurationFormatter.cs | 2 +- .../FallbackRazorConfiguration.cs | 21 +++++++------------ .../ProjectSystem/RemoteProjectSnapshot.cs | 2 +- .../DefaultWindowsRazorProjectHost.cs | 11 +++++++--- ...ojectConfigurationStateSynchronizerTest.cs | 6 ++---- .../RazorProjectServiceTest.cs | 2 +- .../ProjectSnapshotHandleSerializationTest.cs | 3 +-- .../SerializationTest.cs | 2 +- .../RazorToolingProjectEngineTestBase.cs | 4 ++-- .../ProjectStateGeneratedOutputTest.cs | 2 +- .../RazorConfigurationSerializationTest.cs | 3 +-- ...ProjectSnapshotProjectEngineFactoryTest.cs | 6 +++--- ...ojectSnapshotSynchronizationServiceTest.cs | 2 +- .../Remote/OutOfProcTagHelperResolverTest.cs | 2 +- .../ObjectReaders.cs | 2 +- .../Language/RazorProjectEngineTestBase.cs | 4 ++-- 32 files changed, 61 insertions(+), 71 deletions(-) create mode 100644 src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs delete mode 100644 src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorLanguageFeatureFlags.cs diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/InjectDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/InjectDirectiveTest.cs index 1e36de20d59..37874a3c395 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/InjectDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/InjectDirectiveTest.cs @@ -175,7 +175,7 @@ private ClassDeclarationIntermediateNode FindClassNode(IntermediateNode node) private RazorEngine CreateEngine() { - var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_1, "test", Extensions: [], RazorLanguageFeatureFlags.Default); + var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_1, "test", Extensions: []); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b => { // Notice we're not registering the InjectDirective.Pass here so we can run it on demand. diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 4e22e461138..298cb900381 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -18,7 +18,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase public CodeGenerationIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X") { - Configuration = new(RazorLanguageVersion.Version_1_1, "MVC-1.1", Extensions: [], RazorLanguageFeatureFlags.Default); + Configuration = new(RazorLanguageVersion.Version_1_1, "MVC-1.1", Extensions: []); } protected override CSharpCompilation BaseCompilation => DefaultBaseCompilation; diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 2cdd7a73a2d..6ddd860d860 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -20,7 +20,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase public CodeGenerationIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") { - Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: [], RazorLanguageFeatureFlags.Default); + Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: [], LanguageServerFlags: null); } protected override CSharpCompilation BaseCompilation => DefaultBaseCompilation; diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs index f92282e040d..612436e2661 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs @@ -21,7 +21,7 @@ public class InstrumentationPassIntegrationTest : IntegrationTestBase public InstrumentationPassIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") { - Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: [], RazorLanguageFeatureFlags.Default); + Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: []); } protected override CSharpCompilation BaseCompilation => DefaultBaseCompilation; diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 2739a4c1281..7adf529b0f4 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -20,7 +20,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase public CodeGenerationIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions") { - Configuration = new(RazorLanguageVersion.Latest, "MVC-3.0", Extensions: [], RazorLanguageFeatureFlags.Default); + Configuration = new(RazorLanguageVersion.Latest, "MVC-3.0", Extensions: []); } protected override CSharpCompilation BaseCompilation { get; set; } = DefaultBaseCompilation; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index 666fb83430b..7c422de7092 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -995,7 +995,7 @@ public void IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5() RazorLanguageVersion.Version_3_0, base.Configuration.ConfigurationName, base.Configuration.Extensions, - base.Configuration.RazorLanguageFeatureFlags); + base.Configuration.LanguageServerFlags); // Act var generated = CompileToCSharp(@" @@ -3931,7 +3931,6 @@ public void BindToComponent_WithGetSet_ProducesErrorOnOlderLanguageVersions() RazorLanguageVersion.Version_6_0, "unnamed", Extensions: [], - RazorLanguageFeatureFlags.Default, UseConsolidatedMvcViews: false); // Arrange diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs new file mode 100644 index 00000000000..f01262bfc84 --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs @@ -0,0 +1,9 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.AspNetCore.Razor.Language; + +public sealed record class LanguageServerFlags + (bool ForceRuntimeCodeGeneration) +{ +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs index d9dfac961e1..33f6e744b0e 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs @@ -11,21 +11,21 @@ public sealed record class RazorConfiguration( RazorLanguageVersion LanguageVersion, string ConfigurationName, ImmutableArray Extensions, - RazorLanguageFeatureFlags RazorLanguageFeatureFlags, + LanguageServerFlags? LanguageServerFlags = null, bool UseConsolidatedMvcViews = false) { public static readonly RazorConfiguration Default = new( RazorLanguageVersion.Latest, ConfigurationName: "unnamed", Extensions: [], - RazorLanguageFeatureFlags.Default, + LanguageServerFlags: null, UseConsolidatedMvcViews: false); public bool Equals(RazorConfiguration? other) => other is not null && LanguageVersion == other.LanguageVersion && ConfigurationName == other.ConfigurationName && - RazorLanguageFeatureFlags == other.RazorLanguageFeatureFlags && + LanguageServerFlags == other.LanguageServerFlags && UseConsolidatedMvcViews == other.UseConsolidatedMvcViews && Extensions.SequenceEqual(other.Extensions); @@ -36,7 +36,7 @@ public override int GetHashCode() hash.Add(ConfigurationName); hash.Add(Extensions); hash.Add(UseConsolidatedMvcViews); - hash.Add(RazorLanguageFeatureFlags); + hash.Add(LanguageServerFlags); return hash; } } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorLanguageFeatureFlags.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorLanguageFeatureFlags.cs deleted file mode 100644 index 3c21696af7a..00000000000 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorLanguageFeatureFlags.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.AspNetCore.Razor.Language; - -public sealed record class RazorLanguageFeatureFlags( - bool ForceRuntimeCodeGeneration) -{ - public static RazorLanguageFeatureFlags Default = new( - ForceRuntimeCodeGeneration: false); -} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs index 15c6529f985..a0412d29635 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs @@ -109,7 +109,7 @@ public RazorCodeDocument ProcessDesignTime(RazorProjectItem projectItem) throw new ArgumentNullException(nameof(projectItem)); } - var codeDocument = Configuration.RazorLanguageFeatureFlags.ForceRuntimeCodeGeneration + var codeDocument = Configuration.LanguageServerFlags?.ForceRuntimeCodeGeneration == true ? CreateCodeDocumentCore(projectItem) : CreateCodeDocumentDesignTimeCore(projectItem); ProcessCore(codeDocument); @@ -127,7 +127,7 @@ public RazorCodeDocument ProcessDesignTime( throw new ArgumentNullException(nameof(source)); } - var codeDocument = Configuration.RazorLanguageFeatureFlags.ForceRuntimeCodeGeneration + var codeDocument = Configuration.LanguageServerFlags?.ForceRuntimeCodeGeneration == true ? CreateCodeDocumentCore(source, fileKind, importSources, tagHelpers, configureParser: null, configureCodeGeneration: null) : CreateCodeDocumentDesignTimeCore(source, fileKind, importSources, tagHelpers, configureParser: null, configureCodeGeneration: null); ProcessCore(codeDocument); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs index ecd2a456331..a137cdf5bd0 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs @@ -16,7 +16,7 @@ public class RazorPageDocumentClassifierPass : DocumentClassifierPassBase public static readonly string RouteTemplateKey = "RouteTemplate"; private static readonly RazorProjectEngine LeadingDirectiveParsingEngine = RazorProjectEngine.Create( - new(RazorLanguageVersion.Version_2_1, "leading-directive-parser", Extensions: [], RazorLanguageFeatureFlags.Default), + new(RazorLanguageVersion.Version_2_1, "leading-directive-parser", Extensions: []), RazorProjectFileSystem.Create("/"), builder => { diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs index 9729abe4037..1706d408e53 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs @@ -25,7 +25,7 @@ public RazorPageDocumentClassifierPass(bool useConsolidatedMvcViews) } private static readonly RazorProjectEngine LeadingDirectiveParsingEngine = RazorProjectEngine.Create( - new(RazorLanguageVersion.Version_3_0, "leading-directive-parser", [], RazorLanguageFeatureFlags.Default), + new(RazorLanguageVersion.Version_3_0, "leading-directive-parser", []), RazorProjectFileSystem.Create("/"), builder => { diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.RazorProviders.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.RazorProviders.cs index 77097699513..7daf0ba4abf 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.RazorProviders.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.RazorProviders.cs @@ -42,7 +42,7 @@ public partial class RazorSourceGenerator razorLanguageVersion = RazorLanguageVersion.Latest; } - var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName ?? "default", Extensions: [], RazorLanguageFeatureFlags.Default, UseConsolidatedMvcViews: true); + var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName ?? "default", Extensions: [], UseConsolidatedMvcViews: true); var razorSourceGenerationOptions = new RazorSourceGenerationOptions() { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs index 00c0c4968c8..07edb759028 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace/RazorProjectInfoSerializer.cs @@ -114,7 +114,7 @@ private static RazorConfiguration ComputeRazorConfigurationOptions(AnalyzerConfi razorLanguageVersion = RazorLanguageVersion.Latest; } - var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName, Extensions: [], RazorLanguageFeatureFlags.Default, UseConsolidatedMvcViews: true); + var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName, Extensions: [], UseConsolidatedMvcViews: true); defaultNamespace = rootNamespace ?? "ASP"; // TODO: Source generator does this. Do we want it? diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs index 39f6e57dba2..62bfa99e4e2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs @@ -65,7 +65,7 @@ public bool TryDeserialize(LanguageServerFeatureOptions languageServerFeatureOpt { Configuration = deserializedProjectInfo.Configuration with { - RazorLanguageFeatureFlags = new(ForceRuntimeCodeGeneration: languageServerFeatureOptions.ForceRuntimeCodeGeneration) + LanguageServerFlags = new(ForceRuntimeCodeGeneration: languageServerFeatureOptions.ForceRuntimeCodeGeneration) } }; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectEngineHost/UnsupportedRazorConfiguration.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectEngineHost/UnsupportedRazorConfiguration.cs index 0404483bc4f..5966e5e1fc2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectEngineHost/UnsupportedRazorConfiguration.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectEngineHost/UnsupportedRazorConfiguration.cs @@ -10,6 +10,5 @@ internal static class UnsupportedRazorConfiguration public static readonly RazorConfiguration Instance = new( RazorLanguageVersion.Version_1_0, "UnsupportedRazor", - [new("UnsupportedRazorExtension")], - RazorLanguageFeatureFlags.Default); + [new("UnsupportedRazorExtension")]); } 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 index 17ac742fb13..b900b6f0b61 100644 --- 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 @@ -47,7 +47,7 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser ? version : RazorLanguageVersion.Version_2_1; - return new(languageVersion, configurationName, extensions, RazorLanguageFeatureFlags.Default); + return new(languageVersion, configurationName, extensions); } public override void Serialize(ref MessagePackWriter writer, RazorConfiguration value, SerializerCachingOptions options) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackRazorConfiguration.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackRazorConfiguration.cs index 1c6c1342722..fd08ba17e09 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackRazorConfiguration.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackRazorConfiguration.cs @@ -11,46 +11,39 @@ internal static class FallbackRazorConfiguration public static readonly RazorConfiguration MVC_1_0 = new( RazorLanguageVersion.Version_1_0, "MVC-1.0", - [new("MVC-1.0")], - RazorLanguageFeatureFlags.Default); + [new("MVC-1.0")]); public static readonly RazorConfiguration MVC_1_1 = new( RazorLanguageVersion.Version_1_1, "MVC-1.1", - [new("MVC-1.1")], - RazorLanguageFeatureFlags.Default); + [new("MVC-1.1")]); public static readonly RazorConfiguration MVC_2_0 = new( RazorLanguageVersion.Version_2_0, "MVC-2.0", - [new("MVC-2.0")], - RazorLanguageFeatureFlags.Default); + [new("MVC-2.0")]); public static readonly RazorConfiguration MVC_2_1 = new( RazorLanguageVersion.Version_2_1, "MVC-2.1", - [new("MVC-2.1")], - RazorLanguageFeatureFlags.Default); + [new("MVC-2.1")]); public static readonly RazorConfiguration MVC_3_0 = new( RazorLanguageVersion.Version_3_0, "MVC-3.0", - [new("MVC-3.0")], - RazorLanguageFeatureFlags.Default); + [new("MVC-3.0")]); public static readonly RazorConfiguration MVC_5_0 = new( RazorLanguageVersion.Version_5_0, // Razor 5.0 uses MVC 3.0 Razor configuration. "MVC-3.0", - [new("MVC-3.0")], - RazorLanguageFeatureFlags.Default); + [new("MVC-3.0")]); public static readonly RazorConfiguration Latest = new( RazorLanguageVersion.Latest, // Razor latest uses MVC 3.0 Razor configuration. "MVC-3.0", - [new("MVC-3.0")], - RazorLanguageFeatureFlags.Default); + [new("MVC-3.0")]); public static RazorConfiguration SelectConfiguration(Version version) => version switch diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs index 294674654c5..f3b701980f7 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs @@ -172,6 +172,6 @@ private RazorConfiguration CreateRazorConfiguration() razorLanguageVersion = RazorLanguageVersion.Latest; } - return new(razorLanguageVersion, configurationName, Extensions: [], RazorLanguageFeatureFlags.Default, UseConsolidatedMvcViews: true); + return new(razorLanguageVersion, configurationName, Extensions: [], UseConsolidatedMvcViews: true); } } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs index 6975a3b125b..48e4709782d 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs @@ -94,8 +94,8 @@ await UpdateAsync( var hostProject = new HostProject(CommonServices.UnconfiguredProject.FullPath, intermediatePath, configuration, rootNamespace, displayName); - var projectConfigurationFile = Path.Combine(intermediatePath, _languageServerFeatureOptions.ProjectConfigurationFileName); - ProjectConfigurationFilePathStore.Set(hostProject.Key, projectConfigurationFile); + var projectConfigurationFile = Path.Combine(intermediatePath, _languageServerFeatureOptions.ProjectConfigurationFileName); + ProjectConfigurationFilePathStore.Set(hostProject.Key, projectConfigurationFile); UpdateProject(updater, hostProject); @@ -162,7 +162,12 @@ internal static bool TryGetConfiguration( return false; } - configuration = new(languageVersion, configurationItem.Key, extensions, RazorLanguageFeatureFlags.Default with { ForceRuntimeCodeGeneration = forceRuntimeCodeGeneration }); + configuration = new( + languageVersion, + configurationItem.Key, + extensions, + new LanguageServerFlags(forceRuntimeCodeGeneration)); + return true; } 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 e5899b07df5..859e5137dc3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs @@ -291,8 +291,7 @@ public async Task ProjectConfigurationFileChanged_Changed_UpdatesProject() "path/to/project.csproj", new(RazorLanguageVersion.Experimental, "TestConfiguration", - Extensions: [], - RazorLanguageFeatureFlags.Default), + Extensions: []), rootNamespace: "TestRootNamespace2", displayName: "project", ProjectWorkspaceState.Create(LanguageVersion.CSharp6), @@ -375,8 +374,7 @@ public async Task ProjectConfigurationFileChanged_Changed_CantDeserialize_Resets "path/to/project.csproj", new(RazorLanguageVersion.Experimental, "TestConfiguration", - Extensions: [], - RazorLanguageFeatureFlags.Default), + Extensions: []), rootNamespace: "TestRootNamespace2", displayName: "project", ProjectWorkspaceState.Create(LanguageVersion.CSharp6), diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs index babe8121113..31b27821aa7 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs @@ -1152,7 +1152,7 @@ public async Task AddProject_AddsProjectWithSpecifiedConfiguration() const string IntermediateOutputPath = "C:/path/to/obj"; const string RootNamespace = "My.Root.Namespace"; - var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "TestName", Extensions: [], RazorLanguageFeatureFlags.Default); + var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "TestName", Extensions: []); // Act var projectKey = await RunOnDispatcherAsync(() => 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 e77157f6061..48f3af542e8 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 @@ -30,8 +30,7 @@ public void ProjectSnapshotHandleJsonConverter_Serialization_CanKindaRoundTrip() projectId, new(RazorLanguageVersion.Version_1_1, "Test", - [new("Test-Extension1"), new("Test-Extension2")], - RazorLanguageFeatureFlags.Default), + [new("Test-Extension1"), new("Test-Extension2")]), "Test"); // Act 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 449653cca4e..6c8180b94c8 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs @@ -25,7 +25,7 @@ public SerializationTest(ITestOutputHelper testOutput) { var languageVersion = RazorLanguageVersion.Experimental; - _configuration = new(languageVersion, "Custom", [new("TestExtension")], RazorLanguageFeatureFlags.Default); + _configuration = new(languageVersion, "Custom", [new("TestExtension")]); _projectWorkspaceState = ProjectWorkspaceState.Create(ImmutableArray.Create( TagHelperDescriptorBuilder.Create("Test", "TestAssembly").Build()), csharpLanguageVersion: LanguageVersion.LatestMajor); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/RazorToolingProjectEngineTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/RazorToolingProjectEngineTestBase.cs index ad082b4d685..2cf875bd384 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/RazorToolingProjectEngineTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/RazorToolingProjectEngineTestBase.cs @@ -26,13 +26,13 @@ protected virtual void ConfigureProjectEngine(RazorProjectEngineBuilder builder) protected RazorProjectEngine CreateProjectEngine() { - var configuration = new RazorConfiguration(Version, "test", Extensions: [], RazorLanguageFeatureFlags.Default); + var configuration = new RazorConfiguration(Version, "test", Extensions: []); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, ConfigureProjectEngine); } protected RazorProjectEngine CreateProjectEngine(Action configure) { - var configuration = new RazorConfiguration(Version, "test", Extensions: [], RazorLanguageFeatureFlags.Default); + var configuration = new RazorConfiguration(Version, "test", Extensions: []); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b => { ConfigureProjectEngine(b); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs index 32ed085bc3c..0e0f2732f55 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs @@ -191,7 +191,7 @@ public async Task ProjectWorkspaceStateChange_WithTagHelperChange_DoesNotCacheOu public async Task ProjectWorkspaceStateChange_WithProjectWorkspaceState_CSharpLanguageVersionChange_DoesNotCacheOutput() { // Arrange - var csharp8ValidConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_3_0, _hostProject.Configuration.ConfigurationName, _hostProject.Configuration.Extensions, RazorLanguageFeatureFlags.Default); + var csharp8ValidConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_3_0, _hostProject.Configuration.ConfigurationName, _hostProject.Configuration.Extensions); var hostProject = new HostProject(TestProjectData.SomeProject.FilePath, TestProjectData.SomeProject.IntermediateOutputPath, csharp8ValidConfiguration, TestProjectData.SomeProject.RootNamespace); var originalWorkspaceState = ProjectWorkspaceState.Create(_someTagHelpers, LanguageVersion.CSharp7); var original = 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 f42a3332995..ec9268ed174 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 @@ -18,8 +18,7 @@ public void RazorConfigurationJsonConverter_Serialization_CanRoundTrip() var configuration = new RazorConfiguration( RazorLanguageVersion.Version_1_1, "Test", - [new("Test-Extension1"), new("Test-Extension2")], - RazorLanguageFeatureFlags.Default); + [new("Test-Extension1"), new("Test-Extension2")]); // Act var json = JsonDataConvert.SerializeObject(configuration, ObjectWriters.WriteProperties); diff --git a/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultProjectSnapshotProjectEngineFactoryTest.cs b/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultProjectSnapshotProjectEngineFactoryTest.cs index 4a5f32c46bb..3d555a9b33e 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultProjectSnapshotProjectEngineFactoryTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultProjectSnapshotProjectEngineFactoryTest.cs @@ -39,15 +39,15 @@ public DefaultProjectSnapshotProjectEngineFactoryTest(ITestOutputHelper testOutp var hostProject_For_2_1 = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_2_1, "MVC-2.1", Extensions: [], RazorLanguageFeatureFlags.Default), "Test"); + new(RazorLanguageVersion.Version_2_1, "MVC-2.1", Extensions: []), "Test"); var hostProject_For_3_0 = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_3_0, "MVC-3.0", Extensions: [], RazorLanguageFeatureFlags.Default), "Test"); + new(RazorLanguageVersion.Version_3_0, "MVC-3.0", Extensions: []), "Test"); var hostProject_For_UnknownConfiguration = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: [], RazorLanguageFeatureFlags.Default), rootNamespace: null); + new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: []), rootNamespace: null); _snapshot_For_1_0 = new ProjectSnapshot(ProjectState.Create(ProjectEngineFactories.DefaultProvider, hostProject_For_1_0, ProjectWorkspaceState.Default)); _snapshot_For_1_1 = new ProjectSnapshot(ProjectState.Create(ProjectEngineFactories.DefaultProvider, hostProject_For_1_1, ProjectWorkspaceState.Default)); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs index cedf50ec101..c1a4e476f5f 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs @@ -155,7 +155,7 @@ public async Task UpdateGuestProjectManager_ProjectChanged_ConfigurationChange() RazorConfiguration.Default, "project", ProjectWorkspaceState.Default); - var newConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "Custom-1.0", Extensions: [], RazorLanguageFeatureFlags.Default); + var newConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "Custom-1.0", Extensions: []); var newHandle = new ProjectSnapshotHandleProxy( oldHandle.FilePath, oldHandle.IntermediateOutputPath, diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs index 9ed9c150411..f804447b2d5 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs @@ -33,7 +33,7 @@ public partial class OutOfProcTagHelperResolverTest : VisualStudioTestBase private static readonly HostProject s_hostProject_For_NonSerializableConfiguration = new( projectFilePath: "Test.csproj", intermediateOutputPath: "/obj", - razorConfiguration: new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: [], RazorLanguageFeatureFlags.Default), + razorConfiguration: new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: []), rootNamespace: null); private readonly Project _workspaceProject; diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs index cb80efb6dd4..4a77aa811ec 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs @@ -53,7 +53,7 @@ public static RazorConfiguration ReadConfigurationFromProperties(JsonDataReader ? version : RazorLanguageVersion.Version_2_1; - return new(languageVersion, configurationName, extensions, RazorLanguageFeatureFlags.Default); + return new(languageVersion, configurationName, extensions); } public static RazorDiagnostic ReadDiagnostic(JsonDataReader reader) diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineTestBase.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineTestBase.cs index 7582a13de5f..6bc3c1de44e 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineTestBase.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineTestBase.cs @@ -19,13 +19,13 @@ protected virtual void ConfigureProjectEngine(RazorProjectEngineBuilder builder) protected RazorProjectEngine CreateProjectEngine() { - var configuration = new RazorConfiguration(Version, "test", Extensions: [], RazorLanguageFeatureFlags.Default); + var configuration = new RazorConfiguration(Version, "test", Extensions: []); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, ConfigureProjectEngine); } protected RazorProjectEngine CreateProjectEngine(Action configure) { - var configuration = new RazorConfiguration(Version, "test", Extensions: [], RazorLanguageFeatureFlags.Default); + var configuration = new RazorConfiguration(Version, "test", Extensions: []); return RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b => { ConfigureProjectEngine(b); From ddad5fd2f06a7b66e3b69210e2ffb1d2330d04cc Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Tue, 26 Mar 2024 16:47:50 -0700 Subject: [PATCH 04/13] Add a comment --- .../src/Language/LanguageServerFlags.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs index f01262bfc84..9a3c6df576d 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs @@ -3,6 +3,11 @@ namespace Microsoft.AspNetCore.Razor.Language; +/// +/// This class represents flags provided by the language server instead of project configuration. +/// They should not be serialized as part of the configuration, as they instead change runtime behavior +/// impacted by LSP configuration rather than any project configuration +/// public sealed record class LanguageServerFlags (bool ForceRuntimeCodeGeneration) { From d315b68383c6c427687c3d06e7d051660f25b834 Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Tue, 26 Mar 2024 16:49:41 -0700 Subject: [PATCH 05/13] Missed one --- .../IntegrationTests/ComponentCodeGenerationTestBase.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index 7c422de7092..68b9c85fa53 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -991,11 +991,7 @@ public void OmitsMinimizedAttributeValueParameter() public void IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5() { // Arrange - _configuration = new( - RazorLanguageVersion.Version_3_0, - base.Configuration.ConfigurationName, - base.Configuration.Extensions, - base.Configuration.LanguageServerFlags); + _configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_3_0 }; // Act var generated = CompileToCSharp(@" From d16f04e4657ac0f964f3029a17b14521a087bf26 Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Tue, 26 Mar 2024 16:51:58 -0700 Subject: [PATCH 06/13] Missed a null removal --- .../test/IntegrationTests/CodeGenerationIntegrationTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 6ddd860d860..0a73859b82a 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -20,7 +20,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase public CodeGenerationIntegrationTest() : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") { - Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: [], LanguageServerFlags: null); + Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: []); } protected override CSharpCompilation BaseCompilation => DefaultBaseCompilation; From 42fcd7322f654076a8395e850ab3b117c9a4febf Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 27 Mar 2024 14:45:16 -0700 Subject: [PATCH 07/13] Make serialization 3 again --- .../SerializationFormat.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs index 210226d38f4..03ce94e07b7 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs @@ -9,5 +9,5 @@ internal static class SerializationFormat // 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 = 5; + public const int Version = 3; } From 1ad61fad12098e2926e30b4ca15cdcc9120d525f Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 27 Mar 2024 14:48:18 -0700 Subject: [PATCH 08/13] Use TestLanguageServerFeatureOptions.Instance --- .../ProjectConfigurationFileChangeEventArgsTest.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 a6694e99415..6652518c540 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs @@ -39,7 +39,7 @@ public void TryDeserialize_RemovedKind_ReturnsFalse() projectInfoDeserializer: deserializerMock.Object); // Act - var result = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle); + var result = args.TryDeserialize(TestLanguageServerFeatureOptions.Instance, out var handle); // Assert Assert.False(result); @@ -71,7 +71,7 @@ public void TryDeserialize_DifferingSerializationPaths_ReturnsFalse() projectInfoDeserializer: deserializerMock.Object); // Act - var result = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var deserializedProjectInfo); + var result = args.TryDeserialize(TestLanguageServerFeatureOptions.Instance, out var deserializedProjectInfo); // Assert Assert.False(result); @@ -102,8 +102,8 @@ public void TryDeserialize_MemoizesResults() projectInfoDeserializer: deserializerMock.Object); // Act - var result1 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var projectInfo1); - var result2 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var projectInfo2); + var result1 = args.TryDeserialize(TestLanguageServerFeatureOptions.Instance, out var projectInfo1); + var result2 = args.TryDeserialize(TestLanguageServerFeatureOptions.Instance, out var projectInfo2); // Assert Assert.True(result1); @@ -126,8 +126,8 @@ public void TryDeserialize_NullFileDeserialization_MemoizesResults_ReturnsFalse( var args = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.bin", RazorFileChangeKind.Changed, deserializerMock.Object); // Act - var result1 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle1); - var result2 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle2); + var result1 = args.TryDeserialize(TestLanguageServerFeatureOptions.Instance, out var handle1); + var result2 = args.TryDeserialize(TestLanguageServerFeatureOptions.Instance, out var handle2); // Assert Assert.False(result1); From 9f8208828d900eb66b999c0aa67180d806f930e0 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 27 Mar 2024 15:00:05 -0700 Subject: [PATCH 09/13] Formatting, and add ToLanguageServerFlags --- .../src/Language/LanguageServerFlags.cs | 5 +---- .../ProjectConfigurationFileChangeEventArgs.cs | 2 +- .../LanguageServerFeatureOptions.cs | 5 +++++ .../ProjectSystem/FallbackProjectManager.cs | 4 +++- .../ProjectSystem/DefaultWindowsRazorProjectHost.cs | 6 +++--- .../DefaultWindowsRazorProjectHostTest.cs | 12 ++++++------ 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs index 9a3c6df576d..524aae94357 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/LanguageServerFlags.cs @@ -8,7 +8,4 @@ namespace Microsoft.AspNetCore.Razor.Language; /// They should not be serialized as part of the configuration, as they instead change runtime behavior /// impacted by LSP configuration rather than any project configuration /// -public sealed record class LanguageServerFlags - (bool ForceRuntimeCodeGeneration) -{ -} +public sealed record class LanguageServerFlags(bool ForceRuntimeCodeGeneration); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs index 62bfa99e4e2..355ca96a3bd 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeEventArgs.cs @@ -65,7 +65,7 @@ public bool TryDeserialize(LanguageServerFeatureOptions languageServerFeatureOpt { Configuration = deserializedProjectInfo.Configuration with { - LanguageServerFlags = new(ForceRuntimeCodeGeneration: languageServerFeatureOptions.ForceRuntimeCodeGeneration) + LanguageServerFlags = languageServerFeatureOptions.ToLanguageServerFlags() } }; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LanguageServerFeatureOptions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LanguageServerFeatureOptions.cs index ec3b570fd4d..2610384eca1 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LanguageServerFeatureOptions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LanguageServerFeatureOptions.cs @@ -1,6 +1,8 @@ // 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.Language; + namespace Microsoft.CodeAnalysis.Razor.Workspaces; internal abstract class LanguageServerFeatureOptions @@ -52,4 +54,7 @@ internal abstract class LanguageServerFeatureOptions /// When enabled, design time code will not be generated. All tooling will be using runtime code generation. /// public abstract bool ForceRuntimeCodeGeneration { get; } + + public LanguageServerFlags ToLanguageServerFlags() + => new(ForceRuntimeCodeGeneration); } diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/ProjectSystem/FallbackProjectManager.cs b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/ProjectSystem/FallbackProjectManager.cs index a09bd163f64..ed7a8d83478 100644 --- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/ProjectSystem/FallbackProjectManager.cs +++ b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/ProjectSystem/FallbackProjectManager.cs @@ -107,11 +107,13 @@ private async Task AddFallbackProjectAsync(ProjectId projectId, string filePath, var rootNamespace = project.DefaultNamespace; + var configuration = FallbackRazorConfiguration.Latest with { LanguageServerFlags = _languageServerFeatureOptions.ToLanguageServerFlags() }; + // We create this as a fallback project so that other parts of the system can reason about them - eg we don't do code // generation for closed files for documents in these projects. If these projects become "real", either because capabilities // change or simply a timing difference between Roslyn and our CPS components, the HostProject instance associated with // the project will be updated, and it will no longer be a fallback project. - var hostProject = new FallbackHostProject(project.FilePath, intermediateOutputPath, FallbackRazorConfiguration.Latest, rootNamespace, project.Name); + var hostProject = new FallbackHostProject(project.FilePath, intermediateOutputPath, configuration, rootNamespace, project.Name); await UpdateProjectManagerAsync( updater => updater.ProjectAdded(hostProject), diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs index 48e4709782d..ceb0427aec0 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs @@ -54,7 +54,7 @@ public DefaultWindowsRazorProjectHost( protected override async Task HandleProjectChangeAsync(string sliceDimensions, IProjectVersionedValue update) { - if (TryGetConfiguration(update.Value.CurrentState, _languageServerFeatureOptions.ForceRuntimeCodeGeneration, out var configuration) && + if (TryGetConfiguration(update.Value.CurrentState, _languageServerFeatureOptions.ToLanguageServerFlags(), out var configuration) && TryGetIntermediateOutputPath(update.Value.CurrentState, out var intermediatePath)) { TryGetRootNamespace(update.Value.CurrentState, out var rootNamespace); @@ -134,7 +134,7 @@ await UpdateAsync( // Internal for testing internal static bool TryGetConfiguration( IImmutableDictionary state, - bool forceRuntimeCodeGeneration, + LanguageServerFlags? languageServerFlags, [NotNullWhen(returnValue: true)] out RazorConfiguration? configuration) { if (!TryGetDefaultConfiguration(state, out var defaultConfiguration)) @@ -166,7 +166,7 @@ internal static bool TryGetConfiguration( languageVersion, configurationItem.Key, extensions, - new LanguageServerFlags(forceRuntimeCodeGeneration)); + languageServerFlags); return true; } diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/DefaultWindowsRazorProjectHostTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/DefaultWindowsRazorProjectHostTest.cs index 1a2a023361f..8ddf51b1baa 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/DefaultWindowsRazorProjectHostTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/DefaultWindowsRazorProjectHostTest.cs @@ -460,7 +460,7 @@ public void TryGetConfiguration_FailsIfNoDefaultConfiguration() var projectState = new Dictionary().ToImmutableDictionary(); // Act - var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, forceRuntimeCodeGeneration: false, out var configuration); + var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, languageServerFlags: null, out var configuration); // Assert Assert.False(result); @@ -482,7 +482,7 @@ public void TryGetConfiguration_FailsIfNoLanguageVersion() }.ToImmutableDictionary(); // Act - var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, forceRuntimeCodeGeneration: false, out var configuration); + var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, languageServerFlags: null, out var configuration); // Assert Assert.False(result); @@ -505,7 +505,7 @@ public void TryGetConfiguration_FailsIfNoConfigurationItems() }.ToImmutableDictionary(); // Act - var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, forceRuntimeCodeGeneration: false, out var configuration); + var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, languageServerFlags: null, out var configuration); // Assert Assert.False(result); @@ -534,7 +534,7 @@ public void TryGetConfiguration_SucceedsWithNoConfiguredExtensionNames() }.ToImmutableDictionary(); // Act - var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, forceRuntimeCodeGeneration: false, out var configuration); + var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, languageServerFlags: null, out var configuration); // Assert Assert.True(result); @@ -568,7 +568,7 @@ public void TryGetConfiguration_IgnoresMissingExtension() }.ToImmutableDictionary(); // Act - var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, forceRuntimeCodeGeneration: false, out var configuration); + var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, languageServerFlags: null, out var configuration); // Assert Assert.True(result); @@ -616,7 +616,7 @@ public void TryGetConfiguration_SucceedsWithAllPreRequisites() }.ToImmutableDictionary(); // Act - var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, forceRuntimeCodeGeneration: false, out var configuration); + var result = DefaultWindowsRazorProjectHost.TryGetConfiguration(projectState, languageServerFlags: null, out var configuration); // Assert Assert.True(result); From 35fe4412d87dbd4e5d6bccd363ed7d4bc25ac452 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 27 Mar 2024 15:44:41 -0700 Subject: [PATCH 10/13] Fix tests --- ...ojectConfigurationStateSynchronizerTest.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) 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 859e5137dc3..c93b6a22e9c 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationStateSynchronizerTest.cs @@ -64,14 +64,14 @@ public async Task ProjectConfigurationFileChanged_Removed_NonNormalizedPaths() .Setup(x => x.AddProject( projectInfo.FilePath, intermediateOutputPath, - projectInfo.Configuration, + It.IsAny(), projectInfo.RootNamespace, projectInfo.DisplayName)) .Returns(projectKey); projectService .Setup(x => x.UpdateProject( projectKey, - projectInfo.Configuration, + It.IsAny(), projectInfo.RootNamespace, projectInfo.DisplayName, projectInfo.ProjectWorkspaceState, @@ -157,14 +157,14 @@ public async Task ProjectConfigurationFileChanged_Added_AddAndUpdatesProject() .Setup(service => service.AddProject( projectInfo.FilePath, intermediateOutputPath, - projectInfo.Configuration, + It.IsAny(), projectInfo.RootNamespace, projectInfo.DisplayName)) .Returns(projectKey); projectService .Setup(service => service.UpdateProject( projectKey, - projectInfo.Configuration, + It.IsAny(), projectInfo.RootNamespace, projectInfo.DisplayName, projectInfo.ProjectWorkspaceState, @@ -205,14 +205,14 @@ public async Task ProjectConfigurationFileChanged_Removed_ResetsProject() .Setup(service => service.AddProject( projectInfo.FilePath, intermediateOutputPath, - projectInfo.Configuration, + It.IsAny(), projectInfo.RootNamespace, projectInfo.DisplayName)) .Returns(projectKey); projectService .Setup(service => service.UpdateProject( projectKey, - projectInfo.Configuration, + It.IsAny(), projectInfo.RootNamespace, projectInfo.DisplayName, projectInfo.ProjectWorkspaceState, @@ -273,14 +273,14 @@ public async Task ProjectConfigurationFileChanged_Changed_UpdatesProject() .Setup(service => service.AddProject( initialProjectInfo.FilePath, intermediateOutputPath, - initialProjectInfo.Configuration, + It.IsAny(), initialProjectInfo.RootNamespace, initialProjectInfo.DisplayName)) .Returns(projectKey); projectService .Setup(service => service.UpdateProject( projectKey, - initialProjectInfo.Configuration, + It.IsAny(), initialProjectInfo.RootNamespace, initialProjectInfo.DisplayName, initialProjectInfo.ProjectWorkspaceState, @@ -299,7 +299,7 @@ public async Task ProjectConfigurationFileChanged_Changed_UpdatesProject() projectService .Setup(service => service.UpdateProject( projectKey, - changedProjectInfo.Configuration, + It.IsAny(), changedProjectInfo.RootNamespace, changedProjectInfo.DisplayName, changedProjectInfo.ProjectWorkspaceState, @@ -356,14 +356,14 @@ public async Task ProjectConfigurationFileChanged_Changed_CantDeserialize_Resets .Setup(service => service.AddProject( initialProjectInfo.FilePath, intermediateOutputPath, - initialProjectInfo.Configuration, + It.IsAny(), initialProjectInfo.RootNamespace, initialProjectInfo.DisplayName)) .Returns(projectKey); projectService .Setup(service => service.UpdateProject( projectKey, - initialProjectInfo.Configuration, + It.IsAny(), initialProjectInfo.RootNamespace, initialProjectInfo.DisplayName, initialProjectInfo.ProjectWorkspaceState, @@ -470,7 +470,7 @@ public async Task ProjectConfigurationFileChanged_RemoveThenAdd_OnlyAdds() .Setup(service => service.AddProject( projectInfo.FilePath, intermediateOutputPath, - projectInfo.Configuration, + It.IsAny(), projectInfo.RootNamespace, projectInfo.DisplayName)) .Returns(projectKey); From 919b6ff2c97a08009764e878dcd219cdf12c9d7e Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 28 Mar 2024 13:46:54 -0700 Subject: [PATCH 11/13] Fix test --- .../ProjectConfigurationFileChangeEventArgsTest.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 6652518c540..8d98809e023 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeEventArgsTest.cs @@ -86,7 +86,7 @@ public void TryDeserialize_MemoizesResults() var projectInfo = new RazorProjectInfo( "/path/to/obj/project.razor.bin", "c:/path/to/project.csproj", - configuration: RazorConfiguration.Default, + configuration: RazorConfiguration.Default with { LanguageServerFlags = TestLanguageServerFeatureOptions.Instance.ToLanguageServerFlags() }, rootNamespace: null, displayName: "project", projectWorkspaceState: ProjectWorkspaceState.Default, @@ -108,8 +108,11 @@ public void TryDeserialize_MemoizesResults() // Assert Assert.True(result1); Assert.True(result2); - Assert.Same(projectInfo, projectInfo1); - Assert.Same(projectInfo, projectInfo2); + + // Deserialization will cause the LanguageServerFlags to be updated on the configuration, so reference equality will not hold. + // Test equality, and that retrieving same instance on repeat calls works by reference equality of projectInfo1 and projectInfo2. + Assert.Equal(projectInfo, projectInfo1); + Assert.Same(projectInfo1, projectInfo2); } [Fact] From 331659e6cd57023d54a8e3136e9b4a2615ee6c6c Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 28 Mar 2024 14:38:35 -0700 Subject: [PATCH 12/13] No really use the right number in serialization --- .../MessagePack/Formatters/RazorConfigurationFormatter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index b900b6f0b61..6ed8ad8e3c9 100644 --- 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 @@ -54,7 +54,7 @@ public override void Serialize(ref MessagePackWriter writer, RazorConfiguration { // Write 3 values + 1 value per extension. var extensions = value.Extensions; - var count = extensions.Length + 3; + var count = extensions.Length + 2; writer.WriteArrayHeader(count); From 5d44c7d532d6556efb804fcb1c5ee8363ec72ed6 Mon Sep 17 00:00:00 2001 From: "Andrew Hall (METAL)" Date: Thu, 28 Mar 2024 16:42:36 -0700 Subject: [PATCH 13/13] fix version in test data --- .../Resources/Telerik/Kendo.Mvc.Examples.project.razor.json | 2 +- .../Resources/project.razor.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json index fa4516ce3e1..1231bdada6f 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json @@ -1,5 +1,5 @@ { - "__Version": 4, + "__Version": 3, "SerializedFilePath": "C:\\Users\\admin\\location\\Kendo.Mvc.Examples\\obj\\Debug\\net7.0\\project.razor.json", "FilePath": "C:\\Users\\admin\\location\\Kendo.Mvc.Examples\\Kendo.Mvc.Examples.csproj", "Configuration": { diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json index 16cd72d46c8..1c00147d34c 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json @@ -1,5 +1,5 @@ { - "__Version": 4, + "__Version": 3, "SerializedFilePath": "C:\\Users\\admin\\location\\blazorserver\\obj\\Debug\\net7.0\\project.razor.json", "FilePath": "C:\\Users\\admin\\location\\blazorserver\\blazorserver.csproj", "Configuration": {