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 4c649de04d..e49485e47f 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs @@ -3,6 +3,7 @@ using System.Collections.Immutable; using System.Linq; +using Microsoft.CodeAnalysis.CSharp; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Razor.Language; @@ -14,7 +15,8 @@ public sealed record class RazorConfiguration( bool UseConsolidatedMvcViews = true, bool SuppressAddComponentParameter = false, LanguageServerFlags? LanguageServerFlags = null, - bool UseRoslynTokenizer = false) + bool UseRoslynTokenizer = false, + LanguageVersion CSharpLanguageVersion = LanguageVersion.Default) { public static readonly RazorConfiguration Default = new( RazorLanguageVersion.Latest, @@ -29,6 +31,7 @@ public sealed record class RazorConfiguration( LanguageServerFlags == other.LanguageServerFlags && UseConsolidatedMvcViews == other.UseConsolidatedMvcViews && UseRoslynTokenizer == other.UseRoslynTokenizer && + CSharpLanguageVersion == other.CSharpLanguageVersion && Extensions.SequenceEqual(other.Extensions); public override int GetHashCode() @@ -41,6 +44,7 @@ public sealed record class RazorConfiguration( hash.Add(UseConsolidatedMvcViews); hash.Add(LanguageServerFlags); hash.Add(UseRoslynTokenizer); + hash.Add(CSharpLanguageVersion); return hash; } } diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs index e999c1f161..c50b5d9543 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs @@ -73,7 +73,7 @@ public class RazorLanguageServerBenchmarkBase : ProjectSnapshotManagerBenchmarkB { updater.ProjectAdded(hostProject); var tagHelpers = CommonResources.LegacyTagHelpers; - var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers, CodeAnalysis.CSharp.LanguageVersion.CSharp11); + var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers); updater.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState); updater.DocumentAdded(hostProject.Key, hostDocument, textLoader); }, 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 0c4280d8b3..1bf7c4e050 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 @@ -6,6 +6,7 @@ "ConfigurationName": "MVC-3.0", "LanguageVersion": "7.0", "UseRoslynTokenizer": true, + "CSharpLanguageVersion": 1100, "Extensions": [ "MVC-3.0" ] @@ -159527,8 +159528,7 @@ "Runtime.Name": "Components.None" } } - ], - "CSharpLanguageVersion": 1100 + ] }, "RootNamespace": "Kendo.Mvc.Examples", "Documents": [ 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 0bd019c214..e00a7130e2 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 @@ -6,6 +6,7 @@ "ConfigurationName": "MVC-3.0", "LanguageVersion": "3.0", "UseRoslynTokenizer": true, + "CSharpLanguageVersion": 800, "Extensions": [ "MVC-3.0" ] }, "ProjectWorkspaceState": { @@ -16126,8 +16127,7 @@ "Runtime.Name": "Components.None" } } - ], - "CSharpLanguageVersion": 800 + ] }, "RootNamespace": "blazorserver", "Documents": [ diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs index e797c50a4a..52dc25f7a8 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs @@ -366,7 +366,7 @@ internal partial class RazorProjectService : IRazorProjectService, IRazorProject if (!projectWorkspaceState.Equals(ProjectWorkspaceState.Default)) { - _logger.LogInformation($"Updating project '{project.Key}' TagHelpers ({projectWorkspaceState.TagHelpers.Length}) and C# Language Version ({projectWorkspaceState.CSharpLanguageVersion})."); + _logger.LogInformation($"Updating project '{project.Key}' TagHelpers ({projectWorkspaceState.TagHelpers.Length})."); } updater.ProjectWorkspaceStateChanged(project.Key, projectWorkspaceState); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectWorkspaceState.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectWorkspaceState.cs index 041e7cd3bf..f8eb552ce8 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectWorkspaceState.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/ProjectWorkspaceState.cs @@ -5,44 +5,33 @@ using System; using System.Collections.Immutable; using System.Linq; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Razor.ProjectSystem; internal sealed class ProjectWorkspaceState : IEquatable { - public static readonly ProjectWorkspaceState Default = new(ImmutableArray.Empty, LanguageVersion.Default); + public static readonly ProjectWorkspaceState Default = new(ImmutableArray.Empty); public ImmutableArray TagHelpers { get; } - public LanguageVersion CSharpLanguageVersion { get; } private ProjectWorkspaceState( - ImmutableArray tagHelpers, - LanguageVersion csharpLanguageVersion) + ImmutableArray tagHelpers) { TagHelpers = tagHelpers; - CSharpLanguageVersion = csharpLanguageVersion; } public static ProjectWorkspaceState Create( - ImmutableArray tagHelpers, - LanguageVersion csharpLanguageVersion = LanguageVersion.Default) - => tagHelpers.IsEmpty && csharpLanguageVersion == LanguageVersion.Default + ImmutableArray tagHelpers) + => tagHelpers.IsEmpty ? Default - : new(tagHelpers, csharpLanguageVersion); - - public static ProjectWorkspaceState Create(LanguageVersion csharpLanguageVersion) - => csharpLanguageVersion == LanguageVersion.Default - ? Default - : new(ImmutableArray.Empty, csharpLanguageVersion); + : new(tagHelpers); public override bool Equals(object? obj) => obj is ProjectWorkspaceState other && Equals(other); public bool Equals(ProjectWorkspaceState? other) => other is not null && - CSharpLanguageVersion == other.CSharpLanguageVersion && TagHelpers.SequenceEqual(other.TagHelpers); public override int GetHashCode() @@ -50,7 +39,6 @@ internal sealed class ProjectWorkspaceState : IEquatable var hash = HashCodeCombiner.Start(); hash.Add(TagHelpers); - hash.Add(CSharpLanguageVersion); return hash.CombinedHash; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectWorkspaceStateFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectWorkspaceStateFormatter.cs index 60a9894b1d..156c443958 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectWorkspaceStateFormatter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectWorkspaceStateFormatter.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters.TagHelpers; using Microsoft.AspNetCore.Razor.Utilities; -using Microsoft.CodeAnalysis.CSharp; namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; @@ -22,7 +21,7 @@ internal sealed class ProjectWorkspaceStateFormatter : ValueFormatter>(options); @@ -47,19 +46,17 @@ internal sealed class ProjectWorkspaceStateFormatter : ValueFormatter x.Checksum); writer.Serialize(checksums, options); writer.Serialize(value.TagHelpers, options); - writer.Write((int)value.CSharpLanguageVersion); } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs index 366ba8c02b..4bb6b57f8a 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 @@ -4,6 +4,7 @@ using MessagePack; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.CodeAnalysis.CSharp; namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters; @@ -13,7 +14,7 @@ internal sealed class RazorConfigurationFormatter : ValueFormatter TagHelpers => ProjectWorkspaceState.TagHelpers; - public LanguageVersion CSharpLanguageVersion => ProjectWorkspaceState.CSharpLanguageVersion; + public LanguageVersion CSharpLanguageVersion => HostProject.Configuration.CSharpLanguageVersion; /// /// Gets the version of this project, INCLUDING content changes. The is diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Host/ProjectSnapshotManagerProxy.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Host/ProjectSnapshotManagerProxy.cs index 7ae74da1e6..b38129fa39 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Host/ProjectSnapshotManagerProxy.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Host/ProjectSnapshotManagerProxy.cs @@ -101,7 +101,7 @@ internal class ProjectSnapshotManagerProxy : IProjectSnapshotManagerProxy, IColl } var tagHelpers = await project.GetTagHelpersAsync(CancellationToken.None).ConfigureAwait(false); - var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers, project.CSharpLanguageVersion); + var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers); var projectFilePath = _session.ConvertLocalPathToSharedUri(project.FilePath); var intermediateOutputPath = _session.ConvertLocalPathToSharedUri(project.IntermediateOutputPath); var projectHandleProxy = new ProjectSnapshotHandleProxy(projectFilePath, intermediateOutputPath, project.Configuration, project.RootNamespace, projectWorkspaceState); diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs index 77496320ac..5b5be19c6b 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs @@ -294,6 +294,7 @@ internal sealed partial class ProjectWorkspaceStateGenerator( { SuppressAddComponentParameter = suppressAddComponentParameter, UseRoslynTokenizer = useRoslynTokenizer, + CSharpLanguageVersion = csharpLanguageVersion }; using var _ = StopwatchPool.GetPooledObject(out var watch); @@ -318,7 +319,7 @@ internal sealed partial class ProjectWorkspaceStateGenerator( Project: {projectSnapshot.FilePath} """); - return (ProjectWorkspaceState.Create(tagHelpers, csharpLanguageVersion), configuration); + return (ProjectWorkspaceState.Create(tagHelpers), configuration); } catch (OperationCanceledException) { diff --git a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/EphemeralProjectSnapshot.cs b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/EphemeralProjectSnapshot.cs index 48ec5599ff..281d0f95bb 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/EphemeralProjectSnapshot.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/EphemeralProjectSnapshot.cs @@ -50,7 +50,7 @@ internal class EphemeralProjectSnapshot : IProjectSnapshot public VersionStamp Version => VersionStamp.Default; - public LanguageVersion CSharpLanguageVersion => ProjectWorkspaceState.CSharpLanguageVersion; + public LanguageVersion CSharpLanguageVersion => Configuration.CSharpLanguageVersion; public ValueTask> GetTagHelpersAsync(CancellationToken cancellationToken) => new(ProjectWorkspaceState.TagHelpers); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs index 7c05c89c15..a2d8d67c4f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Text; using Xunit; @@ -142,8 +141,7 @@ public class OpenDocumentGeneratorTest(ITestOutputHelper testOutput) : LanguageS updater.DocumentAdded(_hostProject1.Key, _documents[0], _documents[0].CreateEmptyTextLoader()); // Act - updater.ProjectWorkspaceStateChanged(_hostProject1.Key, - ProjectWorkspaceState.Create(LanguageVersion.CSharp8)); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, ProjectWorkspaceState.Default); }); // Assert @@ -166,8 +164,7 @@ public class OpenDocumentGeneratorTest(ITestOutputHelper testOutput) : LanguageS updater.DocumentOpened(_hostProject1.Key, _documents[0].FilePath, SourceText.From(string.Empty)); // Act - updater.ProjectWorkspaceStateChanged(_hostProject1.Key, - ProjectWorkspaceState.Create(LanguageVersion.CSharp8)); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, ProjectWorkspaceState.Default); }); // Assert 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 a12f848949..504d2bd5e2 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Text; using Moq; @@ -66,7 +65,7 @@ public class RazorProjectServiceTest(ITestOutputHelper testOutput) : LanguageSer updater.ProjectAdded(hostProject); }); - var projectWorkspaceState = ProjectWorkspaceState.Create(LanguageVersion.LatestMajor); + var projectWorkspaceState = ProjectWorkspaceState.Default; // Act await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( 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 c910ea7660..50ca8dd6db 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Serialization; using Microsoft.AspNetCore.Razor.Serialization.Json; using Microsoft.AspNetCore.Razor.Test.Common; -using Microsoft.CodeAnalysis.CSharp; using Newtonsoft.Json.Linq; using Xunit; using Xunit.Abstractions; @@ -26,8 +25,7 @@ public class SerializationTest : ToolingTestBase _configuration = new(languageVersion, "Custom", [new("TestExtension")]); _projectWorkspaceState = ProjectWorkspaceState.Create( - tagHelpers: [TagHelperDescriptorBuilder.Create("Test", "TestAssembly").Build()], - csharpLanguageVersion: LanguageVersion.LatestMajor); + tagHelpers: [TagHelperDescriptorBuilder.Create("Test", "TestAssembly").Build()]); } [Fact] diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/StreamExtensionTests.NetCore.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/StreamExtensionTests.NetCore.cs index 8895137d79..965779a4bd 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/StreamExtensionTests.NetCore.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/StreamExtensionTests.NetCore.cs @@ -77,7 +77,7 @@ public class StreamExtensionTests .TagMatchingRuleDescriptor(rule => rule.RequireTagName("tag-name")) .Build(); - var projectWorkspaceState = ProjectWorkspaceState.Create([tagHelper], CodeAnalysis.CSharp.LanguageVersion.Latest); + var projectWorkspaceState = ProjectWorkspaceState.Create([tagHelper]); var projectInfo = new RazorProjectInfo( new ProjectKey("TestProject"), diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs index 9abf55ceff..97571789e5 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs @@ -116,13 +116,13 @@ internal static class TestMocks .Returns(hostProject.RootNamespace); mock.SetupGet(x => x.DisplayName) .Returns(hostProject.DisplayName); + mock.SetupGet(x => x.CSharpLanguageVersion) + .Returns(hostProject.Configuration.CSharpLanguageVersion); if (projectWorkspaceState is not null) { mock.SetupGet(x => x.ProjectWorkspaceState) .Returns(projectWorkspaceState); - mock.SetupGet(x => x.CSharpLanguageVersion) - .Returns(projectWorkspaceState.CSharpLanguageVersion); mock.Setup(x => x.GetTagHelpersAsync(It.IsAny())) .ReturnsAsync(projectWorkspaceState.TagHelpers); } 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 7e80b2537b..64dbd8b65b 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 @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; -using Microsoft.CodeAnalysis.CSharp; using Xunit; using Xunit.Abstractions; @@ -184,30 +183,6 @@ public class ProjectStateGeneratedOutputTest : WorkspaceTestBase Assert.Equal(state.ProjectWorkspaceStateVersion, actualInputVersion); } - [Fact] - public async Task ProjectWorkspaceStateChange_WithProjectWorkspaceState_CSharpLanguageVersionChange_DoesNotCacheOutput() - { - // Arrange - var csharp8ValidConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_3_0, _hostProject.Configuration.ConfigurationName, _hostProject.Configuration.Extensions); - var hostProject = TestProjectData.SomeProject with { Configuration = csharp8ValidConfiguration }; - var originalWorkspaceState = ProjectWorkspaceState.Create(_someTagHelpers, LanguageVersion.CSharp7); - var original = - ProjectState.Create(ProjectEngineFactoryProvider, hostProject, originalWorkspaceState) - .WithAddedHostDocument(_hostDocument, TestMocks.CreateTextLoader("@DateTime.Now", VersionStamp.Default)); - var changedWorkspaceState = ProjectWorkspaceState.Create(_someTagHelpers, LanguageVersion.CSharp8); - - var (originalOutput, originalInputVersion) = await GetOutputAsync(original, _hostDocument, DisposalToken); - - // Act - var state = original.WithProjectWorkspaceState(changedWorkspaceState); - - // Assert - var (actualOutput, actualInputVersion) = await GetOutputAsync(state, _hostDocument, DisposalToken); - Assert.NotSame(originalOutput, actualOutput); - Assert.NotEqual(originalInputVersion, actualInputVersion); - Assert.Equal(state.ProjectWorkspaceStateVersion, actualInputVersion); - } - [Fact] public async Task ConfigurationChange_DoesNotCacheOutput() { diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateTest.cs index 2658d89368..334a5c016c 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateTest.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Text; using Xunit; using Xunit.Abstractions; @@ -642,45 +641,6 @@ public class ProjectStateTest : WorkspaceTestBase Assert.Equal(TestProjectData.SomeProjectFile1.FilePath, documentFilePath); } - [Fact] - public void ProjectState_WithProjectWorkspaceState_Changed() - { - // Arrange - var original = ProjectState.Create(ProjectEngineFactoryProvider, _hostProject, _projectWorkspaceState) - .WithAddedHostDocument(_documents[2], DocumentState.EmptyLoader) - .WithAddedHostDocument(_documents[1], DocumentState.EmptyLoader); - - // Force init - var originalTagHelpers = original.TagHelpers; - var originalProjectWorkspaceStateVersion = original.ProjectWorkspaceStateVersion; - - var changed = ProjectWorkspaceState.Create(_projectWorkspaceState.TagHelpers, LanguageVersion.CSharp6); - - // Act - var state = original.WithProjectWorkspaceState(changed); - - // Assert - Assert.NotEqual(original.Version, state.Version); - Assert.Same(changed, state.ProjectWorkspaceState); - - var actualTagHelpers = state.TagHelpers; - var actualProjectWorkspaceStateVersion = state.ProjectWorkspaceStateVersion; - - // The C# language version changed, and the tag helpers didn't change - Assert.NotSame(original.ProjectEngine, state.ProjectEngine); - - Assert.Equal(originalTagHelpers.Length, actualTagHelpers.Length); - for (var i = 0; i < originalTagHelpers.Length; i++) - { - Assert.Same(originalTagHelpers[i], actualTagHelpers[i]); - } - - Assert.NotEqual(originalProjectWorkspaceStateVersion, actualProjectWorkspaceStateVersion); - - Assert.NotSame(original.Documents[_documents[1].FilePath], state.Documents[_documents[1].FilePath]); - Assert.NotSame(original.Documents[_documents[2].FilePath], state.Documents[_documents[2].FilePath]); - } - [Fact] public void ProjectState_WithProjectWorkspaceState_Changed_TagHelpersChanged() { @@ -727,7 +687,7 @@ public class ProjectStateTest : WorkspaceTestBase _ = original.TagHelpers; _ = original.ProjectWorkspaceStateVersion; - var changed = ProjectWorkspaceState.Create(original.TagHelpers, original.CSharpLanguageVersion); + var changed = ProjectWorkspaceState.Create(original.TagHelpers); // Act var state = original.WithProjectWorkspaceState(changed); diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs index 4185ea3e7f..ed7f469a31 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs @@ -45,6 +45,7 @@ internal static partial class ObjectReaders var suppressAddComponentParameter = reader.ReadBooleanOrFalse(nameof(RazorConfiguration.SuppressAddComponentParameter)); var useConsolidatedMvcViews = reader.ReadBooleanOrTrue(nameof(RazorConfiguration.UseConsolidatedMvcViews)); var useRoslynTokenizer = reader.ReadBooleanOrFalse(nameof(RazorConfiguration.UseRoslynTokenizer)); + var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32OrZero(nameof(RazorConfiguration.CSharpLanguageVersion)); var extensions = reader.ReadImmutableArrayOrEmpty(nameof(RazorConfiguration.Extensions), static r => { @@ -103,9 +104,8 @@ internal static partial class ObjectReaders public static ProjectWorkspaceState ReadProjectWorkspaceStateFromProperties(JsonDataReader reader) { var tagHelpers = reader.ReadImmutableArrayOrEmpty(nameof(ProjectWorkspaceState.TagHelpers), static r => ReadTagHelper(r, useCache: true)); - var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32OrZero(nameof(ProjectWorkspaceState.CSharpLanguageVersion)); - return ProjectWorkspaceState.Create(tagHelpers, csharpLanguageVersion); + return ProjectWorkspaceState.Create(tagHelpers); } public static TagHelperDescriptor ReadTagHelper(JsonDataReader reader, bool useCache) diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs index df1a252ed6..c03051e73c 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs @@ -38,6 +38,7 @@ internal static class ObjectWriters writer.WriteIfNotFalse(nameof(value.SuppressAddComponentParameter), value.SuppressAddComponentParameter); writer.WriteIfNotTrue(nameof(value.UseConsolidatedMvcViews), value.UseConsolidatedMvcViews); writer.WriteIfNotFalse(nameof(value.UseRoslynTokenizer), value.UseRoslynTokenizer); + writer.WriteIfNotZero(nameof(value.CSharpLanguageVersion), (int)value.CSharpLanguageVersion); writer.WriteArrayIfNotNullOrEmpty(nameof(value.Extensions), value.Extensions, static (w, v) => w.Write(v.ExtensionName)); }