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

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

@ -1,8 +1,6 @@
// 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
@ -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.
/// </summary>
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.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.Shell;
@ -28,7 +27,12 @@ namespace Microsoft.VisualStudio.Razor.ProjectSystem;
// MSBuild provides configuration support (>= 2.1).
[AppliesTo("DotNetCoreRazor & DotNetCoreRazorConfiguration")]
[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 static readonly ImmutableHashSet<string> s_ruleNames = ImmutableHashSet.CreateRange(new string[]
@ -40,24 +44,12 @@ internal class DefaultWindowsRazorProjectHost : WindowsRazorProjectHostBase
Rules.RazorGenerateWithTargetPath.SchemaName,
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 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))
{
TryGetRootNamespace(update.Value.CurrentState, out var rootNamespace);
@ -134,7 +126,6 @@ internal class DefaultWindowsRazorProjectHost : WindowsRazorProjectHostBase
// Internal for testing
internal static bool TryGetConfiguration(
IImmutableDictionary<string, IProjectRuleSnapshot> state,
LanguageServerFlags? languageServerFlags,
[NotNullWhen(returnValue: true)] out RazorConfiguration? configuration)
{
if (!TryGetDefaultConfiguration(state, out var defaultConfiguration))
@ -165,8 +156,7 @@ internal class DefaultWindowsRazorProjectHost : WindowsRazorProjectHostBase
configuration = new(
languageVersion,
configurationItem.Key,
extensions,
LanguageServerFlags: languageServerFlags);
extensions);
return true;
}

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

@ -26,13 +26,11 @@ namespace Microsoft.VisualStudio.Razor.ProjectSystem;
[method: ImportingConstructor]
internal sealed class FallbackProjectManager(
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
LanguageServerFeatureOptions languageServerFeatureOptions,
IProjectSnapshotManager projectManager,
IWorkspaceProvider workspaceProvider,
ITelemetryReporter telemetryReporter)
{
private readonly IServiceProvider _serviceProvider = serviceProvider;
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions;
private readonly IProjectSnapshotManager _projectManager = projectManager;
private readonly IWorkspaceProvider _workspaceProvider = workspaceProvider;
private readonly ITelemetryReporter _telemetryReporter = telemetryReporter;
@ -108,7 +106,7 @@ internal sealed class FallbackProjectManager(
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
// generation for closed files for documents in these projects. If these projects become "real", either because capabilities