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

Move RootNamespace from HostProject to RazorConfiguration #11109

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed record class RazorConfiguration(
bool SuppressAddComponentParameter = false,
LanguageServerFlags? LanguageServerFlags = null,
bool UseRoslynTokenizer = false,
LanguageVersion CSharpLanguageVersion = LanguageVersion.Default)
LanguageVersion CSharpLanguageVersion = LanguageVersion.Default,
string? RootNamespace = null)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this isn't referenced anywhere from the compiler layer; why does it need to be in the compiler's RazorConfiguration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RazorConfiguration serves double duty right now, as the thing that the compiler reads some things from, and the type that stores all of the compiler configuration knobs that are serialized between the IDE host and the LSP server. There has been much discussion about removing the configure lambdas for configuring the compiler, and moving to fully utilise the RazorConfiguration, so this is something of a hedge towards that.

{
public static readonly RazorConfiguration Default = new(
RazorLanguageVersion.Latest,
Expand All @@ -32,6 +33,7 @@ public bool Equals(RazorConfiguration? other)
UseConsolidatedMvcViews == other.UseConsolidatedMvcViews &&
UseRoslynTokenizer == other.UseRoslynTokenizer &&
CSharpLanguageVersion == other.CSharpLanguageVersion &&
RootNamespace == other.RootNamespace &&
Extensions.SequenceEqual(other.Extensions);

public override int GetHashCode()
Expand All @@ -45,6 +47,7 @@ public override int GetHashCode()
hash.Add(LanguageServerFlags);
hash.Add(UseRoslynTokenizer);
hash.Add(CSharpLanguageVersion);
hash.Add(RootNamespace);
return hash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private protected virtual LanguageServerFeatureOptions BuildFeatureOptions()
internal async Task<IDocumentSnapshot> GetDocumentSnapshotAsync(string projectFilePath, string filePath, string targetPath)
{
var intermediateOutputPath = Path.Combine(Path.GetDirectoryName(projectFilePath), "obj");
var hostProject = new HostProject(projectFilePath, intermediateOutputPath, RazorConfiguration.Default, rootNamespace: null);
var hostProject = new HostProject(projectFilePath, intermediateOutputPath, RazorConfiguration.Default);
using var fileStream = new FileStream(filePath, FileMode.Open);
var text = SourceText.From(fileStream);
var textLoader = TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected ProjectSnapshotManagerBenchmarkBase(int documentCount = 100)
{
var projectRoot = Path.Combine(Helpers.GetTestAppsPath(), "LargeProject");

HostProject = new HostProject(Path.Combine(projectRoot, "LargeProject.csproj"), Path.Combine(projectRoot, "obj"), FallbackRazorConfiguration.MVC_2_1, rootNamespace: null);
HostProject = new HostProject(Path.Combine(projectRoot, "LargeProject.csproj"), Path.Combine(projectRoot, "obj"), FallbackRazorConfiguration.MVC_2_1);

using var _1 = ArrayBuilderPool<TextLoader>.GetPooledObject(out var textLoaders);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"__Version": 7,
"__Version": 8,
"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,
"RootNamespace": "Kendo.Mvc.Examples",
"Extensions": [
"MVC-3.0"
]
Expand Down Expand Up @@ -159530,7 +159531,6 @@
}
]
},
"RootNamespace": "Kendo.Mvc.Examples",
"Documents": [
{
"FilePath": "C:\\Program Files (x86)\\Progress\\Telerik UI for ASP.NET Core R1 2023\\wrappers\\aspnetcore\\Examples\\AspNet.Core\\VS2022\\Kendo.Mvc.Examples\\Views\\Linear_Gauge\\Scale_Options.cshtml",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"__Version": 7,
"__Version": 8,
"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,
"RootNamespace": "blazorserver",
"Extensions": [ "MVC-3.0" ]
},
"ProjectWorkspaceState": {
Expand Down Expand Up @@ -16129,7 +16130,6 @@
}
]
},
"RootNamespace": "blazorserver",
"Documents": [
{
"FilePath": "C:\\Users\\admin\\location\\blazorserver\\Shared\\MainLayout.razor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ private MiscFilesHostProject(
string filePath,
string intermediateOutputPath,
RazorConfiguration razorConfiguration,
string? rootNamespace, string?
displayName = null)
: base(filePath, intermediateOutputPath, razorConfiguration, rootNamespace, displayName)
string? displayName = null)
: base(filePath, intermediateOutputPath, razorConfiguration, displayName)
{
DirectoryPath = directory;
}
Expand All @@ -45,7 +44,6 @@ private static MiscFilesHostProject Create()
normalizedPath,
normalizedPath,
FallbackRazorConfiguration.Latest,
rootNamespace: null,
"Miscellaneous Files");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public async Task<ProjectKey> AddProjectAsync(
string filePath,
string intermediateOutputPath,
RazorConfiguration? configuration,
string? rootNamespace,
string? displayName,
CancellationToken cancellationToken)
{
Expand All @@ -33,7 +32,7 @@ public async Task<ProjectKey> AddProjectAsync(

return await instance._projectManager
.UpdateAsync(
updater => service.AddProjectCore(updater, filePath, intermediateOutputPath, configuration, rootNamespace, displayName),
updater => service.AddProjectCore(updater, filePath, intermediateOutputPath, configuration, displayName),
cancellationToken)
.ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ await AddOrUpdateProjectCoreAsync(
projectInfo.ProjectKey,
projectInfo.FilePath,
projectInfo.Configuration,
projectInfo.RootNamespace,
projectInfo.DisplayName,
projectInfo.ProjectWorkspaceState,
projectInfo.Documents,
Expand Down Expand Up @@ -114,7 +113,6 @@ await AddOrUpdateProjectCoreAsync(
projectInfo.ProjectKey,
projectInfo.FilePath,
projectInfo.Configuration,
projectInfo.RootNamespace,
projectInfo.DisplayName,
projectInfo.ProjectWorkspaceState,
projectInfo.Documents,
Expand All @@ -133,7 +131,6 @@ await AddOrUpdateProjectCoreAsync(
projectKey,
filePath: null,
configuration: null,
rootNamespace: null,
displayName: "",
ProjectWorkspaceState.Default,
documents: [],
Expand Down Expand Up @@ -313,11 +310,11 @@ private void ActOnDocumentInMultipleProjects(string filePath, Action<IProjectSna
}
}

private ProjectKey AddProjectCore(ProjectSnapshotManager.Updater updater, string filePath, string intermediateOutputPath, RazorConfiguration? configuration, string? rootNamespace, string? displayName)
private ProjectKey AddProjectCore(ProjectSnapshotManager.Updater updater, string filePath, string intermediateOutputPath, RazorConfiguration? configuration, string? displayName)
{
var normalizedPath = FilePathNormalizer.Normalize(filePath);
var hostProject = new HostProject(
normalizedPath, intermediateOutputPath, configuration ?? FallbackRazorConfiguration.Latest, rootNamespace, displayName);
normalizedPath, intermediateOutputPath, configuration ?? FallbackRazorConfiguration.Latest, displayName);

// ProjectAdded will no-op if the project already exists
updater.ProjectAdded(hostProject);
Expand All @@ -331,7 +328,6 @@ private Task AddOrUpdateProjectCoreAsync(
ProjectKey projectKey,
string? filePath,
RazorConfiguration? configuration,
string? rootNamespace,
string? displayName,
ProjectWorkspaceState projectWorkspaceState,
ImmutableArray<DocumentSnapshotHandle> documents,
Expand All @@ -356,7 +352,7 @@ private Task AddOrUpdateProjectCoreAsync(
// the intermediate output path from the id
var intermediateOutputPath = projectKey.Id;

var newKey = AddProjectCore(updater, filePath, intermediateOutputPath, configuration, rootNamespace, displayName);
var newKey = AddProjectCore(updater, filePath, intermediateOutputPath, configuration, displayName);
Debug.Assert(newKey == projectKey);

project = _projectManager.GetLoadedProject(projectKey);
Expand All @@ -371,9 +367,7 @@ private Task AddOrUpdateProjectCoreAsync(

updater.ProjectWorkspaceStateChanged(project.Key, projectWorkspaceState);

var currentRootNamespace = project.RootNamespace;
if (project.Configuration == configuration &&
currentRootNamespace == rootNamespace)
if (project.Configuration == configuration)
{
_logger.LogTrace($"Skipping configuration update for '{project.Key}' as the configuration and root namespace are unchanged.");
return;
Expand All @@ -386,10 +380,10 @@ private Task AddOrUpdateProjectCoreAsync(
}
else
{
_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}'.");
}

var hostProject = new HostProject(project.FilePath, project.IntermediateOutputPath, configuration, rootNamespace, displayName);
var hostProject = new HostProject(project.FilePath, project.IntermediateOutputPath, configuration, displayName);
updater.ProjectConfigurationChanged(hostProject);
},
cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ internal sealed record class RazorProjectInfo
public ProjectKey ProjectKey { 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; }
Expand All @@ -37,15 +36,13 @@ public RazorProjectInfo(
ProjectKey projectKey,
string filePath,
RazorConfiguration configuration,
string? rootNamespace,
string displayName,
ProjectWorkspaceState projectWorkspaceState,
ImmutableArray<DocumentSnapshotHandle> documents)
{
ProjectKey = projectKey;
FilePath = filePath;
Configuration = configuration;
RootNamespace = rootNamespace;
DisplayName = displayName;
ProjectWorkspaceState = projectWorkspaceState;
Documents = documents.NullToEmpty();
Expand All @@ -56,7 +53,6 @@ public bool Equals(RazorProjectInfo? other)
ProjectKey == other.ProjectKey &&
FilePath == other.FilePath &&
Configuration.Equals(other.Configuration) &&
RootNamespace == other.RootNamespace &&
DisplayName == other.DisplayName &&
ProjectWorkspaceState.Equals(other.ProjectWorkspaceState) &&
Documents.SequenceEqual(other.Documents);
Expand All @@ -68,7 +64,6 @@ public override int GetHashCode()
hash.Add(ProjectKey);
hash.Add(FilePath);
hash.Add(Configuration);
hash.Add(RootNamespace);
hash.Add(DisplayName);
hash.Add(ProjectWorkspaceState);
hash.Add(Documents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@ private ProjectSnapshotHandleFormatter()

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

var id = GuidFormatter.Instance.Deserialize(ref reader, options);
var projectId = ProjectId.CreateFromSerialized(id);

var configuration = reader.DeserializeOrNull<RazorConfiguration>(options) ?? RazorConfiguration.Default;
var rootNamespace = CachedStringFormatter.Instance.Deserialize(ref reader, options);

return new(projectId, configuration, rootNamespace);
return new(projectId, configuration);
}

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

GuidFormatter.Instance.Serialize(ref writer, value.ProjectId.Id, options);
writer.Serialize(value.Configuration, options);
CachedStringFormatter.Instance.Serialize(ref writer, value.RootNamespace, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,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 = 6;
private const int SerializedPropertyCount = 7;

private RazorConfigurationFormatter()
{
Expand All @@ -31,6 +31,7 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser
var useConsolidatedMvcViews = reader.ReadBoolean();
var useRoslynTokenizer = reader.ReadBoolean();
var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32();
var rootNamespace = CachedStringFormatter.Instance.Deserialize(ref reader, options);

count -= SerializedPropertyCount;

Expand All @@ -55,7 +56,8 @@ public override RazorConfiguration Deserialize(ref MessagePackReader reader, Ser
UseConsolidatedMvcViews: useConsolidatedMvcViews,
SuppressAddComponentParameter: suppressAddComponentParameter,
UseRoslynTokenizer: useRoslynTokenizer,
CSharpLanguageVersion: csharpLanguageVersion);
CSharpLanguageVersion: csharpLanguageVersion,
RootNamespace: rootNamespace);
}

public override void Serialize(ref MessagePackWriter writer, RazorConfiguration value, SerializerCachingOptions options)
Expand All @@ -81,6 +83,7 @@ public override void Serialize(ref MessagePackWriter writer, RazorConfiguration
writer.Write(value.UseConsolidatedMvcViews);
writer.Write(value.UseRoslynTokenizer);
writer.Write((int)value.CSharpLanguageVersion);
CachedStringFormatter.Instance.Serialize(ref writer, value.RootNamespace, options);

count -= SerializedPropertyCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ public override RazorProjectInfo Deserialize(ref MessagePackReader reader, Seria
var filePath = CachedStringFormatter.Instance.Deserialize(ref reader, options).AssumeNotNull();
var configuration = reader.DeserializeOrNull<RazorConfiguration>(options) ?? RazorConfiguration.Default;
var projectWorkspaceState = reader.DeserializeOrNull<ProjectWorkspaceState>(options) ?? ProjectWorkspaceState.Default;
var rootNamespace = CachedStringFormatter.Instance.Deserialize(ref reader, options);
var displayName = CachedStringFormatter.Instance.Deserialize(ref reader, options).AssumeNotNull();
var documents = reader.Deserialize<ImmutableArray<DocumentSnapshotHandle>>(options);

return new RazorProjectInfo(new ProjectKey(projectKeyId), filePath, configuration, rootNamespace, displayName, projectWorkspaceState, documents);
return new RazorProjectInfo(new ProjectKey(projectKeyId), filePath, configuration, displayName, projectWorkspaceState, documents);
}

public override void Serialize(ref MessagePackWriter writer, RazorProjectInfo value, SerializerCachingOptions options)
Expand All @@ -47,7 +46,6 @@ public override void Serialize(ref MessagePackWriter writer, RazorProjectInfo va
CachedStringFormatter.Instance.Serialize(ref writer, value.FilePath, options);
writer.Serialize(value.Configuration, options);
writer.Serialize(value.ProjectWorkspaceState, options);
CachedStringFormatter.Instance.Serialize(ref writer, value.RootNamespace, options);
CachedStringFormatter.Instance.Serialize(ref writer, value.DisplayName, options);
writer.Serialize(value.Documents, options);
}
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 = 8;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ internal record ProjectSnapshotHandle
{
public ProjectId ProjectId { get; }
public RazorConfiguration Configuration { get; }
public string? RootNamespace { get; }

public ProjectSnapshotHandle(ProjectId projectId, RazorConfiguration configuration, string? rootNamespace)
public ProjectSnapshotHandle(ProjectId projectId, RazorConfiguration configuration)
{
ProjectId = projectId ?? throw new ArgumentNullException(nameof(projectId));
Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
RootNamespace = rootNamespace;
}
}
Loading
Loading