diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs index e49485e47f7..7b8f0eabb4c 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorConfiguration.cs @@ -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) { public static readonly RazorConfiguration Default = new( RazorLanguageVersion.Latest, @@ -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() @@ -45,6 +47,7 @@ public override int GetHashCode() hash.Add(LanguageServerFlags); hash.Add(UseRoslynTokenizer); hash.Add(CSharpLanguageVersion); + hash.Add(RootNamespace); return hash; } } diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs index 5af8926bdc3..35f55941144 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs @@ -62,7 +62,7 @@ private protected virtual LanguageServerFeatureOptions BuildFeatureOptions() internal async Task 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())); diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs index d8ab181d8d9..11c4b1364e8 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs @@ -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.GetPooledObject(out var textLoaders); diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json index 1bf7c4e050d..12f96f08aba 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/Telerik/Kendo.Mvc.Examples.project.razor.json @@ -1,5 +1,5 @@ { - "__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": { @@ -7,6 +7,7 @@ "LanguageVersion": "7.0", "UseRoslynTokenizer": true, "CSharpLanguageVersion": 1100, + "RootNamespace": "Kendo.Mvc.Examples", "Extensions": [ "MVC-3.0" ] @@ -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", diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json index e00a7130e2f..ccdb7c2dde6 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Resources/project.razor.json @@ -1,5 +1,5 @@ { - "__Version": 7, + "__Version": 8, "ProjectKey": "C:\\Users\\admin\\location\\blazorserver\\obj\\Debug\\net7.0\\", "FilePath": "C:\\Users\\admin\\location\\blazorserver\\blazorserver.csproj", "Configuration": { @@ -7,6 +7,7 @@ "LanguageVersion": "3.0", "UseRoslynTokenizer": true, "CSharpLanguageVersion": 800, + "RootNamespace": "blazorserver", "Extensions": [ "MVC-3.0" ] }, "ProjectWorkspaceState": { @@ -16129,7 +16130,6 @@ } ] }, - "RootNamespace": "blazorserver", "Documents": [ { "FilePath": "C:\\Users\\admin\\location\\blazorserver\\Shared\\MainLayout.razor", diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/MiscFilesHostProject.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/MiscFilesHostProject.cs index cb29d7e08ce..827d06ef3f5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/MiscFilesHostProject.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/MiscFilesHostProject.cs @@ -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; } @@ -45,7 +44,6 @@ private static MiscFilesHostProject Create() normalizedPath, normalizedPath, FallbackRazorConfiguration.Latest, - rootNamespace: null, "Miscellaneous Files"); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.TestAccessor.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.TestAccessor.cs index a0312a283c8..3038b7367d2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.TestAccessor.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.TestAccessor.cs @@ -23,7 +23,6 @@ public async Task AddProjectAsync( string filePath, string intermediateOutputPath, RazorConfiguration? configuration, - string? rootNamespace, string? displayName, CancellationToken cancellationToken) { @@ -33,7 +32,7 @@ public async Task 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); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs index 52dc25f7a83..ce84cccb437 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs @@ -85,7 +85,6 @@ await AddOrUpdateProjectCoreAsync( projectInfo.ProjectKey, projectInfo.FilePath, projectInfo.Configuration, - projectInfo.RootNamespace, projectInfo.DisplayName, projectInfo.ProjectWorkspaceState, projectInfo.Documents, @@ -114,7 +113,6 @@ await AddOrUpdateProjectCoreAsync( projectInfo.ProjectKey, projectInfo.FilePath, projectInfo.Configuration, - projectInfo.RootNamespace, projectInfo.DisplayName, projectInfo.ProjectWorkspaceState, projectInfo.Documents, @@ -133,7 +131,6 @@ await AddOrUpdateProjectCoreAsync( projectKey, filePath: null, configuration: null, - rootNamespace: null, displayName: "", ProjectWorkspaceState.Default, documents: [], @@ -313,11 +310,11 @@ private void ActOnDocumentInMultipleProjects(string filePath, Action documents, @@ -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); @@ -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; @@ -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); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs index 86158c6ceb9..ed87fa9dfae 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/ProjectSystem/RazorProjectInfo.cs @@ -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 Documents { get; init; } @@ -37,7 +36,6 @@ public RazorProjectInfo( ProjectKey projectKey, string filePath, RazorConfiguration configuration, - string? rootNamespace, string displayName, ProjectWorkspaceState projectWorkspaceState, ImmutableArray documents) @@ -45,7 +43,6 @@ public RazorProjectInfo( ProjectKey = projectKey; FilePath = filePath; Configuration = configuration; - RootNamespace = rootNamespace; DisplayName = displayName; ProjectWorkspaceState = projectWorkspaceState; Documents = documents.NullToEmpty(); @@ -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); @@ -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); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectSnapshotHandleFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectSnapshotHandleFormatter.cs index 52763e77807..a900367a3d3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectSnapshotHandleFormatter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/ProjectSnapshotHandleFormatter.cs @@ -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(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); } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs index 4bb6b57f8a1..cecc65ef7a1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/Formatters/RazorConfigurationFormatter.cs @@ -14,7 +14,7 @@ internal sealed class RazorConfigurationFormatter : ValueFormatter(options) ?? RazorConfiguration.Default; var projectWorkspaceState = reader.DeserializeOrNull(options) ?? ProjectWorkspaceState.Default; - var rootNamespace = CachedStringFormatter.Instance.Deserialize(ref reader, options); var displayName = CachedStringFormatter.Instance.Deserialize(ref reader, options).AssumeNotNull(); var documents = reader.Deserialize>(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) @@ -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); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs index bb7d6524f7b..c791d0eedf7 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/MessagePack/SerializationFormat.cs @@ -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; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ProjectSnapshotHandle.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ProjectSnapshotHandle.cs index cf8de7e3bc9..53be623a236 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ProjectSnapshotHandle.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Serialization/ProjectSnapshotHandle.cs @@ -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; } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs index a5649c9405c..2c5ec76f961 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs @@ -15,7 +15,6 @@ using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Compiler.CSharp; using Microsoft.NET.Sdk.Razor.SourceGenerators; @@ -56,30 +55,20 @@ static RazorProjectInfoFactory() return null; } - var csharpParseOptions = project.ParseOptions as CSharpParseOptions ?? CSharpParseOptions.Default; - var csharpLanguageVersion = csharpParseOptions.LanguageVersion; - var useRoslynTokenizer = csharpParseOptions.UseRoslynTokenizer(); - - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); - if (compilation is null) + var (configuration, csharpParseOptions) = await ComputeRazorConfigurationOptionsAsync(project, cancellationToken).ConfigureAwait(false); + if (configuration is null) { return null; } - var options = project.AnalyzerOptions.AnalyzerConfigOptionsProvider; - var configuration = ComputeRazorConfigurationOptions(options, compilation, out var defaultNamespace); var fileSystem = RazorProjectFileSystem.Create(projectPath); var defaultConfigure = (RazorProjectEngineBuilder builder) => { - if (defaultNamespace is not null) - { - builder.SetRootNamespace(defaultNamespace); - } - - builder.SetCSharpLanguageVersion(csharpLanguageVersion); + builder.SetRootNamespace(configuration.RootNamespace ?? "ASP"); + builder.SetCSharpLanguageVersion(configuration.CSharpLanguageVersion); builder.SetSupportLocalizedComponentNames(); // ProjectState in MS.CA.Razor.Workspaces does this, so I'm doing it too! - builder.Features.Add(new ConfigureRazorParserOptions(useRoslynTokenizer, csharpParseOptions)); + builder.Features.Add(new ConfigureRazorParserOptions(configuration.UseRoslynTokenizer, csharpParseOptions)); }; var engineFactory = ProjectEngineFactories.DefaultProvider.GetFactory(configuration); @@ -97,16 +86,25 @@ static RazorProjectInfoFactory() projectKey: new ProjectKey(intermediateOutputPath), filePath: project.FilePath!, configuration: configuration, - rootNamespace: defaultNamespace, displayName: project.Name, projectWorkspaceState: projectWorkspaceState, documents: documents); } - private static RazorConfiguration ComputeRazorConfigurationOptions(AnalyzerConfigOptionsProvider options, Compilation compilation, out string defaultNamespace) + private static async Task<(RazorConfiguration?, CSharpParseOptions)> ComputeRazorConfigurationOptionsAsync(Project project, CancellationToken cancellationToken) { // See RazorSourceGenerator.RazorProviders.cs + var csharpParseOptions = project.ParseOptions as CSharpParseOptions ?? CSharpParseOptions.Default; + var csharpLanguageVersion = csharpParseOptions.LanguageVersion; + var useRoslynTokenizer = csharpParseOptions.UseRoslynTokenizer(); + + var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + if (compilation is null) + { + return (null, csharpParseOptions); + } + var options = project.AnalyzerOptions.AnalyzerConfigOptionsProvider; var globalOptions = options.GlobalOptions; globalOptions.TryGetValue("build_property.RazorConfiguration", out var configurationName); @@ -114,6 +112,7 @@ private static RazorConfiguration ComputeRazorConfigurationOptions(AnalyzerConfi configurationName ??= "MVC-3.0"; // TODO: Source generator uses "default" here?? globalOptions.TryGetValue("build_property.RootNamespace", out var rootNamespace); + var defaultNamespace = rootNamespace ?? project.DefaultNamespace; if (!globalOptions.TryGetValue("build_property.RazorLangVersion", out var razorLanguageVersionString) || !RazorLanguageVersion.TryParse(razorLanguageVersionString, out var razorLanguageVersion)) @@ -128,11 +127,12 @@ private static RazorConfiguration ComputeRazorConfigurationOptions(AnalyzerConfi configurationName, Extensions: [], UseConsolidatedMvcViews: true, - suppressAddComponentParameter); - - defaultNamespace = rootNamespace ?? "ASP"; // TODO: Source generator does this. Do we want it? + suppressAddComponentParameter, + RootNamespace: defaultNamespace, + UseRoslynTokenizer: useRoslynTokenizer, + CSharpLanguageVersion: csharpLanguageVersion); - return razorConfiguration; + return (razorConfiguration, csharpParseOptions); } internal static ImmutableArray GetDocuments(Project project, string projectPath) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/HostProject.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/HostProject.cs index c1fdd685eb2..ee3dd392d4a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/HostProject.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/HostProject.cs @@ -24,8 +24,6 @@ internal record class HostProject public RazorConfiguration Configuration { get; init; } - public string? RootNamespace { get; init; } - /// /// An extra user-friendly string to show in the VS navigation bar to help the user, of the form "{ProjectFileName} ({Flavor})" /// @@ -35,13 +33,11 @@ public HostProject( string filePath, string intermediateOutputPath, RazorConfiguration configuration, - string? rootNamespace, string? displayName = null) { FilePath = filePath; IntermediateOutputPath = intermediateOutputPath; Configuration = configuration; - RootNamespace = rootNamespace; DisplayName = displayName ?? Path.GetFileNameWithoutExtension(filePath); Key = new(intermediateOutputPath); @@ -59,7 +55,6 @@ public virtual bool Equals(HostProject? other) FilePathComparer.Instance.Equals(FilePath, other.FilePath) && FilePathComparer.Instance.Equals(IntermediateOutputPath, other.IntermediateOutputPath) && Configuration == other.Configuration && - RootNamespace == other.RootNamespace && DisplayName == other.DisplayName; } @@ -70,7 +65,6 @@ public override int GetHashCode() hash.Add(FilePath, FilePathComparer.Instance); hash.Add(IntermediateOutputPath, FilePathComparer.Instance); hash.Add(Configuration); - hash.Add(RootNamespace); hash.Add(DisplayName); return hash.CombinedHash; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshot.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshot.cs index ea4d2ea12de..434ea362fdd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshot.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshot.cs @@ -28,7 +28,6 @@ internal interface IProjectSnapshot /// string IntermediateOutputPath { get; } - string? RootNamespace { get; } string DisplayName { get; } VersionStamp Version { get; } ProjectWorkspaceState ProjectWorkspaceState { get; } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs index 693b7d6265a..c26ddd967bf 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/IProjectSnapshotExtensions.cs @@ -32,7 +32,6 @@ public static RazorProjectInfo ToRazorProjectInfo(this IProjectSnapshot project) projectKey: project.Key, filePath: project.FilePath, configuration: project.Configuration, - rootNamespace: project.RootNamespace, displayName: project.DisplayName, projectWorkspaceState: project.ProjectWorkspaceState, documents: documents.DrainToImmutable()); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshot.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshot.cs index e2fe87b71a8..3c17317a108 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshot.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshot.cs @@ -28,7 +28,6 @@ internal sealed class ProjectSnapshot(ProjectState state) : IProjectSnapshot public IEnumerable DocumentFilePaths => _state.Documents.Keys; public string FilePath => _state.HostProject.FilePath; public string IntermediateOutputPath => _state.HostProject.IntermediateOutputPath; - public string? RootNamespace => _state.HostProject.RootNamespace; public string DisplayName => _state.HostProject.DisplayName; public VersionStamp Version => _state.Version; public ProjectWorkspaceState ProjectWorkspaceState => _state.ProjectWorkspaceState; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectState.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectState.cs index 1fe54321749..5561c0108c3 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectState.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectState.cs @@ -197,7 +197,7 @@ RazorProjectEngine CreateProjectEngine() return _projectEngineFactoryProvider.Create(configuration, rootDirectoryPath, builder => { - builder.SetRootNamespace(HostProject.RootNamespace); + builder.SetRootNamespace(configuration.RootNamespace); builder.SetCSharpLanguageVersion(configuration.CSharpLanguageVersion); builder.SetSupportLocalizedComponentNames(); builder.Features.Add(new ConfigureRazorParserOptions(useRoslynTokenizer: configuration.UseRoslynTokenizer, CSharpParseOptions.Default)); @@ -345,8 +345,7 @@ public ProjectState WithHostProject(HostProject hostProject) throw new ArgumentNullException(nameof(hostProject)); } - if (HostProject.Configuration.Equals(hostProject.Configuration) && - HostProject.RootNamespace == hostProject.RootNamespace) + if (HostProject.Configuration == hostProject.Configuration) { return this; } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs index 1720c1a09be..90db6836197 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteProjectSnapshot.cs @@ -58,10 +58,10 @@ public RemoteProjectSnapshot(Project project, RemoteSolutionSnapshot solutionSna rootDirectoryPath: Path.GetDirectoryName(FilePath).AssumeNotNull(), configure: builder => { - builder.SetRootNamespace(RootNamespace); - builder.SetCSharpLanguageVersion(CSharpLanguageVersion); + builder.SetRootNamespace(configuration.RootNamespace ?? "ASP"); + builder.SetCSharpLanguageVersion(configuration.CSharpLanguageVersion); builder.SetSupportLocalizedComponentNames(); - builder.Features.Add(new ConfigureRazorParserOptions(useRoslynTokenizer: csharpParseOptions.UseRoslynTokenizer(), csharpParseOptions)); + builder.Features.Add(new ConfigureRazorParserOptions(useRoslynTokenizer: configuration.UseRoslynTokenizer, csharpParseOptions)); }); }, joinableTaskFactory: null); @@ -78,14 +78,10 @@ public IEnumerable DocumentFilePaths public string IntermediateOutputPath => FilePathNormalizer.GetNormalizedDirectoryName(_project.CompilationOutputInfo.AssemblyPath); - public string? RootNamespace => _project.DefaultNamespace ?? "ASP"; - public string DisplayName => _project.Name; public VersionStamp Version => _project.Version; - public LanguageVersion CSharpLanguageVersion => ((CSharpParseOptions)_project.ParseOptions.AssumeNotNull()).LanguageVersion; - public ValueTask> GetTagHelpersAsync(CancellationToken cancellationToken) { return !_tagHelpers.IsDefault @@ -218,11 +214,18 @@ private async Task CreateRazorConfigurationAsync() var suppressAddComponentParameter = compilation is not null && !compilation.HasAddComponentParameter(); + var csharpParseOptions = _project.ParseOptions as CSharpParseOptions ?? CSharpParseOptions.Default; + var csharpLanguageVersion = csharpParseOptions.LanguageVersion; + var useRoslynTokenizer = csharpParseOptions.UseRoslynTokenizer(); + return new( razorLanguageVersion, configurationName, Extensions: [], UseConsolidatedMvcViews: true, - suppressAddComponentParameter); + suppressAddComponentParameter, + CSharpLanguageVersion: csharpLanguageVersion, + UseRoslynTokenizer: useRoslynTokenizer, + RootNamespace: _project.DefaultNamespace); } } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Guest/ProjectSnapshotSynchronizationService.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Guest/ProjectSnapshotSynchronizationService.cs index 295ec7ec6c0..32b6e96e3de 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Guest/ProjectSnapshotSynchronizationService.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Guest/ProjectSnapshotSynchronizationService.cs @@ -76,7 +76,7 @@ internal async ValueTask UpdateGuestProjectManagerAsync(ProjectChangeEventProxyA { var guestPath = ResolveGuestPath(args.ProjectFilePath); var guestIntermediateOutputPath = ResolveGuestPath(args.IntermediateOutputPath); - var hostProject = new HostProject(guestPath, guestIntermediateOutputPath, args.Newer!.Configuration, args.Newer.RootNamespace); + var hostProject = new HostProject(guestPath, guestIntermediateOutputPath, args.Newer!.Configuration); await _projectManager.UpdateAsync( static (updater, state) => @@ -112,7 +112,7 @@ await _projectManager.UpdateAsync( { var guestPath = ResolveGuestPath(args.Newer.FilePath); var guestIntermediateOutputPath = ResolveGuestPath(args.Newer.IntermediateOutputPath); - var hostProject = new HostProject(guestPath, guestIntermediateOutputPath, args.Newer.Configuration, args.Newer.RootNamespace); + var hostProject = new HostProject(guestPath, guestIntermediateOutputPath, args.Newer.Configuration); await _projectManager.UpdateAsync( static (updater, hostProject) => updater.ProjectConfigurationChanged(hostProject), state: hostProject, @@ -144,7 +144,7 @@ private async Task InitializeGuestProjectManagerAsync(IReadOnlyList { diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Host/ProjectSnapshotManagerProxy.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Host/ProjectSnapshotManagerProxy.cs index b38129fa399..90b1911ccc0 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Host/ProjectSnapshotManagerProxy.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Host/ProjectSnapshotManagerProxy.cs @@ -104,7 +104,7 @@ internal async Task CalculateUpdatedStateAsync var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers); var projectFilePath = _session.ConvertLocalPathToSharedUri(project.FilePath); var intermediateOutputPath = _session.ConvertLocalPathToSharedUri(project.IntermediateOutputPath); - var projectHandleProxy = new ProjectSnapshotHandleProxy(projectFilePath, intermediateOutputPath, project.Configuration, project.RootNamespace, projectWorkspaceState); + var projectHandleProxy = new ProjectSnapshotHandleProxy(projectFilePath, intermediateOutputPath, project.Configuration, projectWorkspaceState); return projectHandleProxy; } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/ProjectSnapshotHandleProxy.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/ProjectSnapshotHandleProxy.cs index 261fc0921c5..6148419e835 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/ProjectSnapshotHandleProxy.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/ProjectSnapshotHandleProxy.cs @@ -15,20 +15,17 @@ public sealed class ProjectSnapshotHandleProxy internal Uri FilePath { get; } internal Uri IntermediateOutputPath { get; } internal RazorConfiguration Configuration { get; } - internal string? RootNamespace { get; } internal ProjectWorkspaceState ProjectWorkspaceState { get; } internal ProjectSnapshotHandleProxy( Uri filePath, Uri intermediateOutputPath, RazorConfiguration configuration, - string? rootNamespace, ProjectWorkspaceState projectWorkspaceState) { FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath)); IntermediateOutputPath = intermediateOutputPath ?? throw new ArgumentNullException(nameof(intermediateOutputPath)); Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - RootNamespace = rootNamespace; ProjectWorkspaceState = projectWorkspaceState; } } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Serialization/ProjectSnapshotHandleProxyJsonConverter.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Serialization/ProjectSnapshotHandleProxyJsonConverter.cs index 3aef4f2a513..303fe347027 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Serialization/ProjectSnapshotHandleProxyJsonConverter.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LiveShare/Serialization/ProjectSnapshotHandleProxyJsonConverter.cs @@ -15,10 +15,9 @@ protected override ProjectSnapshotHandleProxy ReadFromProperties(JsonDataReader var filePath = reader.ReadNonNullUri(nameof(ProjectSnapshotHandleProxy.FilePath)); var intermediateOutputPath = reader.ReadNonNullUri(nameof(ProjectSnapshotHandleProxy.IntermediateOutputPath)); var configuration = reader.ReadNonNullObject(nameof(ProjectSnapshotHandleProxy.Configuration), ObjectReaders.ReadConfigurationFromProperties); - var rootNamespace = reader.ReadStringOrNull(nameof(ProjectSnapshotHandleProxy.RootNamespace)); var projectWorkspaceState = reader.ReadObjectOrNull(nameof(ProjectSnapshotHandleProxy.ProjectWorkspaceState), ObjectReaders.ReadProjectWorkspaceStateFromProperties) ?? ProjectWorkspaceState.Default; - return new(filePath, intermediateOutputPath, configuration, rootNamespace, projectWorkspaceState); + return new(filePath, intermediateOutputPath, configuration, projectWorkspaceState); } protected override void WriteProperties(JsonDataWriter writer, ProjectSnapshotHandleProxy value) @@ -26,7 +25,6 @@ protected override void WriteProperties(JsonDataWriter writer, ProjectSnapshotHa writer.Write(nameof(value.FilePath), value.FilePath); writer.Write(nameof(value.IntermediateOutputPath), value.IntermediateOutputPath); writer.WriteObject(nameof(value.Configuration), value.Configuration, ObjectWriters.WriteProperties); - writer.WriteIfNotNull(nameof(value.RootNamespace), value.RootNamespace); writer.WriteObjectIfNotNull(nameof(value.ProjectWorkspaceState), value.ProjectWorkspaceState, ObjectWriters.WriteProperties); } } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs index 5b499fb9c44..134be6178cd 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultWindowsRazorProjectHost.cs @@ -60,8 +60,6 @@ protected override async Task HandleProjectChangeAsync(string sliceDimensions, I if (TryGetConfiguration(update.Value.CurrentState, _languageServerFeatureOptions.ToLanguageServerFlags(), out var configuration) && TryGetIntermediateOutputPath(update.Value.CurrentState, out var intermediatePath)) { - TryGetRootNamespace(update.Value.CurrentState, out var rootNamespace); - if (TryGetBeforeIntermediateOutputPath(update.Value.ProjectChanges, out var beforeIntermediateOutputPath) && beforeIntermediateOutputPath != intermediatePath) { @@ -95,7 +93,7 @@ await UpdateAsync( ? $"{projectFileName} ({sliceDimensions})" : projectFileName; - var hostProject = new HostProject(CommonServices.UnconfiguredProject.FullPath, intermediatePath, configuration, rootNamespace, displayName); + var hostProject = new HostProject(CommonServices.UnconfiguredProject.FullPath, intermediatePath, configuration, displayName); UpdateProject(updater, hostProject); @@ -162,11 +160,14 @@ internal static bool TryGetConfiguration( return false; } + TryGetRootNamespace(state, out var rootNamespace); + configuration = new( languageVersion, configurationItem.Key, extensions, - LanguageServerFlags: languageServerFlags); + LanguageServerFlags: languageServerFlags, + RootNamespace: rootNamespace); return true; } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackHostProject.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackHostProject.cs index 5e9616948d4..a143b72d7aa 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackHostProject.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackHostProject.cs @@ -12,9 +12,8 @@ public FallbackHostProject( string filePath, string intermediateOutputPath, RazorConfiguration configuration, - string? rootNamespace, string displayName) - : base(filePath, intermediateOutputPath, configuration, rootNamespace, displayName) + : base(filePath, intermediateOutputPath, configuration, displayName) { } } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackProjectManager.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackProjectManager.cs index 09130e8cb44..57d31c67a92 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackProjectManager.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackProjectManager.cs @@ -106,15 +106,17 @@ private void AddFallbackProject(ProjectId projectId, string filePath, Cancellati return; } - var rootNamespace = project.DefaultNamespace; - - var configuration = FallbackRazorConfiguration.Latest with { LanguageServerFlags = _languageServerFeatureOptions.ToLanguageServerFlags() }; + var configuration = FallbackRazorConfiguration.Latest with + { + LanguageServerFlags = _languageServerFeatureOptions.ToLanguageServerFlags(), + RootNamespace = project.DefaultNamespace + }; // 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 // change or simply a timing difference between Roslyn and our CPS components, the HostProject instance associated with // the project will be updated, and it will no longer be a fallback project. - var hostProject = new FallbackHostProject(project.FilePath, intermediateOutputPath, configuration, rootNamespace, project.Name); + var hostProject = new FallbackHostProject(project.FilePath, intermediateOutputPath, configuration, project.Name); EnqueueProjectManagerUpdate( updater => updater.ProjectAdded(hostProject), diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackWindowsRazorProjectHost.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackWindowsRazorProjectHost.cs index 229221b53e4..7f6151e7f85 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackWindowsRazorProjectHost.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackWindowsRazorProjectHost.cs @@ -141,7 +141,7 @@ await UpdateAsync(updater => ? $"{projectFileName} ({sliceDimensions})" : projectFileName; - var hostProject = new HostProject(CommonServices.UnconfiguredProject.FullPath, intermediatePath, configuration, rootNamespace: null, displayName); + var hostProject = new HostProject(CommonServices.UnconfiguredProject.FullPath, intermediatePath, configuration, displayName); UpdateProject(updater, hostProject); diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/WindowsRazorProjectHostBase.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/WindowsRazorProjectHostBase.cs index 9c1f525174d..dd563e07575 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/WindowsRazorProjectHostBase.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/WindowsRazorProjectHostBase.cs @@ -222,7 +222,7 @@ internal Task OnProjectRenamingAsync(string oldProjectFilePath, string newProjec { RemoveProject(updater, projectKey); - var hostProject = new HostProject(newProjectFilePath, current.IntermediateOutputPath, current.Configuration, current.RootNamespace); + var hostProject = new HostProject(newProjectFilePath, current.IntermediateOutputPath, current.Configuration); UpdateProject(updater, hostProject); // This should no-op in the common case, just putting it here for insurance. diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/OutOfProcTagHelperResolver.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/OutOfProcTagHelperResolver.cs index 63078a39543..74587a2e7e6 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/OutOfProcTagHelperResolver.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/OutOfProcTagHelperResolver.cs @@ -77,7 +77,7 @@ protected virtual async ValueTask> ResolveTa lastResultId = -1; } - var projectHandle = new ProjectSnapshotHandle(project.Id, projectSnapshot.Configuration, projectSnapshot.RootNamespace); + var projectHandle = new ProjectSnapshotHandle(project.Id, projectSnapshot.Configuration); var deltaResult = await _remoteServiceInvoker.TryInvokeAsync( project.Solution, diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/RoslynProjectChangeProcessor.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/RoslynProjectChangeProcessor.cs index 4d8f9a62f47..529e722c586 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/RoslynProjectChangeProcessor.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/RoslynProjectChangeProcessor.cs @@ -155,7 +155,7 @@ private async Task UpdateWorkspaceStateAsync(Project? workspaceProject, IProject // We got a possibly changed configuration, but need a host project to update. Fortunately everything will no-op if this // is unchanged - var hostProject = new HostProject(projectSnapshot.FilePath, projectSnapshot.IntermediateOutputPath, configuration, projectSnapshot.RootNamespace, projectSnapshot.DisplayName); + var hostProject = new HostProject(projectSnapshot.FilePath, projectSnapshot.IntermediateOutputPath, configuration, projectSnapshot.DisplayName); await _projectManager .UpdateAsync( diff --git a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/EphemeralProjectSnapshot.cs b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/EphemeralProjectSnapshot.cs index 8257de4f3f9..8a4040b9167 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/EphemeralProjectSnapshot.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/EphemeralProjectSnapshot.cs @@ -43,8 +43,6 @@ public EphemeralProjectSnapshot(IProjectEngineFactoryProvider projectEngineFacto public string IntermediateOutputPath { get; } - public string? RootNamespace { get; } - public string DisplayName { get; } public VersionStamp Version => VersionStamp.Default; diff --git a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/Parsing/VisualStudioRazorParser.cs b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/Parsing/VisualStudioRazorParser.cs index 67d2ab55309..13f7db13dd0 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/Parsing/VisualStudioRazorParser.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LegacyEditor.Razor/Parsing/VisualStudioRazorParser.cs @@ -497,7 +497,7 @@ private void ConfigureProjectEngine(RazorProjectEngineBuilder builder) builder.SetCSharpLanguageVersion(projectSnapshot.Configuration.CSharpLanguageVersion); } - builder.SetRootNamespace(projectSnapshot?.RootNamespace); + builder.SetRootNamespace(projectSnapshot?.Configuration.RootNamespace); builder.Features.Add(new VisualStudioParserOptionsFeature(_documentTracker.EditorSettings)); builder.Features.Add(new VisualStudioTagHelperFeature(_documentTracker.TagHelpers)); builder.Features.Add(new VisualStudioEnableTagHelpersFeature()); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/RazorWorkspaceListenerTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/RazorWorkspaceListenerTest.cs index 8fe48a38dce..09d75e7f7ae 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/RazorWorkspaceListenerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/RazorWorkspaceListenerTest.cs @@ -225,6 +225,7 @@ public async Task TestSerialization() "TestProject", LanguageNames.CSharp); + projectInfo = projectInfo.WithDefaultNamespace("TestNamespace"); projectInfo = projectInfo.WithCompilationOutputInfo(projectInfo.CompilationOutputInfo.WithAssemblyPath(@"C:\test\out\test.dll")); projectInfo = projectInfo.WithFilePath(@"C:\test\test.csproj"); projectInfo = projectInfo.WithAdditionalDocuments([DocumentInfo.Create(DocumentId.CreateNewId(projectInfo.Id), @"Page.razor", filePath: @"C:\test\Page.razor")]); @@ -242,7 +243,7 @@ public async Task TestSerialization() Assert.NotNull(deserializedProjectInfo); Assert.Single(deserializedProjectInfo.Documents); Assert.Equal("TestProject", deserializedProjectInfo.DisplayName); - Assert.Equal("ASP", deserializedProjectInfo.RootNamespace); + Assert.Equal("TestNamespace", deserializedProjectInfo.Configuration.RootNamespace); Assert.Equal(@"C:/test/out/", deserializedProjectInfo.ProjectKey.Id); Assert.Equal(@"C:\test\test.csproj", deserializedProjectInfo.FilePath); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs index 7662dfbf0f4..13171b227e0 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs @@ -21,8 +21,10 @@ public class CodeDocumentReferenceHolderTest(ITestOutputHelper testOutput) : Lan private static readonly HostProject s_hostProject = new( filePath: "C:/path/to/project.csproj", intermediateOutputPath: "C:/path/to/obj", - configuration: RazorConfiguration.Default, - rootNamespace: "TestNamespace"); + configuration: RazorConfiguration.Default with + { + RootNamespace = "TestNamespace" + }); private static readonly HostDocument s_hostDocument = new("C:/path/to/file.razor", "file.razor"); @@ -135,7 +137,7 @@ public async Task ProjectChanged_DereferencesGeneratedCodeDocument() // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectConfigurationChanged(s_hostProject with { Configuration = RazorConfiguration.Default, RootNamespace = "NewRootNamespace" }); + updater.ProjectConfigurationChanged(s_hostProject with { Configuration = RazorConfiguration.Default with { RootNamespace = "NewRootNamespace" } }); }); PerformFullGC(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Definition/DefinitionEndpointDelegationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Definition/DefinitionEndpointDelegationTest.cs index a766d66314e..7fdae7e34c5 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Definition/DefinitionEndpointDelegationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Definition/DefinitionEndpointDelegationTest.cs @@ -233,8 +233,10 @@ await projectManager.UpdateAsync(updater => updater.ProjectAdded(new( filePath: "C:/path/to/project.csproj", intermediateOutputPath: "C:/path/to/obj", - configuration: RazorConfiguration.Default, - rootNamespace: "project")); + configuration: RazorConfiguration.Default with + { + RootNamespace = "project" + })); }); var componentSearchEngine = new RazorComponentSearchEngine(LoggerFactory); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorDiagnosticsPublisherTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorDiagnosticsPublisherTest.cs index 01a8e65ea6f..756b37ff50c 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorDiagnosticsPublisherTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorDiagnosticsPublisherTest.cs @@ -61,7 +61,7 @@ public class RazorDiagnosticsPublisherTest(ITestOutputHelper testOutput) : Langu protected override async Task InitializeAsync() { var testProjectManager = CreateProjectSnapshotManager(); - var hostProject = new HostProject("C:/project/project.csproj", "C:/project/obj", RazorConfiguration.Default, "TestRootNamespace"); + var hostProject = new HostProject("C:/project/project.csproj", "C:/project/obj", RazorConfiguration.Default); var sourceText = SourceText.From(string.Empty); var textAndVersion = TextAndVersion.Create(sourceText, VersionStamp.Default); var openedHostDocument = new HostDocument("C:/project/open_document.cshtml", "C:/project/open_document.cshtml"); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentContextFactoryTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentContextFactoryTest.cs index a202af3d35c..5c9d0961751 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentContextFactoryTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentContextFactoryTest.cs @@ -93,7 +93,7 @@ public async Task TryCreateAsync_WithProjectContext_Resolves() var factory = new DocumentContextFactory(_projectManager, LoggerFactory); - var hostProject = new HostProject(projectFilePath, intermediateOutputPath, RazorConfiguration.Default, rootNamespace: null); + var hostProject = new HostProject(projectFilePath, intermediateOutputPath, RazorConfiguration.Default); var hostDocument = new HostDocument(filePath, "file.cshtml"); await _projectManager.UpdateAsync(updater => diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/GeneratedDocumentPublisherTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/GeneratedDocumentPublisherTest.cs index 33d82d4784b..9eb963fa2a7 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/GeneratedDocumentPublisherTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/GeneratedDocumentPublisherTest.cs @@ -17,8 +17,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; public class GeneratedDocumentPublisherTest : LanguageServerTestBase { - private static readonly HostProject s_hostProject = new("/path/to/project.csproj", "/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); - private static readonly HostProject s_hostProject2 = new("/path/to/project2.csproj", "/path/to/obj2", RazorConfiguration.Default, "TestRootNamespace"); + private static readonly HostProject s_hostProject = new("/path/to/project.csproj", "/path/to/obj", RazorConfiguration.Default); + private static readonly HostProject s_hostProject2 = new("/path/to/project2.csproj", "/path/to/obj2", RazorConfiguration.Default); private static readonly HostDocument s_hostDocument = new("/path/to/file.razor", "file.razor"); private readonly TestClient _serverClient = new(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/GeneratedDocumentSynchronizerTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/GeneratedDocumentSynchronizerTest.cs index cd99181070f..37466a2765e 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/GeneratedDocumentSynchronizerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/GeneratedDocumentSynchronizerTest.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; public class GeneratedDocumentSynchronizerTest : LanguageServerTestBase { - private static readonly HostProject s_hostProject = new("/path/to/project.csproj", "/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + private static readonly HostProject s_hostProject = new("/path/to/project.csproj", "/path/to/obj", RazorConfiguration.Default); private static readonly HostDocument s_hostDocument = new("/path/to/file.razor", "file.razor"); private readonly GeneratedDocumentSynchronizer _synchronizer; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs index f56b61fddd3..6c41efd027f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs @@ -24,8 +24,8 @@ public class OpenDocumentGeneratorTest(ITestOutputHelper testOutput) : LanguageS new HostDocument("c:/Test1/Components/Counter.cshtml", "Components/Counter.cshtml"), ]; - private readonly HostProject _hostProject1 = new("c:/Test1/Test1.csproj", "c:/Test1/obj", RazorConfiguration.Default, "TestRootNamespace"); - private readonly HostProject _hostProject2 = new("c:/Test2/Test2.csproj", "c:/Test2/obj", RazorConfiguration.Default, "TestRootNamespace"); + private readonly HostProject _hostProject1 = new("c:/Test1/Test1.csproj", "c:/Test1/obj", RazorConfiguration.Default); + private readonly HostProject _hostProject2 = new("c:/Test2/Test2.csproj", "c:/Test2/obj", RazorConfiguration.Default); [Fact] public async Task DocumentAdded_ProcessesOpenDocument() diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs index e9402ab71b6..294e01b0299 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs @@ -267,6 +267,5 @@ private static void AssertSnapshotsEqual(IProjectSnapshot first, IProjectSnapsho { Assert.Equal(first.FilePath, second.FilePath); Assert.Equal(first.Configuration, second.Configuration); - Assert.Equal(first.RootNamespace, second.RootNamespace); } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorComponentSearchEngineTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorComponentSearchEngineTest.cs index 9dfc3afdccd..702e29ff25d 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorComponentSearchEngineTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorComponentSearchEngineTest.cs @@ -69,8 +69,10 @@ protected override async Task InitializeAsync() await projectService.GetTestAccessor().AddProjectAsync( s_projectFilePath1, s_intermediateOutputPath1, - RazorConfiguration.Default, - RootNamespace1, + RazorConfiguration.Default with + { + RootNamespace = RootNamespace1, + }, displayName: "", DisposalToken); @@ -83,8 +85,10 @@ await projectService.GetTestAccessor().AddProjectAsync( await projectService.GetTestAccessor().AddProjectAsync( s_projectFilePath2, s_intermediateOutputPath2, - RazorConfiguration.Default, - RootNamespace2, + RazorConfiguration.Default with + { + RootNamespace = RootNamespace2, + }, displayName: "", DisposalToken); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs index 46a9609ffa8..f13745d1f10 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs @@ -58,7 +58,7 @@ protected override Task InitializeAsync() public async Task IProjectInfoListener_UpdatedAsync_UpdatesProjectWorkspaceState() { // Arrange - var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default); await _projectManager.UpdateAsync(updater => { @@ -72,7 +72,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( hostProject.Key, hostProject.FilePath, hostProject.Configuration, - hostProject.RootNamespace, hostProject.DisplayName, projectWorkspaceState, documents: []), @@ -87,7 +86,7 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( public async Task IProjectInfoListener_UpdatedAsync_UpdatingDocument_MapsRelativeFilePathToActualDocument() { // Arrange - var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default); var hostDocument = new HostDocument("C:/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy); await _projectManager.UpdateAsync(updater => @@ -103,7 +102,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( hostProject.Key, hostProject.FilePath, hostProject.Configuration, - hostProject.RootNamespace, hostProject.DisplayName, ProjectWorkspaceState.Default, [newDocument]), @@ -120,7 +118,7 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( public async Task IProjectInfoListener_UpdatedAsync_AddsNewDocuments() { // Arrange - var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default); var hostDocument = new HostDocument("C:/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy); await _projectManager.UpdateAsync(updater => @@ -137,7 +135,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( hostProject.Key, hostProject.FilePath, hostProject.Configuration, - hostProject.RootNamespace, hostProject.DisplayName, ProjectWorkspaceState.Default, [oldDocument, newDocument]), @@ -153,7 +150,7 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( public async Task IProjectInfoListener_UpdatedAsync_MovesDocumentsFromMisc() { // Arrange - var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default); var hostDocument = new HostDocument("C:/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy); var miscProject = _projectManager.GetMiscellaneousProject(); @@ -173,7 +170,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( hostProject.Key, hostProject.FilePath, hostProject.Configuration, - hostProject.RootNamespace, hostProject.DisplayName, ProjectWorkspaceState.Default, [addedDocument]), @@ -197,7 +193,7 @@ public async Task IProjectInfoListener_UpdatedAsync_MovesDocumentsFromMisc_ViaSe const string RootNamespace = "TestRootNamespace"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default with { RootNamespace = RootNamespace }, displayName: null, DisposalToken); await _projectService.AddDocumentToMiscProjectAsync(DocumentFilePath, DisposalToken); @@ -212,7 +208,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( project.Key, project.FilePath, project.Configuration, - project.RootNamespace, project.DisplayName, ProjectWorkspaceState.Default, [addedDocument]), @@ -230,7 +225,7 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( public async Task IProjectInfoListener_UpdatedAsync_MovesExistingDocumentToMisc() { // Arrange - var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default); var hostDocument = new HostDocument("C:/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy); var miscProject = _projectManager.GetMiscellaneousProject(); @@ -252,7 +247,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( hostProject.Key, hostProject.FilePath, hostProject.Configuration, - hostProject.RootNamespace, hostProject.DisplayName, ProjectWorkspaceState.Default, [newDocument]), @@ -270,7 +264,7 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( public async Task IProjectInfoListener_UpdatedAsync_KnownDocuments() { // Arrange - var hostProject = new HostProject("path/to/project.csproj", "path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + var hostProject = new HostProject("path/to/project.csproj", "path/to/obj", RazorConfiguration.Default); var document = new HostDocument("path/to/file.cshtml", "file.cshtml", FileKinds.Legacy); await _projectManager.UpdateAsync(updater => @@ -288,7 +282,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( hostProject.Key, hostProject.FilePath, hostProject.Configuration, - hostProject.RootNamespace, hostProject.DisplayName, ProjectWorkspaceState.Default, [newDocument]), @@ -301,7 +294,7 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( public async Task IProjectInfoListener_UpdatedAsync_UpdatesLegacyDocumentsAsComponents() { // Arrange - var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + var hostProject = new HostProject("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default); var legacyDocument = new HostDocument("C:/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy); await _projectManager.UpdateAsync(updater => @@ -317,7 +310,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( hostProject.Key, hostProject.FilePath, hostProject.Configuration, - hostProject.RootNamespace, hostProject.DisplayName, ProjectWorkspaceState.Default, [newDocument]), @@ -331,7 +323,7 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( } [Fact] - public async Task IProjectInfoListener_UpdatedAsync_SameConfigurationDifferentRootNamespace_UpdatesRootNamespace() + public async Task IProjectInfoListener_UpdatedAsync_DifferentConfiguration_UpdatesRootNamespace() { // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; @@ -339,7 +331,7 @@ public async Task IProjectInfoListener_UpdatedAsync_SameConfigurationDifferentRo const string NewRootNamespace = "NewRootNamespace"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, rootNamespace: null, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); var ownerProject = _projectManager.GetLoadedProject(ownerProjectKey); @@ -349,8 +341,7 @@ public async Task IProjectInfoListener_UpdatedAsync_SameConfigurationDifferentRo await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( ownerProject.Key, ownerProject.FilePath, - ownerProject.Configuration, - NewRootNamespace, + ownerProject.Configuration with { RootNamespace = NewRootNamespace }, ownerProject.DisplayName, ProjectWorkspaceState.Default, documents: []), @@ -358,21 +349,20 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( var notification = Assert.Single(listener); Assert.NotNull(notification.Older); - Assert.Null(notification.Older.RootNamespace); + Assert.Null(notification.Older.Configuration.RootNamespace); Assert.NotNull(notification.Newer); - Assert.Equal(NewRootNamespace, notification.Newer.RootNamespace); + Assert.Equal(NewRootNamespace, notification.Newer.Configuration.RootNamespace); } [Fact] - public async Task IProjectInfoListener_UpdatedAsync_SameConfigurationAndRootNamespaceNoops() + public async Task IProjectInfoListener_UpdatedAsync_SameConfigurationNoops() { // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); var ownerProject = _projectManager.GetLoadedProject(ownerProjectKey); @@ -383,7 +373,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( ownerProject.Key, ownerProject.FilePath, ownerProject.Configuration, - ownerProject.RootNamespace, displayName: "", ProjectWorkspaceState.Default, documents: []), @@ -398,10 +387,9 @@ public async Task IProjectInfoListener_UpdatedAsync_ChangesProjectToUseProvidedC // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); var ownerProject = _projectManager.GetLoadedProject(ownerProjectKey); @@ -412,7 +400,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( ownerProject.Key, ownerProject.FilePath, FallbackRazorConfiguration.MVC_1_1, - "TestRootNamespace", displayName: "", ProjectWorkspaceState.Default, documents: []), @@ -430,11 +417,10 @@ public async Task CloseDocument_ClosesDocumentInOwnerProject() // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); await _projectService.OpenDocumentAsync(DocumentFilePath, s_emptyText, DisposalToken); @@ -461,13 +447,12 @@ public async Task CloseDocument_ClosesDocumentInAllOwnerProjects() const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath1 = "C:/path/to/obj/net6"; const string IntermediateOutputPath2 = "C:/path/to/obj/net7"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey1 = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath1, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath1, RazorConfiguration.Default, displayName: null, DisposalToken); var ownerProjectKey2 = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath2, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath2, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); await _projectService.OpenDocumentAsync(DocumentFilePath, s_emptyText, DisposalToken); @@ -520,11 +505,10 @@ public async Task OpenDocument_OpensAlreadyAddedDocumentInOwnerProject() // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); var ownerProject = _projectManager.GetLoadedProject(ownerProjectKey); @@ -550,13 +534,12 @@ public async Task OpenDocument_OpensAlreadyAddedDocumentInAllOwnerProjects() const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath1 = "C:/path/to/obj/net6"; const string IntermediateOutputPath2 = "C:/path/to/obj/net7"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey1 = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath1, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath1, RazorConfiguration.Default, displayName: null, DisposalToken); var ownerProjectKey2 = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath2, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath2, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); var ownerProject1 = _projectManager.GetLoadedProject(ownerProjectKey1); @@ -607,11 +590,10 @@ public async Task OpenDocument_OpensAndAddsDocumentToMiscellaneousProject() // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); var miscProject = _projectManager.GetMiscellaneousProject(); @@ -651,11 +633,10 @@ public async Task AddDocument_AddsDocumentToOwnerProject() // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); var ownerProject = _projectManager.GetLoadedProject(ownerProjectKey); @@ -697,11 +678,10 @@ public async Task AddDocumentToMiscProjectAsync_IgnoresKnownDocument() // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); // Act @@ -738,11 +718,10 @@ public async Task RemoveDocument_RemovesDocumentFromOwnerProject() // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); var ownerProject = _projectManager.GetLoadedProject(ownerProjectKey); @@ -766,13 +745,12 @@ public async Task RemoveDocument_RemovesDocumentFromAllOwnerProjects() const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath1 = "C:/path/to/obj/net6"; const string IntermediateOutputPath2 = "C:/path/to/obj/net7"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey1 = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath1, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath1, RazorConfiguration.Default, displayName: null, DisposalToken); var ownerProjectKey2 = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath2, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath2, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); var ownerProject1 = _projectManager.GetLoadedProject(ownerProjectKey1); @@ -797,11 +775,10 @@ public async Task RemoveOpenDocument_RemovesDocumentFromOwnerProject_MovesToMisc // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); await _projectService.OpenDocumentAsync(DocumentFilePath, s_emptyText, DisposalToken); @@ -883,11 +860,10 @@ public async Task UpdateDocument_ChangesDocumentInOwnerProject() // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); await _projectService.OpenDocumentAsync(DocumentFilePath, s_emptyText, DisposalToken); @@ -914,13 +890,12 @@ public async Task UpdateDocument_ChangesDocumentInAllOwnerProjects() const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath1 = "C:/path/to/obj/net6"; const string IntermediateOutputPath2 = "C:/path/to/obj/net7"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey1 = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath1, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath1, RazorConfiguration.Default, displayName: null, DisposalToken); var ownerProjectKey2 = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath2, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath2, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); await _projectService.OpenDocumentAsync(DocumentFilePath, s_emptyText, DisposalToken); @@ -973,11 +948,10 @@ public async Task UpdateDocument_DocumentVersionUpdated() // Arrange const string ProjectFilePath = "C:/path/to/project.csproj"; const string IntermediateOutputPath = "C:/path/to/obj"; - const string RootNamespace = "TestRootNamespace"; const string DocumentFilePath = "C:/path/to/document.cshtml"; var ownerProjectKey = await _projectService.GetTestAccessor().AddProjectAsync( - ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken); + ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, displayName: null, DisposalToken); await _projectService.AddDocumentToPotentialProjectsAsync(DocumentFilePath, DisposalToken); var ownerProject = _projectManager.GetLoadedProject(ownerProjectKey); @@ -1003,7 +977,7 @@ public async Task IRazorProjectInfoListener_UpdatedAsync_AddsProjectWithSpecifie const string IntermediateOutputPath = "C:/path/to/obj"; const string RootNamespace = "My.Root.Namespace"; - var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "TestName", Extensions: []); + var configuration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "TestName", RootNamespace: RootNamespace, Extensions: []); var projectKey = new ProjectKey(IntermediateOutputPath); // Act @@ -1011,7 +985,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( projectKey, ProjectFilePath, configuration, - RootNamespace, "ProjectDisplayName", ProjectWorkspaceState.Default, documents: []), @@ -1022,7 +995,6 @@ await _projectInfoListener.UpdatedAsync(new RazorProjectInfo( // Assert Assert.Equal(ProjectFilePath, project.FilePath); Assert.Same(configuration, project.Configuration); - Assert.Equal(RootNamespace, project.RootNamespace); } private static TextLoader CreateTextLoader(SourceText text) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointDelegationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointDelegationTest.cs index 0d587573d67..5e5183713b2 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointDelegationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointDelegationTest.cs @@ -59,8 +59,7 @@ await projectManager.UpdateAsync(updater => updater.ProjectAdded(new( filePath: "C:/path/to/project.csproj", intermediateOutputPath: "C:/path/to/obj", - configuration: RazorConfiguration.Default, - rootNamespace: "project")); + configuration: RazorConfiguration.Default)); }); var searchEngine = new RazorComponentSearchEngine(LoggerFactory); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointTest.cs index 4c78d3dd3db..69ff42d922b 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointTest.cs @@ -655,7 +655,7 @@ public async Task Handle_Rename_SingleServer_DoesNotDelegateForRazor() LoggerFactory)); var projectKey1 = await projectService.GetTestAccessor().AddProjectAsync( - s_projectFilePath1, s_intermediateOutputPath1, RazorConfiguration.Default, RootNamespace1, displayName: null, DisposalToken); + s_projectFilePath1, s_intermediateOutputPath1, RazorConfiguration.Default with { RootNamespace = RootNamespace1 }, displayName: null, DisposalToken); await projectManager.UpdateAsync(updater => { @@ -677,7 +677,7 @@ await projectManager.UpdateAsync(updater => await projectService.UpdateDocumentAsync(s_indexFilePath1, SourceText.From(IndexText1), DisposalToken); var projectKey2 = await projectService.GetTestAccessor().AddProjectAsync( - s_projectFilePath2, s_intermediateOutputPath2, RazorConfiguration.Default, RootNamespace2, displayName: null, DisposalToken); + s_projectFilePath2, s_intermediateOutputPath2, RazorConfiguration.Default with { RootNamespace = RootNamespace2 }, displayName: null, DisposalToken); await projectManager.UpdateAsync(updater => { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorProjectService.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorProjectService.cs index 026a36c8242..36422ffa3db 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorProjectService.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorProjectService.cs @@ -53,7 +53,7 @@ public async Task AddDocumentToPotentialProjectsAsync(string textDocumentPath, C .Select(d => new DocumentSnapshotHandle(d, d, FileKinds.GetFileKindFromFilePath(d))) .ToImmutableArray(); - await ((IRazorProjectInfoListener)this).UpdatedAsync(new RazorProjectInfo(projectSnapshot.Key, projectSnapshot.FilePath, projectSnapshot.Configuration, projectSnapshot.RootNamespace, projectSnapshot.DisplayName, projectSnapshot.ProjectWorkspaceState, + await ((IRazorProjectInfoListener)this).UpdatedAsync(new RazorProjectInfo(projectSnapshot.Key, projectSnapshot.FilePath, projectSnapshot.Configuration, projectSnapshot.DisplayName, projectSnapshot.ProjectWorkspaceState, documents), cancellationToken).ConfigureAwait(false); } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WorkspaceSemanticTokensRefreshTriggerTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WorkspaceSemanticTokensRefreshTriggerTest.cs index da819d2d94b..ebd2d034bd0 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WorkspaceSemanticTokensRefreshTriggerTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WorkspaceSemanticTokensRefreshTriggerTest.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; public class WorkspaceSemanticTokensRefreshTriggerTest : LanguageServerTestBase { - private static readonly HostProject s_hostProject = new("/path/to/project.csproj", "/path/to/obj", RazorConfiguration.Default, "TestRootNamespace"); + private static readonly HostProject s_hostProject = new("/path/to/project.csproj", "/path/to/obj", RazorConfiguration.Default); private static readonly HostDocument s_hostDocument = new("/path/to/file.razor", "file.razor"); private readonly TestProjectSnapshotManager _projectManager; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ProjectEngineFactoryProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ProjectEngineFactoryProviderTest.cs index 6b0c2f43966..b4756626f16 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ProjectEngineFactoryProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/ProjectEngineFactoryProviderTest.cs @@ -33,21 +33,21 @@ public ProjectEngineFactoryProviderTest(ITestOutputHelper testOutput) { var projectFilePath = "/TestPath/SomePath/Test.csproj"; var intermediateOutputPath = "/TestPath/SomePath/obj"; - var hostProject_For_1_0 = new HostProject(projectFilePath, intermediateOutputPath, FallbackRazorConfiguration.MVC_1_0, "Test"); - var hostProject_For_1_1 = new HostProject(projectFilePath, intermediateOutputPath, FallbackRazorConfiguration.MVC_1_1, "Test"); - var hostProject_For_2_0 = new HostProject(projectFilePath, intermediateOutputPath, FallbackRazorConfiguration.MVC_2_0, "Test"); + var hostProject_For_1_0 = new HostProject(projectFilePath, intermediateOutputPath, FallbackRazorConfiguration.MVC_1_0); + var hostProject_For_1_1 = new HostProject(projectFilePath, intermediateOutputPath, FallbackRazorConfiguration.MVC_1_1); + var hostProject_For_2_0 = new HostProject(projectFilePath, intermediateOutputPath, FallbackRazorConfiguration.MVC_2_0); var hostProject_For_2_1 = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_2_1, "MVC-2.1", Extensions: []), "Test"); + new(RazorLanguageVersion.Version_2_1, "MVC-2.1", Extensions: [])); var hostProject_For_3_0 = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_3_0, "MVC-3.0", Extensions: []), "Test"); + new(RazorLanguageVersion.Version_3_0, "MVC-3.0", Extensions: [])); var hostProject_For_UnknownConfiguration = new HostProject( projectFilePath, intermediateOutputPath, - new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: []), rootNamespace: null); + new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: [])); _snapshot_For_1_0 = new ProjectSnapshot(ProjectState.Create(ProjectEngineFactories.DefaultProvider, hostProject_For_1_0, ProjectWorkspaceState.Default)); _snapshot_For_1_1 = new ProjectSnapshot(ProjectState.Create(ProjectEngineFactories.DefaultProvider, hostProject_For_1_1, ProjectWorkspaceState.Default)); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/ProjectSnapshotHandleSerializationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/ProjectSnapshotHandleSerializationTest.cs index 48f3af542e8..decdf213194 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/ProjectSnapshotHandleSerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/ProjectSnapshotHandleSerializationTest.cs @@ -30,8 +30,7 @@ public void ProjectSnapshotHandleJsonConverter_Serialization_CanKindaRoundTrip() projectId, new(RazorLanguageVersion.Version_1_1, "Test", - [new("Test-Extension1"), new("Test-Extension2")]), - "Test"); + [new("Test-Extension1"), new("Test-Extension2")])); // Act var bytes = MessagePackConvert.Serialize(expectedSnapshot, s_options); @@ -48,7 +47,7 @@ public void ProjectSnapshotHandleJsonConverter_Serialization_CanKindaRoundTrip() e => Assert.Equal("Test-Extension1", e.ExtensionName), e => Assert.Equal("Test-Extension2", e.ExtensionName)); Assert.Equal(expectedSnapshot.Configuration.LanguageVersion, actualSnapshot.Configuration.LanguageVersion); - Assert.Equal(expectedSnapshot.RootNamespace, actualSnapshot.RootNamespace); + Assert.Equal(expectedSnapshot.Configuration.RootNamespace, actualSnapshot.Configuration.RootNamespace); } [Fact] @@ -56,7 +55,7 @@ public void ProjectSnapshotHandleJsonConverter_SerializationWithNulls_CanKindaRo { // Arrange var projectId = ProjectId.CreateNewId(); - var expectedSnapshot = new ProjectSnapshotHandle(projectId, RazorConfiguration.Default, null); + var expectedSnapshot = new ProjectSnapshotHandle(projectId, RazorConfiguration.Default); // Act var bytes = MessagePackConvert.Serialize(expectedSnapshot, s_options); @@ -66,6 +65,5 @@ public void ProjectSnapshotHandleJsonConverter_SerializationWithNulls_CanKindaRo Assert.NotNull(actualSnapshot); Assert.Equal(expectedSnapshot.ProjectId, actualSnapshot.ProjectId); Assert.NotNull(actualSnapshot.Configuration); - Assert.Null(actualSnapshot.RootNamespace); } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/SerializerValidationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/SerializerValidationTest.cs index 97a8f86c57a..99ac8df08bd 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/SerializerValidationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Serialization/SerializerValidationTest.cs @@ -90,7 +90,6 @@ public void VerifyJson_RazorProjectInfo(string resourceName) Assert.Equal(originalProjectInfo.ProjectKey, actualProjectInfo.ProjectKey); Assert.Equal(originalProjectInfo.FilePath, actualProjectInfo.FilePath); Assert.Equal(originalProjectInfo.Configuration, actualProjectInfo.Configuration); - Assert.Equal(originalProjectInfo.RootNamespace, actualProjectInfo.RootNamespace); Assert.Equal(originalProjectInfo.ProjectWorkspaceState, actualProjectInfo.ProjectWorkspaceState); Assert.Equal(originalProjectInfo.Documents, actualProjectInfo.Documents); } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs index 50ca8dd6db9..e07f0c1eb4a 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/SerializationTest.cs @@ -36,7 +36,6 @@ public void RazorProjectInfo_InvalidVersionThrows() new ProjectKey("/path/to/obj/"), "/path/to/project.csproj", _configuration, - rootNamespace: "TestProject", displayName: "project", _projectWorkspaceState, documents: []); @@ -69,7 +68,6 @@ public void RazorProjectInfo_MissingVersionThrows() new ProjectKey("/path/to/obj/"), "/path/to/project.csproj", _configuration, - rootNamespace: "TestProject", displayName: "project", _projectWorkspaceState, documents: []); @@ -103,8 +101,10 @@ public void RazorProjectInfo_CanRoundTrip() var projectInfo = new RazorProjectInfo( new ProjectKey("/path/to/obj/"), "/path/to/project.csproj", - _configuration, - rootNamespace: "TestProject", + _configuration with + { + RootNamespace = "TestProject" + }, displayName: "project", _projectWorkspaceState, documents: [legacyDocument, componentDocument]); @@ -119,7 +119,6 @@ public void RazorProjectInfo_CanRoundTrip() // Assert Assert.Equal(projectInfo.FilePath, deserializedProjectInfo.FilePath); Assert.Equal(projectInfo.Configuration, deserializedProjectInfo.Configuration); - Assert.Equal(projectInfo.RootNamespace, deserializedProjectInfo.RootNamespace); Assert.Equal(projectInfo.ProjectWorkspaceState, deserializedProjectInfo.ProjectWorkspaceState); Assert.Collection(projectInfo.Documents.OrderBy(doc => doc.FilePath), document => diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/StreamExtensionTests.NetCore.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/StreamExtensionTests.NetCore.cs index 965779a4bd8..b14902b7800 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/StreamExtensionTests.NetCore.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/StreamExtensionTests.NetCore.cs @@ -71,7 +71,8 @@ public async Task SerializeProjectInfo() var configuration = new RazorConfiguration( RazorLanguageVersion.Latest, "TestConfiguration", - ImmutableArray.Empty); + ImmutableArray.Empty, + RootNamespace: "TestNamespace"); var tagHelper = TagHelperDescriptorBuilder.Create("TypeName", "AssemblyName") .TagMatchingRuleDescriptor(rule => rule.RequireTagName("tag-name")) @@ -83,7 +84,6 @@ public async Task SerializeProjectInfo() new ProjectKey("TestProject"), @"C:\test\test.csproj", configuration, - "TestNamespace", "Test", projectWorkspaceState, [new DocumentSnapshotHandle(@"C:\test\document.razor", @"document.razor", FileKinds.Component)]); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestHostProject.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestHostProject.cs index 0f3ac548c4e..92523364b20 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestHostProject.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestHostProject.cs @@ -13,5 +13,5 @@ public static HostProject Create(string filePath) => Create(filePath, intermediateOutputPath: Path.Combine(Path.GetDirectoryName(filePath) ?? @"\\path", "obj")); public static HostProject Create(string filePath, string intermediateOutputPath) - => new(filePath, intermediateOutputPath, RazorConfiguration.Default, rootNamespace: "TestRootNamespace"); + => new(filePath, intermediateOutputPath, RazorConfiguration.Default with { RootNamespace = "TestRootNamespace" }); } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestProjectKey.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestProjectKey.cs index df026533088..08c2fb8d58b 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestProjectKey.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestProjectKey.cs @@ -15,7 +15,7 @@ public static class TestProjectKey internal static ProjectKey Create(string projectFilePath) { // Parameters here are largely useless, we just want a key - var hostProject = new HostProject(projectFilePath, projectFilePath, FallbackRazorConfiguration.Latest, rootNamespace: null); + var hostProject = new HostProject(projectFilePath, projectFilePath, FallbackRazorConfiguration.Latest); return hostProject.Key; } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestProjectSnapshot.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestProjectSnapshot.cs index c094f233b34..32ede48d488 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestProjectSnapshot.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ProjectSystem/TestProjectSnapshot.cs @@ -42,7 +42,6 @@ public static TestProjectSnapshot Create(string filePath, ProjectWorkspaceState? public IEnumerable DocumentFilePaths => RealSnapshot.DocumentFilePaths; public string FilePath => RealSnapshot.FilePath; public string IntermediateOutputPath => RealSnapshot.IntermediateOutputPath; - public string? RootNamespace => RealSnapshot.RootNamespace; public string DisplayName => RealSnapshot.DisplayName; public ProjectWorkspaceState ProjectWorkspaceState => RealSnapshot.ProjectWorkspaceState; public VersionStamp Version => RealSnapshot.Version; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs index cdbc6c655d3..6d0cdd09c84 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs @@ -112,8 +112,6 @@ public static IProjectSnapshot CreateProjectSnapshot(HostProject hostProject, Pr .Returns(hostProject.IntermediateOutputPath); mock.SetupGet(x => x.Configuration) .Returns(hostProject.Configuration); - mock.SetupGet(x => x.RootNamespace) - .Returns(hostProject.RootNamespace); mock.SetupGet(x => x.DisplayName) .Returns(hostProject.DisplayName); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs index 815e9588eea..231134fa17f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs @@ -22,7 +22,7 @@ static TestProjectData() SomeProjectPath = Path.Combine(baseDirectory, "SomeProject"); var someProjectObjPath = Path.Combine(SomeProjectPath, "obj"); - SomeProject = new HostProject(Path.Combine(SomeProjectPath, "SomeProject.csproj"), someProjectObjPath, RazorConfiguration.Default, "SomeProject"); + SomeProject = new HostProject(Path.Combine(SomeProjectPath, "SomeProject.csproj"), someProjectObjPath, RazorConfiguration.Default with { RootNamespace = "SomeProject" }); SomeProjectFile1 = new HostDocument(Path.Combine(SomeProjectPath, "File1.cshtml"), "File1.cshtml", FileKinds.Legacy); SomeProjectFile2 = new HostDocument(Path.Combine(SomeProjectPath, "File2.cshtml"), "File2.cshtml", FileKinds.Legacy); SomeProjectImportFile = new HostDocument(Path.Combine(SomeProjectPath, "_ViewImports.cshtml"), "_ViewImports.cshtml", FileKinds.Legacy); @@ -39,7 +39,7 @@ static TestProjectData() var anotherProjectPath = Path.Combine(baseDirectory, "AnotherProject"); var anotherProjectObjPath = Path.Combine(anotherProjectPath, "obj"); - AnotherProject = new HostProject(Path.Combine(anotherProjectPath, "AnotherProject.csproj"), anotherProjectObjPath, RazorConfiguration.Default, "AnotherProject"); + AnotherProject = new HostProject(Path.Combine(anotherProjectPath, "AnotherProject.csproj"), anotherProjectObjPath, RazorConfiguration.Default with { RootNamespace = "AnotherProject" }); AnotherProjectFile1 = new HostDocument(Path.Combine(anotherProjectPath, "File1.cshtml"), "File1.cshtml", FileKinds.Legacy); AnotherProjectFile2 = new HostDocument(Path.Combine(anotherProjectPath, "File2.cshtml"), "File2.cshtml", FileKinds.Legacy); AnotherProjectImportFile = new HostDocument(Path.Combine(anotherProjectPath, "_ViewImports.cshtml"), "_ViewImports.cshtml", FileKinds.Legacy); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateTest.cs index 334a5c016c5..8ad9cfc5fec 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateTest.cs @@ -572,7 +572,7 @@ public void ProjectState_WithHostProject_RootNamespaceChange_UpdatesConfiguratio var original = ProjectState.Create(ProjectEngineFactoryProvider, _hostProject, _projectWorkspaceState) .WithAddedHostDocument(_documents[2], DocumentState.EmptyLoader) .WithAddedHostDocument(_documents[1], DocumentState.EmptyLoader); - var hostProjectWithRootNamespaceChange = original.HostProject with { RootNamespace = "ChangedRootNamespace" }; + var hostProjectWithRootNamespaceChange = original.HostProject with { Configuration = original.HostProject.Configuration with { RootNamespace = "ChangedRootNamespace" } }; // Force init _ = original.TagHelpers; diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Tooltip/ProjectAvailabilityTests.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Tooltip/ProjectAvailabilityTests.cs index d19a69bedee..a86e638d89b 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Tooltip/ProjectAvailabilityTests.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Tooltip/ProjectAvailabilityTests.cs @@ -43,7 +43,6 @@ public async Task GetProjectAvailabilityText_OneProject_ReturnsNull() "C:/path/to/project.csproj", "C:/path/to/obj/1", RazorConfiguration.Default, - rootNamespace: null, displayName: "project"); var hostDocument = new HostDocument( @@ -81,14 +80,12 @@ public async Task GetProjectAvailabilityText_AvailableInAllProjects_ReturnsNull( "C:/path/to/project.csproj", "C:/path/to/obj/1", RazorConfiguration.Default, - rootNamespace: null, displayName: "project1"); var hostProject2 = new HostProject( "C:/path/to/project.csproj", "C:/path/to/obj/2", RazorConfiguration.Default, - rootNamespace: null, displayName: "project2"); var hostDocument = new HostDocument( @@ -130,14 +127,12 @@ public async Task GetProjectAvailabilityText_NotAvailableInAllProjects_ReturnsTe "C:/path/to/project.csproj", "C:/path/to/obj/1", RazorConfiguration.Default, - rootNamespace: null, displayName: "project1"); var hostProject2 = new HostProject( "C:/path/to/project.csproj", "C:/path/to/obj/2", RazorConfiguration.Default, - rootNamespace: null, displayName: "project2"); var hostDocument = new HostDocument( @@ -175,14 +170,12 @@ public async Task GetProjectAvailabilityText_NotAvailableInAnyProject_ReturnsTex "C:/path/to/project.csproj", "C:/path/to/obj/1", RazorConfiguration.Default, - rootNamespace: null, displayName: "project1"); var hostProject2 = new HostProject( "C:/path/to/project.csproj", "C:/path/to/obj/2", RazorConfiguration.Default, - rootNamespace: null, displayName: "project2"); var hostDocument = new HostDocument( diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostEndpointTestBase.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostEndpointTestBase.cs index fac6c663afa..742467e177b 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostEndpointTestBase.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostEndpointTestBase.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Basic.Reference.Assemblies; using Microsoft.AspNetCore.Razor; @@ -162,7 +161,7 @@ private static TextDocument CreateProjectAndRazorDocument(CodeAnalysis.Workspace assemblyName: projectName, LanguageNames.CSharp, documentFilePath) - .WithDefaultNamespace(TestProjectData.SomeProject.RootNamespace) + .WithDefaultNamespace(TestProjectData.SomeProject.Configuration.RootNamespace) .WithMetadataReferences(AspNet80.ReferenceInfos.All.Select(r => r.Reference)); var solution = workspace.CurrentSolution.AddProject(projectInfo); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Documents/EditorDocumentManagerListenerTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Documents/EditorDocumentManagerListenerTest.cs index 03b9648cf21..6bf9c8a6885 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Documents/EditorDocumentManagerListenerTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Documents/EditorDocumentManagerListenerTest.cs @@ -25,8 +25,7 @@ public class EditorDocumentManagerListenerTest(ITestOutputHelper testOutput) : V private static readonly HostProject s_hostProject = new( filePath: "/path/to/project.csproj", intermediateOutputPath: "/path/to/obj", - RazorConfiguration.Default, - rootNamespace: null); + RazorConfiguration.Default); private static readonly HostDocument s_hostDocument = new( filePath: "/path/to/file1.razor", diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/ProjectSystem/RazorProjectInfoDriverTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/ProjectSystem/RazorProjectInfoDriverTest.cs index 083e53b2aff..25f4588e242 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/ProjectSystem/RazorProjectInfoDriverTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/ProjectSystem/RazorProjectInfoDriverTest.cs @@ -21,16 +21,20 @@ public class RazorProjectInfoDriverTest(ITestOutputHelper testOutput) : Language private static readonly HostProject s_hostProject1 = new( filePath: "C:/path/to/project1/project1.csproj", intermediateOutputPath: "C:/path/to/project1/obj", - configuration: RazorConfiguration.Default, - rootNamespace: "TestNamespace"); + configuration: RazorConfiguration.Default with + { + RootNamespace = "TestNamespace" + }); private static readonly HostDocument s_hostDocument1 = new("C:/path/to/project1/file.razor", "file.razor"); private static readonly HostProject s_hostProject2 = new( filePath: "C:/path/to/project2/project2.csproj", intermediateOutputPath: "C:/path/to/project2/obj", - configuration: RazorConfiguration.Default, - rootNamespace: "TestNamespace"); + configuration: RazorConfiguration.Default with + { + RootNamespace = "TestNamespace" + }); private static readonly HostDocument s_hostDocument2 = new("C:/path/to/project2/file.razor", "file.razor"); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs index 72570a90160..0a63683405b 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs @@ -92,7 +92,7 @@ private Document InitializeDocument(SourceText sourceText) { var baseDirectory = PlatformInformation.IsWindows ? @"c:\users\example\src" : "/home/example"; var hostProject = new HostProject( - Path.Combine(baseDirectory, "SomeProject", "SomeProject.csproj"), Path.Combine(baseDirectory, "SomeProject", "obj"), RazorConfiguration.Default, "SomeProject"); + Path.Combine(baseDirectory, "SomeProject", "SomeProject.csproj"), Path.Combine(baseDirectory, "SomeProject", "obj"), RazorConfiguration.Default); var hostDocument = new HostDocument( Path.Combine(baseDirectory, "SomeProject", "File1.cshtml"), "File1.cshtml", FileKinds.Legacy); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs index 497d4c58529..85353065960 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Guest/ProjectSnapshotSynchronizationServiceTest.cs @@ -42,7 +42,6 @@ public async Task InitializeAsync_RetrievesHostProjectManagerStateAndInitializes new Uri("vsls:/path/project.csproj"), new Uri("vsls:/path/obj"), RazorConfiguration.Default, - "project", _projectWorkspaceStateWithTagHelpers); var state = new ProjectSnapshotManagerProxyState([projectHandle]); var hostProjectManagerProxyMock = new StrictMock(); @@ -82,7 +81,6 @@ public async Task UpdateGuestProjectManager_ProjectAdded() new Uri("vsls:/path/project.csproj"), new Uri("vsls:/path/obj"), RazorConfiguration.Default, - "project", _projectWorkspaceStateWithTagHelpers); var synchronizationService = new ProjectSnapshotSynchronizationService( _sessionContext, @@ -117,7 +115,6 @@ public async Task UpdateGuestProjectManager_ProjectRemoved() new Uri("vsls:/path/project.csproj"), new Uri("vsls:/path/obj"), RazorConfiguration.Default, - "project", ProjectWorkspaceState.Default); var synchronizationService = new ProjectSnapshotSynchronizationService( _sessionContext, @@ -125,7 +122,7 @@ public async Task UpdateGuestProjectManager_ProjectRemoved() _projectManager, LoggerFactory, JoinableTaskFactory); - var hostProject = new HostProject("/guest/path/project.csproj", "/guest/path/obj", RazorConfiguration.Default, "project"); + var hostProject = new HostProject("/guest/path/project.csproj", "/guest/path/obj", RazorConfiguration.Default); await _projectManager.UpdateAsync(updater => { @@ -150,14 +147,12 @@ public async Task UpdateGuestProjectManager_ProjectChanged_ConfigurationChange() new Uri("vsls:/path/project.csproj"), new Uri("vsls:/path/obj"), RazorConfiguration.Default, - "project", ProjectWorkspaceState.Default); var newConfiguration = new RazorConfiguration(RazorLanguageVersion.Version_1_0, "Custom-1.0", Extensions: []); var newHandle = new ProjectSnapshotHandleProxy( oldHandle.FilePath, oldHandle.IntermediateOutputPath, newConfiguration, - oldHandle.RootNamespace, oldHandle.ProjectWorkspaceState); var synchronizationService = new ProjectSnapshotSynchronizationService( _sessionContext, @@ -165,7 +160,7 @@ public async Task UpdateGuestProjectManager_ProjectChanged_ConfigurationChange() _projectManager, LoggerFactory, JoinableTaskFactory); - var hostProject = new HostProject("/guest/path/project.csproj", "/guest/path/obj", RazorConfiguration.Default, "project"); + var hostProject = new HostProject("/guest/path/project.csproj", "/guest/path/obj", RazorConfiguration.Default); await _projectManager.UpdateAsync(updater => { @@ -194,14 +189,12 @@ public async Task UpdateGuestProjectManager_ProjectChanged_ProjectWorkspaceState new Uri("vsls:/path/project.csproj"), new Uri("vsls:/path/obj"), RazorConfiguration.Default, - "project", ProjectWorkspaceState.Default); var newProjectWorkspaceState = _projectWorkspaceStateWithTagHelpers; var newHandle = new ProjectSnapshotHandleProxy( oldHandle.FilePath, oldHandle.IntermediateOutputPath, oldHandle.Configuration, - oldHandle.RootNamespace, newProjectWorkspaceState); var synchronizationService = new ProjectSnapshotSynchronizationService( _sessionContext, @@ -209,7 +202,7 @@ public async Task UpdateGuestProjectManager_ProjectChanged_ProjectWorkspaceState _projectManager, LoggerFactory, JoinableTaskFactory); - var hostProject = new HostProject("/guest/path/project.csproj", "/guest/path/obj", RazorConfiguration.Default, "project"); + var hostProject = new HostProject("/guest/path/project.csproj", "/guest/path/obj", RazorConfiguration.Default); await _projectManager.UpdateAsync(updater => { diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Host/ProjectSnapshotManagerProxyTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Host/ProjectSnapshotManagerProxyTest.cs index 12e9c3e8299..d6686dcbaf5 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Host/ProjectSnapshotManagerProxyTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/Host/ProjectSnapshotManagerProxyTest.cs @@ -26,8 +26,8 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis private const string LspProjectFilePath1 = $"vsls:/path/to/first/{ProjectName1}.csproj"; private const string LspProjectFilePath2 = $"vsls:/path/to/second/{ProjectName2}.csproj"; - private readonly HostProject _hostProject1 = new(ProjectFilePath1, IntermediateOutputPath1, RazorConfiguration.Default, ProjectName1); - private readonly HostProject _hostProject2 = new(ProjectFilePath2, IntermediateOutputPath2, RazorConfiguration.Default, ProjectName2); + private readonly HostProject _hostProject1 = new(ProjectFilePath1, IntermediateOutputPath1, RazorConfiguration.Default); + private readonly HostProject _hostProject2 = new(ProjectFilePath2, IntermediateOutputPath2, RazorConfiguration.Default); private readonly ProjectWorkspaceState _projectWorkspaceState1 = ProjectWorkspaceState.Create( [TagHelperDescriptorBuilder.Create("test1", "TestAssembly1").Build()]); @@ -106,7 +106,6 @@ await projectManager.UpdateAsync(updater => project.FilePath, project.IntermediateOutputPath, FallbackRazorConfiguration.MVC_1_0, - project.RootNamespace, project.DisplayName)); }); @@ -147,7 +146,6 @@ await projectManager.UpdateAsync(updater => project.FilePath, project.IntermediateOutputPath, FallbackRazorConfiguration.MVC_1_0, - project.RootNamespace, project.DisplayName)); }); @@ -182,7 +180,6 @@ await projectManager.UpdateAsync(updater => Assert.Equal(_hostProject1.FilePath, project.FilePath); Assert.Equal(_hostProject1.IntermediateOutputPath, project.IntermediateOutputPath); Assert.Equal(_hostProject1.Configuration, project.Configuration); - Assert.Equal(_hostProject1.RootNamespace, project.RootNamespace); Assert.Equal(_hostProject1.DisplayName, project.DisplayName); Assert.Equal(_projectWorkspaceState1, project.ProjectWorkspaceState); } diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/SerializationTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/SerializationTest.cs index 79d2d2ca930..a01e070b478 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/SerializationTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LiveShare/SerializationTest.cs @@ -25,8 +25,7 @@ public void ProjectSnapshotHandleProxy_RoundTripsProperly() var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers); var expectedConfiguration = RazorConfiguration.Default; - var expectedRootNamespace = "project"; - var handle = new ProjectSnapshotHandleProxy(new Uri("vsls://some/path/project.csproj"), new Uri("vsls://some/path/obj"), RazorConfiguration.Default, expectedRootNamespace, projectWorkspaceState); + var handle = new ProjectSnapshotHandleProxy(new Uri("vsls://some/path/project.csproj"), new Uri("vsls://some/path/obj"), RazorConfiguration.Default, projectWorkspaceState); var json = JsonConvert.SerializeObject(handle, ProjectSnapshotHandleProxyJsonConverter.Instance); Assert.NotNull(json); @@ -41,6 +40,34 @@ public void ProjectSnapshotHandleProxy_RoundTripsProperly() Assert.Equal(expectedConfiguration.ConfigurationName, deserializedHandle.Configuration.ConfigurationName); Assert.Equal(expectedConfiguration.Extensions.Length, deserializedHandle.Configuration.Extensions.Length); Assert.Equal(expectedConfiguration.LanguageVersion, deserializedHandle.Configuration.LanguageVersion); - Assert.Equal(expectedRootNamespace, deserializedHandle.RootNamespace); + Assert.Equal(expectedConfiguration.RootNamespace, deserializedHandle.Configuration.RootNamespace); + } + + [Fact] + public void ProjectSnapshotHandleProxy_WithNamespace_RoundTripsProperly() + { + // Arrange + var tagHelpers = ImmutableArray.Create( + TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly").Build(), + TagHelperDescriptorBuilder.Create("TestTagHelper2", "TestAssembly2").Build()); + + var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers); + var expectedConfiguration = RazorConfiguration.Default with { RootNamespace = "project" }; + var handle = new ProjectSnapshotHandleProxy(new Uri("vsls://some/path/project.csproj"), new Uri("vsls://some/path/obj"), expectedConfiguration, projectWorkspaceState); + + var json = JsonConvert.SerializeObject(handle, ProjectSnapshotHandleProxyJsonConverter.Instance); + Assert.NotNull(json); + + // Act + var deserializedHandle = JsonConvert.DeserializeObject(json, ProjectSnapshotHandleProxyJsonConverter.Instance); + Assert.NotNull(deserializedHandle); + + // Assert + Assert.Equal("vsls://some/path/project.csproj", deserializedHandle.FilePath.ToString()); + Assert.Equal(projectWorkspaceState, deserializedHandle.ProjectWorkspaceState); + Assert.Equal(expectedConfiguration.ConfigurationName, deserializedHandle.Configuration.ConfigurationName); + Assert.Equal(expectedConfiguration.Extensions.Length, deserializedHandle.Configuration.Extensions.Length); + Assert.Equal(expectedConfiguration.LanguageVersion, deserializedHandle.Configuration.LanguageVersion); + Assert.Equal(expectedConfiguration.RootNamespace, deserializedHandle.Configuration.RootNamespace); } } diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/FallbackProjectManagerTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/FallbackProjectManagerTest.cs index 43c28f4e8d0..0ad081613f8 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/FallbackProjectManagerTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/FallbackProjectManagerTest.cs @@ -50,8 +50,10 @@ public async Task DynamicFileAdded_KnownProject_DoesNothing() { var hostProject = SomeProject with { - Configuration = RazorConfiguration.Default, - RootNamespace = "RootNamespace", + Configuration = RazorConfiguration.Default with + { + RootNamespace = "RootNamespace", + }, DisplayName = "DisplayName" }; @@ -102,7 +104,7 @@ public async Task DynamicFileAdded_UnknownProject_Adds() var project = Assert.Single(_projectManager.GetProjects()); Assert.Equal("DisplayName", project.DisplayName); - Assert.Equal("RootNamespace", project.RootNamespace); + Assert.Equal("RootNamespace", project.Configuration.RootNamespace); Assert.IsType(((ProjectSnapshot)project).HostProject); @@ -136,8 +138,10 @@ public async Task DynamicFileAdded_UnknownToKnownProject_NotFallbackHostProject( var hostProject = SomeProject with { - Configuration = RazorConfiguration.Default, - RootNamespace = "RootNamespace", + Configuration = RazorConfiguration.Default with + { + RootNamespace = "RootNamespace" + }, DisplayName = "DisplayName" }; diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/ProjectSnapshotManagerTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/ProjectSnapshotManagerTest.cs index 6f127b659dc..ebc3b0eb8af 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/ProjectSnapshotManagerTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/ProjectSnapshotManagerTest.cs @@ -76,7 +76,7 @@ public async Task Initialize_DoneInCorrectOrderBasedOnInitializePriorityPriority await projectManager.UpdateAsync(updater => { updater.ProjectAdded( - new("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default, rootNamespace: null)); + new("C:/path/to/project.csproj", "C:/path/to/obj", RazorConfiguration.Default)); }); // Assert diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/RazorDynamicFileInfoProviderTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/RazorDynamicFileInfoProviderTest.cs index d749db5e6ae..e4704645a4a 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/RazorDynamicFileInfoProviderTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/RazorDynamicFileInfoProviderTest.cs @@ -45,7 +45,7 @@ protected override async Task InitializeAsync() _projectManager = CreateProjectSnapshotManager(); - var hostProject = new HostProject(@"C:\project.csproj", @"C:\obj", RazorConfiguration.Default, rootNamespace: "TestNamespace"); + var hostProject = new HostProject(@"C:\project.csproj", @"C:\obj", RazorConfiguration.Default); var hostDocument1 = new HostDocument(@"C:\document1.razor", "document1.razor", FileKinds.Component); var hostDocument2 = new HostDocument(@"C:\document2.razor", "document2.razor", FileKinds.Component); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/RoslynProjectChangeDetectorTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/RoslynProjectChangeDetectorTest.cs index 9c7421c2d62..c54a802b23b 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/RoslynProjectChangeDetectorTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/RoslynProjectChangeDetectorTest.cs @@ -113,9 +113,9 @@ public RoslynProjectChangeDetectorTest(ITestOutputHelper testOutput) _projectNumberTwo = _solutionWithTwoProjects.GetProject(projectId2).AssumeNotNull(); _projectNumberThree = _solutionWithOneProject.GetProject(projectId3).AssumeNotNull(); - _hostProjectOne = new HostProject("One.csproj", "obj1", FallbackRazorConfiguration.MVC_1_1, "One"); - _hostProjectTwo = new HostProject("Two.csproj", "obj2", FallbackRazorConfiguration.MVC_1_1, "Two"); - _hostProjectThree = new HostProject("Three.csproj", "obj3", FallbackRazorConfiguration.MVC_1_1, "Three"); + _hostProjectOne = new HostProject("One.csproj", "obj1", FallbackRazorConfiguration.MVC_1_1); + _hostProjectTwo = new HostProject("Two.csproj", "obj2", FallbackRazorConfiguration.MVC_1_1); + _hostProjectThree = new HostProject("Three.csproj", "obj3", FallbackRazorConfiguration.MVC_1_1); } [UIFact] diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs index 929f4541dd1..79822632677 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Remote/OutOfProcTagHelperResolverTest.cs @@ -29,13 +29,11 @@ public partial class OutOfProcTagHelperResolverTest : VisualStudioTestBase private static readonly HostProject s_hostProject_For_2_0 = new( filePath: "Test.csproj", intermediateOutputPath: "/obj", - configuration: FallbackRazorConfiguration.MVC_2_0, - rootNamespace: null); + configuration: FallbackRazorConfiguration.MVC_2_0); private static readonly HostProject s_hostProject_For_NonSerializableConfiguration = new( filePath: "Test.csproj", intermediateOutputPath: "/obj", - configuration: new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: []), - rootNamespace: null); + configuration: new(RazorLanguageVersion.Version_2_1, "Random-0.1", Extensions: [])); private readonly Project _workspaceProject; private readonly TestProjectSnapshotManager _projectManager; diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/VsSolutionUpdatesProjectSnapshotChangeTriggerTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/VsSolutionUpdatesProjectSnapshotChangeTriggerTest.cs index d8a42d8829c..1270cf67b0e 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/VsSolutionUpdatesProjectSnapshotChangeTriggerTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/VsSolutionUpdatesProjectSnapshotChangeTriggerTest.cs @@ -259,7 +259,7 @@ public async Task OnProjectBuiltAsync_WithoutWorkspaceProject_DoesNotEnqueueUpda await projectManager.UpdateAsync(updater => { updater.ProjectAdded( - new HostProject("/Some/Unknown/Path.csproj", "/Some/Unknown/obj", RazorConfiguration.Default, "Path")); + new HostProject("/Some/Unknown/Path.csproj", "/Some/Unknown/obj", RazorConfiguration.Default)); }); var roslynProjectChangeProcessor = new TestRoslynProjectChangeProcessor(); diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs index ed7f469a31b..e3d9de2d6e7 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders.cs @@ -46,6 +46,7 @@ public static RazorConfiguration ReadConfigurationFromProperties(JsonDataReader var useConsolidatedMvcViews = reader.ReadBooleanOrTrue(nameof(RazorConfiguration.UseConsolidatedMvcViews)); var useRoslynTokenizer = reader.ReadBooleanOrFalse(nameof(RazorConfiguration.UseRoslynTokenizer)); var csharpLanguageVersion = (LanguageVersion)reader.ReadInt32OrZero(nameof(RazorConfiguration.CSharpLanguageVersion)); + var rootNamespace = reader.ReadStringOrNull(nameof(RazorConfiguration.RootNamespace)); var extensions = reader.ReadImmutableArrayOrEmpty(nameof(RazorConfiguration.Extensions), static r => { @@ -57,7 +58,7 @@ public static RazorConfiguration ReadConfigurationFromProperties(JsonDataReader ? version : RazorLanguageVersion.Version_2_1; - return new(languageVersion, configurationName, extensions, SuppressAddComponentParameter: suppressAddComponentParameter, UseRoslynTokenizer: useRoslynTokenizer); + return new(languageVersion, configurationName, extensions, SuppressAddComponentParameter: suppressAddComponentParameter, UseRoslynTokenizer: useRoslynTokenizer, RootNamespace: rootNamespace); } public static RazorDiagnostic ReadDiagnostic(JsonDataReader reader) @@ -85,11 +86,10 @@ public static ProjectSnapshotHandle ReadProjectSnapshotHandleFromProperties(Json { var projectIdString = reader.ReadNonNullString(nameof(ProjectSnapshotHandle.ProjectId)); var configuration = reader.ReadObjectOrNull(nameof(ProjectSnapshotHandle.Configuration), ReadConfigurationFromProperties) ?? RazorConfiguration.Default; - var rootNamespace = reader.ReadStringOrNull(nameof(ProjectSnapshotHandle.RootNamespace)); var projectId = ProjectId.CreateFromSerialized(Guid.Parse(projectIdString)); - return new(projectId, configuration, rootNamespace); + return new(projectId, configuration); } public static DocumentSnapshotHandle ReadDocumentSnapshotHandleFromProperties(JsonDataReader reader) @@ -349,12 +349,11 @@ public static RazorProjectInfo ReadProjectInfoFromProperties(JsonDataReader read var filePath = reader.ReadNonNullString(nameof(RazorProjectInfo.FilePath)); var configuration = reader.ReadObject(nameof(RazorProjectInfo.Configuration), ReadConfigurationFromProperties) ?? RazorConfiguration.Default; var projectWorkspaceState = reader.ReadObject(nameof(RazorProjectInfo.ProjectWorkspaceState), ReadProjectWorkspaceStateFromProperties) ?? ProjectWorkspaceState.Default; - var rootNamespace = reader.ReadString(nameof(RazorProjectInfo.RootNamespace)); var documents = reader.ReadImmutableArray(nameof(RazorProjectInfo.Documents), static r => r.ReadNonNullObject(ReadDocumentSnapshotHandleFromProperties)); var displayName = Path.GetFileNameWithoutExtension(filePath); - return new RazorProjectInfo(new ProjectKey(projectKeyId), filePath, configuration, rootNamespace, displayName, projectWorkspaceState, documents); + return new RazorProjectInfo(new ProjectKey(projectKeyId), filePath, configuration, displayName, projectWorkspaceState, documents); } public static Checksum ReadChecksum(JsonDataReader reader) diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs index c03051e73c9..ce607e3c18c 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters.cs @@ -39,6 +39,7 @@ public static void WriteProperties(JsonDataWriter writer, RazorConfiguration val writer.WriteIfNotTrue(nameof(value.UseConsolidatedMvcViews), value.UseConsolidatedMvcViews); writer.WriteIfNotFalse(nameof(value.UseRoslynTokenizer), value.UseRoslynTokenizer); writer.WriteIfNotZero(nameof(value.CSharpLanguageVersion), (int)value.CSharpLanguageVersion); + writer.WriteIfNotNull(nameof(value.RootNamespace), value.RootNamespace); writer.WriteArrayIfNotNullOrEmpty(nameof(value.Extensions), value.Extensions, static (w, v) => w.Write(v.ExtensionName)); } @@ -67,7 +68,6 @@ public static void WriteProperties(JsonDataWriter writer, ProjectSnapshotHandle { writer.Write(nameof(value.ProjectId), value.ProjectId.Id.ToString()); writer.WriteObject(nameof(value.Configuration), value.Configuration, WriteProperties); - writer.WriteIfNotNull(nameof(value.RootNamespace), value.RootNamespace); } public static void Write(JsonDataWriter writer, DocumentSnapshotHandle? value) @@ -244,7 +244,6 @@ public static void WriteProperties(JsonDataWriter writer, RazorProjectInfo value writer.Write(nameof(value.FilePath), value.FilePath); writer.WriteObject(nameof(value.Configuration), value.Configuration, WriteProperties); writer.WriteObject(nameof(value.ProjectWorkspaceState), value.ProjectWorkspaceState, WriteProperties); - writer.Write(nameof(value.RootNamespace), value.RootNamespace); writer.WriteArray(nameof(value.Documents), value.Documents, Write); } diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs index f0941e5b38b..0d159b32de0 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/SerializationFormat.cs @@ -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; }