зеркало из https://github.com/dotnet/razor.git
Move CSharpLanguageVersion to RazorConfiguration
This commit is contained in:
Родитель
f6e3f1c275
Коммит
04375f6034
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ProjectWorkspaceState>
|
||||
{
|
||||
public static readonly ProjectWorkspaceState Default = new(ImmutableArray<TagHelperDescriptor>.Empty, LanguageVersion.Default);
|
||||
public static readonly ProjectWorkspaceState Default = new(ImmutableArray<TagHelperDescriptor>.Empty);
|
||||
|
||||
public ImmutableArray<TagHelperDescriptor> TagHelpers { get; }
|
||||
public LanguageVersion CSharpLanguageVersion { get; }
|
||||
|
||||
private ProjectWorkspaceState(
|
||||
ImmutableArray<TagHelperDescriptor> tagHelpers,
|
||||
LanguageVersion csharpLanguageVersion)
|
||||
ImmutableArray<TagHelperDescriptor> tagHelpers)
|
||||
{
|
||||
TagHelpers = tagHelpers;
|
||||
CSharpLanguageVersion = csharpLanguageVersion;
|
||||
}
|
||||
|
||||
public static ProjectWorkspaceState Create(
|
||||
ImmutableArray<TagHelperDescriptor> tagHelpers,
|
||||
LanguageVersion csharpLanguageVersion = LanguageVersion.Default)
|
||||
=> tagHelpers.IsEmpty && csharpLanguageVersion == LanguageVersion.Default
|
||||
ImmutableArray<TagHelperDescriptor> tagHelpers)
|
||||
=> tagHelpers.IsEmpty
|
||||
? Default
|
||||
: new(tagHelpers, csharpLanguageVersion);
|
||||
|
||||
public static ProjectWorkspaceState Create(LanguageVersion csharpLanguageVersion)
|
||||
=> csharpLanguageVersion == LanguageVersion.Default
|
||||
? Default
|
||||
: new(ImmutableArray<TagHelperDescriptor>.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<ProjectWorkspaceState>
|
|||
var hash = HashCodeCombiner.Start();
|
||||
|
||||
hash.Add(TagHelpers);
|
||||
hash.Add(CSharpLanguageVersion);
|
||||
|
||||
return hash.CombinedHash;
|
||||
}
|
||||
|
|
|
@ -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<ProjectWor
|
|||
|
||||
public override ProjectWorkspaceState Deserialize(ref MessagePackReader reader, SerializerCachingOptions options)
|
||||
{
|
||||
reader.ReadArrayHeaderAndVerify(3);
|
||||
reader.ReadArrayHeaderAndVerify(2);
|
||||
|
||||
var checksums = reader.Deserialize<ImmutableArray<Checksum>>(options);
|
||||
|
||||
|
@ -47,19 +46,17 @@ internal sealed class ProjectWorkspaceStateFormatter : ValueFormatter<ProjectWor
|
|||
}
|
||||
|
||||
var tagHelpers = builder.DrainToImmutable();
|
||||
var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32();
|
||||
|
||||
return ProjectWorkspaceState.Create(tagHelpers, csharpLanguageVersion);
|
||||
return ProjectWorkspaceState.Create(tagHelpers);
|
||||
}
|
||||
|
||||
public override void Serialize(ref MessagePackWriter writer, ProjectWorkspaceState value, SerializerCachingOptions options)
|
||||
{
|
||||
writer.WriteArrayHeader(3);
|
||||
writer.WriteArrayHeader(2);
|
||||
|
||||
var checksums = value.TagHelpers.SelectAsArray(x => x.Checksum);
|
||||
|
||||
writer.Serialize(checksums, options);
|
||||
writer.Serialize(value.TagHelpers, options);
|
||||
writer.Write((int)value.CSharpLanguageVersion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<RazorConfigur
|
|||
|
||||
// The count of properties in RazorConfiguration that are serialized. The number of Extensions will be added
|
||||
// to this, for the final serialized value count.
|
||||
private const int SerializedPropertyCount = 5;
|
||||
private const int SerializedPropertyCount = 6;
|
||||
|
||||
private RazorConfigurationFormatter()
|
||||
{
|
||||
|
@ -29,6 +30,7 @@ internal sealed class RazorConfigurationFormatter : ValueFormatter<RazorConfigur
|
|||
var suppressAddComponentParameter = reader.ReadBoolean();
|
||||
var useConsolidatedMvcViews = reader.ReadBoolean();
|
||||
var useRoslynTokenizer = reader.ReadBoolean();
|
||||
var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32();
|
||||
|
||||
count -= SerializedPropertyCount;
|
||||
|
||||
|
@ -52,7 +54,8 @@ internal sealed class RazorConfigurationFormatter : ValueFormatter<RazorConfigur
|
|||
extensions,
|
||||
UseConsolidatedMvcViews: useConsolidatedMvcViews,
|
||||
SuppressAddComponentParameter: suppressAddComponentParameter,
|
||||
UseRoslynTokenizer: useRoslynTokenizer);
|
||||
UseRoslynTokenizer: useRoslynTokenizer,
|
||||
CSharpLanguageVersion: csharpLanguageVersion);
|
||||
}
|
||||
|
||||
public override void Serialize(ref MessagePackWriter writer, RazorConfiguration value, SerializerCachingOptions options)
|
||||
|
@ -77,6 +80,7 @@ internal sealed class RazorConfigurationFormatter : ValueFormatter<RazorConfigur
|
|||
writer.Write(value.SuppressAddComponentParameter);
|
||||
writer.Write(value.UseConsolidatedMvcViews);
|
||||
writer.Write(value.UseRoslynTokenizer);
|
||||
writer.Write((int)value.CSharpLanguageVersion);
|
||||
|
||||
count -= SerializedPropertyCount;
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ internal static class RazorProjectInfoFactory
|
|||
|
||||
var tagHelpers = await project.GetTagHelpersAsync(engine, NoOpTelemetryReporter.Instance, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers, csharpLanguageVersion);
|
||||
var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers);
|
||||
|
||||
return new RazorProjectInfo(
|
||||
projectKey: new ProjectKey(intermediateOutputPath),
|
||||
|
|
|
@ -152,14 +152,6 @@ internal class ProjectState
|
|||
{
|
||||
ProjectWorkspaceStateVersion = Version;
|
||||
}
|
||||
|
||||
if ((difference & ClearProjectWorkspaceStateVersionMask) != 0 &&
|
||||
CSharpLanguageVersion != older.CSharpLanguageVersion)
|
||||
{
|
||||
// C# language version changed. This impacts the ProjectEngine, reset it.
|
||||
_projectEngine = null;
|
||||
ConfigurationVersion = Version;
|
||||
}
|
||||
}
|
||||
|
||||
// Internal set for testing.
|
||||
|
@ -174,7 +166,7 @@ internal class ProjectState
|
|||
|
||||
public ImmutableArray<TagHelperDescriptor> TagHelpers => ProjectWorkspaceState.TagHelpers;
|
||||
|
||||
public LanguageVersion CSharpLanguageVersion => ProjectWorkspaceState.CSharpLanguageVersion;
|
||||
public LanguageVersion CSharpLanguageVersion => HostProject.Configuration.CSharpLanguageVersion;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version of this project, INCLUDING content changes. The <see cref="Version"/> is
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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<ImmutableArray<TagHelperDescriptor>> GetTagHelpersAsync(CancellationToken cancellationToken) => new(ProjectWorkspaceState.TagHelpers);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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<CancellationToken>()))
|
||||
.ReturnsAsync(projectWorkspaceState.TagHelpers);
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче