Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vscode fuse feature flag #10169

Merged
merged 13 commits into from
Mar 29, 2024
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.Utilities;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Workspaces;

namespace Microsoft.AspNetCore.Razor.LanguageServer;

Expand All @@ -32,7 +33,7 @@ public ProjectConfigurationFileChangeEventArgs(
_gate = new object();
}

public bool TryDeserialize([NotNullWhen(true)] out RazorProjectInfo? projectInfo)
public bool TryDeserialize(LanguageServerFeatureOptions languageServerFeatureOptions, [NotNullWhen(true)] out RazorProjectInfo? projectInfo)
ryzngard marked this conversation as resolved.
Show resolved Hide resolved
{
if (Kind == RazorFileChangeKind.Removed)
{
Expand All @@ -59,6 +60,15 @@ public bool TryDeserialize([NotNullWhen(true)] out RazorProjectInfo? projectInfo
var normalizedDetectedFilePath = FilePathNormalizer.Normalize(ConfigurationFilePath);
if (string.Equals(normalizedSerializedFilePath, normalizedDetectedFilePath, FilePathComparison.Instance))
{
// Modify the feature flags on the configuration before storing
deserializedProjectInfo = deserializedProjectInfo with
{
Configuration = deserializedProjectInfo.Configuration with
{
RazorLanguageFeatureFlags = new(ForceRuntimeCodeGeneration: languageServerFeatureOptions.ForceRuntimeCodeGeneration)
}
};

_projectInfo = deserializedProjectInfo;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Razor.LanguageServer;
Expand All @@ -22,17 +23,20 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile
{
private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly IRazorProjectService _projectService;
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
private readonly ILogger _logger;
private readonly Dictionary<string, ProjectKey> _configurationToProjectMap;
internal readonly Dictionary<ProjectKey, DelayedProjectInfo> ProjectInfoMap;

public ProjectConfigurationStateSynchronizer(
ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
IRazorProjectService projectService,
IRazorLoggerFactory loggerFactory)
IRazorLoggerFactory loggerFactory,
LanguageServerFeatureOptions languageServerFeatureOptions)
{
_projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_projectService = projectService;
_languageServerFeatureOptions = languageServerFeatureOptions;
_logger = loggerFactory.CreateLogger<ProjectConfigurationStateSynchronizer>();
_configurationToProjectMap = new Dictionary<string, ProjectKey>(FilePathComparer.Instance);
ProjectInfoMap = new Dictionary<ProjectKey, DelayedProjectInfo>();
Expand All @@ -54,7 +58,7 @@ public void ProjectConfigurationFileChanged(ProjectConfigurationFileChangeEventA
case RazorFileChangeKind.Changed:
{
var configurationFilePath = FilePathNormalizer.Normalize(args.ConfigurationFilePath);
if (!args.TryDeserialize(out var projectInfo))
if (!args.TryDeserialize(_languageServerFeatureOptions, out var projectInfo))
{
if (!_configurationToProjectMap.TryGetValue(configurationFilePath, out var lastAssociatedProjectKey))
{
Expand Down Expand Up @@ -90,7 +94,7 @@ public void ProjectConfigurationFileChanged(ProjectConfigurationFileChangeEventA
case RazorFileChangeKind.Added:
{
var configurationFilePath = FilePathNormalizer.Normalize(args.ConfigurationFilePath);
if (!args.TryDeserialize(out var projectInfo))
if (!args.TryDeserialize(_languageServerFeatureOptions, out var projectInfo))
{
// Given that this is the first time we're seeing this configuration file if we can't deserialize it
// then we have to noop.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

namespace Microsoft.AspNetCore.Razor.ProjectSystem;

internal sealed class RazorProjectInfo
internal sealed record class RazorProjectInfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does making this a record help in some way? Note that the equality of this record won't be correct because it will need to use SequenceEquals for the Documents property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It made it cleaner to add a with for modifying readonly properties than having to write out new(...)

{
private static readonly MessagePackSerializerOptions s_options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
RazorProjectInfoResolver.Instance,
StandardResolver.Instance));

public string SerializedFilePath { get; }
public string FilePath { get; }
public RazorConfiguration Configuration { get; }
public string? RootNamespace { get; }
public string DisplayName { get; }
public ProjectWorkspaceState ProjectWorkspaceState { get; }
public ImmutableArray<DocumentSnapshotHandle> Documents { get; }
public string SerializedFilePath { get; init; }
public string FilePath { get; init; }
public RazorConfiguration Configuration { get; init; }
public string? RootNamespace { get; init; }
public string DisplayName { get; init; }
public ProjectWorkspaceState ProjectWorkspaceState { get; init; }
public ImmutableArray<DocumentSnapshotHandle> Documents { get; init; }

public RazorProjectInfo(
string serializedFilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser

count -= 2;

var forceRuntimeCodeGeneration = false;

if (reader.NextMessagePackType is MessagePackType.Boolean)
{
forceRuntimeCodeGeneration = reader.ReadBoolean();
count -= 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this back again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I'm so afraid to break things!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably safe to remove at this point.


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

for (var i = 0; i < count; i++)
Expand Down Expand Up @@ -61,7 +69,7 @@ public override void Serialize(ref MessagePackWriter writer, RazorConfiguration
CachedStringFormatter.Instance.Serialize(ref writer, value.LanguageVersion.ToString(), options);
}

count -= 3;
count -= 2;

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 = 4;
public const int Version = 3;
}
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;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Moq;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void TryDeserialize_RemovedKind_ReturnsFalse()
projectInfoDeserializer: deserializerMock.Object);

// Act
var result = args.TryDeserialize(out var handle);
var result = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle);
ryzngard marked this conversation as resolved.
Show resolved Hide resolved

// Assert
Assert.False(result);
Expand Down Expand Up @@ -70,7 +71,7 @@ public void TryDeserialize_DifferingSerializationPaths_ReturnsFalse()
projectInfoDeserializer: deserializerMock.Object);

// Act
var result = args.TryDeserialize(out var deserializedProjectInfo);
var result = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var deserializedProjectInfo);

// Assert
Assert.False(result);
Expand Down Expand Up @@ -101,8 +102,8 @@ public void TryDeserialize_MemoizesResults()
projectInfoDeserializer: deserializerMock.Object);

// Act
var result1 = args.TryDeserialize(out var projectInfo1);
var result2 = args.TryDeserialize(out var projectInfo2);
var result1 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var projectInfo1);
var result2 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var projectInfo2);

// Assert
Assert.True(result1);
Expand All @@ -125,8 +126,8 @@ public void TryDeserialize_NullFileDeserialization_MemoizesResults_ReturnsFalse(
var args = new ProjectConfigurationFileChangeEventArgs("/path/to/obj/project.razor.bin", RazorFileChangeKind.Changed, deserializerMock.Object);

// Act
var result1 = args.TryDeserialize(out var handle1);
var result2 = args.TryDeserialize(out var handle2);
var result1 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle1);
var result2 = args.TryDeserialize(new TestLanguageServerFeatureOptions(), out var handle2);

// Assert
Assert.False(result1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.AspNetCore.Razor.Serialization;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.CSharp;
using Moq;
Expand Down Expand Up @@ -527,7 +528,7 @@ private async Task WaitForEnqueue_DispatcherThreadAsync(ProjectConfigurationStat

private ProjectConfigurationStateSynchronizer GetSynchronizer(IRazorProjectService razorProjectService)
{
var synchronizer = new ProjectConfigurationStateSynchronizer(Dispatcher, razorProjectService, LoggerFactory);
var synchronizer = new ProjectConfigurationStateSynchronizer(Dispatcher, razorProjectService, LoggerFactory, new TestLanguageServerFeatureOptions());
synchronizer.EnqueueDelay = 5;

return synchronizer;
Expand Down
Loading