Skip to content

Commit

Permalink
Revert "Update project configuration from Roslyn info (dotnet#11092)"
Browse files Browse the repository at this point in the history
This reverts commit a37ee12, reversing
changes made to ad74439.
  • Loading branch information
jjonescz committed Nov 5, 2024
1 parent 4bf2470 commit 0ef2236
Show file tree
Hide file tree
Showing 44 changed files with 308 additions and 260 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language;
Expand All @@ -14,14 +13,15 @@ public sealed record class RazorConfiguration(
ImmutableArray<RazorExtension> Extensions,
bool UseConsolidatedMvcViews = true,
bool SuppressAddComponentParameter = false,
LanguageServerFlags? LanguageServerFlags = null,
bool UseRoslynTokenizer = false,
LanguageVersion CSharpLanguageVersion = LanguageVersion.Default)
LanguageServerFlags? LanguageServerFlags = null)
{
public static readonly RazorConfiguration Default = new(
RazorLanguageVersion.Latest,
ConfigurationName: "unnamed",
Extensions: []);
Extensions: [],
UseConsolidatedMvcViews: true,
SuppressAddComponentParameter: false,
LanguageServerFlags: null);

public bool Equals(RazorConfiguration? other)
=> other is not null &&
Expand All @@ -30,8 +30,6 @@ public bool Equals(RazorConfiguration? other)
SuppressAddComponentParameter == other.SuppressAddComponentParameter &&
LanguageServerFlags == other.LanguageServerFlags &&
UseConsolidatedMvcViews == other.UseConsolidatedMvcViews &&
UseRoslynTokenizer == other.UseRoslynTokenizer &&
CSharpLanguageVersion == other.CSharpLanguageVersion &&
Extensions.SequenceEqual(other.Extensions);

public override int GetHashCode()
Expand All @@ -43,8 +41,6 @@ public override int GetHashCode()
hash.Add(SuppressAddComponentParameter);
hash.Add(UseConsolidatedMvcViews);
hash.Add(LanguageServerFlags);
hash.Add(UseRoslynTokenizer);
hash.Add(CSharpLanguageVersion);
return hash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public partial class RazorSourceGenerator
var razorConfiguration = new RazorConfiguration(razorLanguageVersion, configurationName ?? "default", Extensions: [], UseConsolidatedMvcViews: true, SuppressAddComponentParameter: !isComponentParameterSupported);

// We use the new tokenizer only when requested for now.
var useRoslynTokenizer = parseOptions.UseRoslynTokenizer();
var useRoslynTokenizer = parseOptions.Features.TryGetValue("use-roslyn-tokenizer", out var useRoslynTokenizerValue)
&& string.Equals(useRoslynTokenizerValue, "true", StringComparison.OrdinalIgnoreCase);

var razorSourceGenerationOptions = new RazorSourceGenerationOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ await projectManager.UpdateAsync(
{
updater.ProjectAdded(hostProject);
var tagHelpers = CommonResources.LegacyTagHelpers;
var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers);
var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers, CodeAnalysis.CSharp.LanguageVersion.CSharp11);
updater.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState);
updater.DocumentAdded(hostProject.Key, hostDocument, textLoader);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"__Version": 7,
"__Version": 6,
"ProjectKey": "C:\\Users\\admin\\location\\Kendo.Mvc.Examples\\obj\\Debug\\net7.0\\",
"FilePath": "C:\\Users\\admin\\location\\Kendo.Mvc.Examples\\Kendo.Mvc.Examples.csproj",
"Configuration": {
"ConfigurationName": "MVC-3.0",
"LanguageVersion": "7.0",
"UseRoslynTokenizer": true,
"CSharpLanguageVersion": 1100,
"Extensions": [
"MVC-3.0"
]
Expand Down Expand Up @@ -159528,7 +159526,8 @@
"Runtime.Name": "Components.None"
}
}
]
],
"CSharpLanguageVersion": 1100
},
"RootNamespace": "Kendo.Mvc.Examples",
"Documents": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"__Version": 7,
"__Version": 6,
"ProjectKey": "C:\\Users\\admin\\location\\blazorserver\\obj\\Debug\\net7.0\\",
"FilePath": "C:\\Users\\admin\\location\\blazorserver\\blazorserver.csproj",
"Configuration": {
"ConfigurationName": "MVC-3.0",
"LanguageVersion": "3.0",
"UseRoslynTokenizer": true,
"CSharpLanguageVersion": 800,
"Extensions": [ "MVC-3.0" ]
},
"ProjectWorkspaceState": {
Expand Down Expand Up @@ -16127,7 +16125,8 @@
"Runtime.Name": "Components.None"
}
}
]
],
"CSharpLanguageVersion": 800
},
"RootNamespace": "blazorserver",
"Documents": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,17 @@ private Task AddOrUpdateProjectCoreAsync(
if (!projectWorkspaceState.Equals(ProjectWorkspaceState.Default))
{
_logger.LogInformation($"Updating project '{project.Key}' TagHelpers ({projectWorkspaceState.TagHelpers.Length}).");
_logger.LogInformation($"Updating project '{project.Key}' TagHelpers ({projectWorkspaceState.TagHelpers.Length}) and C# Language Version ({projectWorkspaceState.CSharpLanguageVersion}).");
}
updater.ProjectWorkspaceStateChanged(project.Key, projectWorkspaceState);
var currentConfiguration = project.Configuration;
var currentRootNamespace = project.RootNamespace;
if (project.Configuration == configuration &&
if (currentConfiguration.ConfigurationName == configuration?.ConfigurationName &&
currentRootNamespace == rootNamespace)
{
_logger.LogTrace($"Skipping configuration update for '{project.Key}' as the configuration and root namespace are unchanged.");
_logger.LogTrace($"Updating project '{project.Key}'. The project is already using configuration '{configuration.ConfigurationName}' and root namespace '{rootNamespace}'.");
return;
}
Expand All @@ -384,9 +385,14 @@ private Task AddOrUpdateProjectCoreAsync(
configuration = FallbackRazorConfiguration.Latest;
_logger.LogInformation($"Updating project '{project.Key}' to use the latest configuration ('{configuration.ConfigurationName}')'.");
}
else
else if (currentConfiguration.ConfigurationName != configuration.ConfigurationName)
{
_logger.LogInformation($"Updating project '{project.Key}' to Razor configuration '{configuration.ConfigurationName}', namespace '{rootNamespace}', with language version '{configuration.LanguageVersion}'.");
_logger.LogInformation($"Updating project '{project.Key}' to Razor configuration '{configuration.ConfigurationName}' with language version '{configuration.LanguageVersion}'.");
}
if (currentRootNamespace != rootNamespace)
{
_logger.LogInformation($"Updating project '{project.Key}''s root namespace to '{rootNamespace}'.");
}
var hostProject = new HostProject(project.FilePath, project.IntermediateOutputPath, configuration, rootNamespace, displayName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,52 @@
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);
public static readonly ProjectWorkspaceState Default = new(ImmutableArray<TagHelperDescriptor>.Empty, LanguageVersion.Default);

public ImmutableArray<TagHelperDescriptor> TagHelpers { get; }
public LanguageVersion CSharpLanguageVersion { get; }

private ProjectWorkspaceState(
ImmutableArray<TagHelperDescriptor> tagHelpers)
ImmutableArray<TagHelperDescriptor> tagHelpers,
LanguageVersion csharpLanguageVersion)
{
TagHelpers = tagHelpers;
CSharpLanguageVersion = csharpLanguageVersion;
}

public static ProjectWorkspaceState Create(
ImmutableArray<TagHelperDescriptor> tagHelpers)
=> tagHelpers.IsEmpty
ImmutableArray<TagHelperDescriptor> tagHelpers,
LanguageVersion csharpLanguageVersion = LanguageVersion.Default)
=> tagHelpers.IsEmpty && csharpLanguageVersion == LanguageVersion.Default
? Default
: new(tagHelpers);
: new(tagHelpers, csharpLanguageVersion);

public static ProjectWorkspaceState Create(LanguageVersion csharpLanguageVersion)
=> csharpLanguageVersion == LanguageVersion.Default
? Default
: new(ImmutableArray<TagHelperDescriptor>.Empty, csharpLanguageVersion);

public override bool Equals(object? obj)
=> obj is ProjectWorkspaceState other && Equals(other);

public bool Equals(ProjectWorkspaceState? other)
=> other is not null &&
TagHelpers.SequenceEqual(other.TagHelpers);
TagHelpers.SequenceEqual(other.TagHelpers) &&
CSharpLanguageVersion == other.CSharpLanguageVersion;

public override int GetHashCode()
{
var hash = HashCodeCombiner.Start();

hash.Add(TagHelpers);
hash.Add(CSharpLanguageVersion);

return hash.CombinedHash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;

Expand All @@ -21,7 +22,7 @@ private ProjectWorkspaceStateFormatter()

public override ProjectWorkspaceState Deserialize(ref MessagePackReader reader, SerializerCachingOptions options)
{
reader.ReadArrayHeaderAndVerify(2);
reader.ReadArrayHeaderAndVerify(3);

var checksums = reader.Deserialize<ImmutableArray<Checksum>>(options);

Expand All @@ -46,17 +47,19 @@ public override ProjectWorkspaceState Deserialize(ref MessagePackReader reader,
}

var tagHelpers = builder.DrainToImmutable();
var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32();

return ProjectWorkspaceState.Create(tagHelpers);
return ProjectWorkspaceState.Create(tagHelpers, csharpLanguageVersion);
}

public override void Serialize(ref MessagePackWriter writer, ProjectWorkspaceState value, SerializerCachingOptions options)
{
writer.WriteArrayHeader(2);
writer.WriteArrayHeader(3);

var checksums = value.TagHelpers.SelectAsArray(x => x.Checksum);

writer.Serialize(checksums, options);
writer.Serialize(value.TagHelpers, options);
writer.Write((int)value.CSharpLanguageVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
using MessagePack;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis.CSharp;

namespace Microsoft.AspNetCore.Razor.Serialization.MessagePack.Formatters;

internal sealed class RazorConfigurationFormatter : ValueFormatter<RazorConfiguration>
{
public static readonly ValueFormatter<RazorConfiguration> Instance = new RazorConfigurationFormatter();

// 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 = 6;

private RazorConfigurationFormatter()
{
}
Expand All @@ -29,10 +24,8 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser
var languageVersionText = CachedStringFormatter.Instance.Deserialize(ref reader, options) ?? string.Empty;
var suppressAddComponentParameter = reader.ReadBoolean();
var useConsolidatedMvcViews = reader.ReadBoolean();
var useRoslynTokenizer = reader.ReadBoolean();
var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32();

count -= SerializedPropertyCount;
count -= 4;

using var builder = new PooledArrayBuilder<RazorExtension>();

Expand All @@ -53,16 +46,14 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser
configurationName,
extensions,
UseConsolidatedMvcViews: useConsolidatedMvcViews,
SuppressAddComponentParameter: suppressAddComponentParameter,
UseRoslynTokenizer: useRoslynTokenizer,
CSharpLanguageVersion: csharpLanguageVersion);
SuppressAddComponentParameter: suppressAddComponentParameter);
}

public override void Serialize(ref MessagePackWriter writer, RazorConfiguration value, SerializerCachingOptions options)
{
// Write SerializedPropertyCount values + 1 value per extension.
// Write 4 values + 1 value per extension.
var extensions = value.Extensions;
var count = extensions.Length + SerializedPropertyCount;
var count = extensions.Length + 4;

writer.WriteArrayHeader(count);

Expand All @@ -79,10 +70,8 @@ public override void Serialize(ref MessagePackWriter writer, RazorConfiguration

writer.Write(value.SuppressAddComponentParameter);
writer.Write(value.UseConsolidatedMvcViews);
writer.Write(value.UseRoslynTokenizer);
writer.Write((int)value.CSharpLanguageVersion);

count -= SerializedPropertyCount;
count -= 4;

for (var i = 0; i < count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 7;
public const int Version = 6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Compiler.CSharp;
using Microsoft.NET.Sdk.Razor.SourceGenerators;

namespace Microsoft.AspNetCore.Razor.Utilities;

Expand Down Expand Up @@ -56,9 +55,7 @@ static RazorProjectInfoFactory()
return null;
}

var csharpParseOptions = project.ParseOptions as CSharpParseOptions ?? CSharpParseOptions.Default;
var csharpLanguageVersion = csharpParseOptions.LanguageVersion;
var useRoslynTokenizer = csharpParseOptions.UseRoslynTokenizer();
var csharpLanguageVersion = (project.ParseOptions as CSharpParseOptions)?.LanguageVersion ?? LanguageVersion.Default;

var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
if (compilation is null)
Expand All @@ -79,7 +76,6 @@ static RazorProjectInfoFactory()
builder.SetCSharpLanguageVersion(csharpLanguageVersion);
builder.SetSupportLocalizedComponentNames(); // ProjectState in MS.CA.Razor.Workspaces does this, so I'm doing it too!
builder.Features.Add(new ConfigureRazorParserOptions(useRoslynTokenizer, csharpParseOptions));
};

var engineFactory = ProjectEngineFactories.DefaultProvider.GetFactory(configuration);
Expand All @@ -91,7 +87,7 @@ static RazorProjectInfoFactory()

var tagHelpers = await project.GetTagHelpersAsync(engine, NoOpTelemetryReporter.Instance, cancellationToken).ConfigureAwait(false);

var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers);
var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers, csharpLanguageVersion);

return new RazorProjectInfo(
projectKey: new ProjectKey(intermediateOutputPath),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using Microsoft.AspNetCore.Razor.ProjectSystem;
using System;
using System.Buffers;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.ProjectSystem;

namespace Microsoft.AspNetCore.Razor.Utilities;

Expand Down
Loading

0 comments on commit 0ef2236

Please sign in to comment.