These flags were explicitly not for the compiler, being not serialized, and hence don't really belong on RazorConfiguration.
They also were only ever set in the VS layer
This commit is contained in:
David Wengier 2024-11-07 14:02:30 +11:00
Родитель 390aced03b
Коммит 19831e9f98
5 изменённых файлов: 11 добавлений и 43 удалений

Просмотреть файл

@ -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;
/// <summary>
/// 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
/// </summary>
public sealed record class LanguageServerFlags(bool ForceRuntimeCodeGeneration);

Просмотреть файл

@ -12,23 +12,20 @@ public sealed record class RazorConfiguration(
string ConfigurationName, string ConfigurationName,
ImmutableArray<RazorExtension> Extensions, ImmutableArray<RazorExtension> Extensions,
bool UseConsolidatedMvcViews = true, bool UseConsolidatedMvcViews = true,
bool SuppressAddComponentParameter = false, bool SuppressAddComponentParameter = false)
LanguageServerFlags? LanguageServerFlags = null)
{ {
public static readonly RazorConfiguration Default = new( public static readonly RazorConfiguration Default = new(
RazorLanguageVersion.Latest, RazorLanguageVersion.Latest,
ConfigurationName: "unnamed", ConfigurationName: "unnamed",
Extensions: [], Extensions: [],
UseConsolidatedMvcViews: true, UseConsolidatedMvcViews: true,
SuppressAddComponentParameter: false, SuppressAddComponentParameter: false);
LanguageServerFlags: null);
public bool Equals(RazorConfiguration? other) public bool Equals(RazorConfiguration? other)
=> other is not null && => other is not null &&
LanguageVersion == other.LanguageVersion && LanguageVersion == other.LanguageVersion &&
ConfigurationName == other.ConfigurationName && ConfigurationName == other.ConfigurationName &&
SuppressAddComponentParameter == other.SuppressAddComponentParameter && SuppressAddComponentParameter == other.SuppressAddComponentParameter &&
LanguageServerFlags == other.LanguageServerFlags &&
UseConsolidatedMvcViews == other.UseConsolidatedMvcViews && UseConsolidatedMvcViews == other.UseConsolidatedMvcViews &&
Extensions.SequenceEqual(other.Extensions); Extensions.SequenceEqual(other.Extensions);
@ -40,7 +37,6 @@ public sealed record class RazorConfiguration(
hash.Add(Extensions); hash.Add(Extensions);
hash.Add(SuppressAddComponentParameter); hash.Add(SuppressAddComponentParameter);
hash.Add(UseConsolidatedMvcViews); hash.Add(UseConsolidatedMvcViews);
hash.Add(LanguageServerFlags);
return hash; return hash;
} }
} }

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information. // 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; namespace Microsoft.CodeAnalysis.Razor.Workspaces;
internal abstract class LanguageServerFeatureOptions internal abstract class LanguageServerFeatureOptions
@ -41,7 +39,4 @@ internal abstract class LanguageServerFeatureOptions
/// When enabled, design time code will not be generated. All tooling will be using runtime code generation. /// When enabled, design time code will not be generated. All tooling will be using runtime code generation.
/// </summary> /// </summary>
public abstract bool ForceRuntimeCodeGeneration { get; } public abstract bool ForceRuntimeCodeGeneration { get; }
public LanguageServerFlags ToLanguageServerFlags()
=> new(ForceRuntimeCodeGeneration);
} }

Просмотреть файл

@ -15,7 +15,6 @@ using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.ProjectSystem; using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.Properties; using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell;
@ -28,7 +27,12 @@ namespace Microsoft.VisualStudio.Razor.ProjectSystem;
// MSBuild provides configuration support (>= 2.1). // MSBuild provides configuration support (>= 2.1).
[AppliesTo("DotNetCoreRazor & DotNetCoreRazorConfiguration")] [AppliesTo("DotNetCoreRazor & DotNetCoreRazorConfiguration")]
[Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))] [Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))]
internal class DefaultWindowsRazorProjectHost : WindowsRazorProjectHostBase [method: ImportingConstructor]
internal class DefaultWindowsRazorProjectHost(
IUnconfiguredProjectCommonServices commonServices,
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
IProjectSnapshotManager projectManager)
: WindowsRazorProjectHostBase(commonServices, serviceProvider, projectManager)
{ {
private const string RootNamespaceProperty = "RootNamespace"; private const string RootNamespaceProperty = "RootNamespace";
private static readonly ImmutableHashSet<string> s_ruleNames = ImmutableHashSet.CreateRange(new string[] private static readonly ImmutableHashSet<string> s_ruleNames = ImmutableHashSet.CreateRange(new string[]
@ -40,24 +44,12 @@ internal class DefaultWindowsRazorProjectHost : WindowsRazorProjectHostBase
Rules.RazorGenerateWithTargetPath.SchemaName, Rules.RazorGenerateWithTargetPath.SchemaName,
ConfigurationGeneralSchemaName, ConfigurationGeneralSchemaName,
}); });
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
[ImportingConstructor]
public DefaultWindowsRazorProjectHost(
IUnconfiguredProjectCommonServices commonServices,
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
IProjectSnapshotManager projectManager,
LanguageServerFeatureOptions languageServerFeatureOptions)
: base(commonServices, serviceProvider, projectManager)
{
_languageServerFeatureOptions = languageServerFeatureOptions;
}
protected override ImmutableHashSet<string> GetRuleNames() => s_ruleNames; protected override ImmutableHashSet<string> GetRuleNames() => s_ruleNames;
protected override async Task HandleProjectChangeAsync(string sliceDimensions, IProjectVersionedValue<IProjectSubscriptionUpdate> update) protected override async Task HandleProjectChangeAsync(string sliceDimensions, IProjectVersionedValue<IProjectSubscriptionUpdate> update)
{ {
if (TryGetConfiguration(update.Value.CurrentState, _languageServerFeatureOptions.ToLanguageServerFlags(), out var configuration) && if (TryGetConfiguration(update.Value.CurrentState, out var configuration) &&
TryGetIntermediateOutputPath(update.Value.CurrentState, out var intermediatePath)) TryGetIntermediateOutputPath(update.Value.CurrentState, out var intermediatePath))
{ {
TryGetRootNamespace(update.Value.CurrentState, out var rootNamespace); TryGetRootNamespace(update.Value.CurrentState, out var rootNamespace);
@ -134,7 +126,6 @@ internal class DefaultWindowsRazorProjectHost : WindowsRazorProjectHostBase
// Internal for testing // Internal for testing
internal static bool TryGetConfiguration( internal static bool TryGetConfiguration(
IImmutableDictionary<string, IProjectRuleSnapshot> state, IImmutableDictionary<string, IProjectRuleSnapshot> state,
LanguageServerFlags? languageServerFlags,
[NotNullWhen(returnValue: true)] out RazorConfiguration? configuration) [NotNullWhen(returnValue: true)] out RazorConfiguration? configuration)
{ {
if (!TryGetDefaultConfiguration(state, out var defaultConfiguration)) if (!TryGetDefaultConfiguration(state, out var defaultConfiguration))
@ -165,8 +156,7 @@ internal class DefaultWindowsRazorProjectHost : WindowsRazorProjectHostBase
configuration = new( configuration = new(
languageVersion, languageVersion,
configurationItem.Key, configurationItem.Key,
extensions, extensions);
LanguageServerFlags: languageServerFlags);
return true; return true;
} }

Просмотреть файл

@ -26,13 +26,11 @@ namespace Microsoft.VisualStudio.Razor.ProjectSystem;
[method: ImportingConstructor] [method: ImportingConstructor]
internal sealed class FallbackProjectManager( internal sealed class FallbackProjectManager(
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
LanguageServerFeatureOptions languageServerFeatureOptions,
IProjectSnapshotManager projectManager, IProjectSnapshotManager projectManager,
IWorkspaceProvider workspaceProvider, IWorkspaceProvider workspaceProvider,
ITelemetryReporter telemetryReporter) ITelemetryReporter telemetryReporter)
{ {
private readonly IServiceProvider _serviceProvider = serviceProvider; private readonly IServiceProvider _serviceProvider = serviceProvider;
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions;
private readonly IProjectSnapshotManager _projectManager = projectManager; private readonly IProjectSnapshotManager _projectManager = projectManager;
private readonly IWorkspaceProvider _workspaceProvider = workspaceProvider; private readonly IWorkspaceProvider _workspaceProvider = workspaceProvider;
private readonly ITelemetryReporter _telemetryReporter = telemetryReporter; private readonly ITelemetryReporter _telemetryReporter = telemetryReporter;
@ -108,7 +106,7 @@ internal sealed class FallbackProjectManager(
var rootNamespace = project.DefaultNamespace; var rootNamespace = project.DefaultNamespace;
var configuration = FallbackRazorConfiguration.Latest with { LanguageServerFlags = _languageServerFeatureOptions.ToLanguageServerFlags() }; var configuration = FallbackRazorConfiguration.Latest;
// We create this as a fallback project so that other parts of the system can reason about them - eg we don't do code // 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 // generation for closed files for documents in these projects. If these projects become "real", either because capabilities