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 77b6d3f0c3..f4c9db8e9a 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs @@ -76,7 +76,7 @@ public class RazorLanguageServerBenchmarkBase : ProjectSnapshotManagerBenchmarkB updater.ProjectAdded(hostProject); var tagHelpers = CommonResources.LegacyTagHelpers; var projectWorkspaceState = ProjectWorkspaceState.Create(tagHelpers, CodeAnalysis.CSharp.LanguageVersion.CSharp11); - updater.ProjectChanged(hostProject, projectWorkspaceState); + updater.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState); updater.DocumentAdded(hostProject.Key, hostDocument, textLoader); }, CancellationToken.None); 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 872d1c2a8d..25f498d721 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs @@ -369,21 +369,34 @@ internal partial class RazorProjectService : IRazorProjectService, IRazorProject _logger.LogInformation($"Updating project '{project.Key}' TagHelpers ({projectWorkspaceState.TagHelpers.Length}) and C# Language Version ({projectWorkspaceState.CSharpLanguageVersion})."); } + updater.ProjectWorkspaceStateChanged(project.Key, projectWorkspaceState); + var currentConfiguration = project.Configuration; var currentRootNamespace = project.RootNamespace; + if (currentConfiguration.ConfigurationName == configuration?.ConfigurationName && + currentRootNamespace == rootNamespace) + { + _logger.LogTrace($"Updating project '{project.Key}'. The project is already using configuration '{configuration.ConfigurationName}' and root namespace '{rootNamespace}'."); + return; + } + if (configuration is null) { configuration = FallbackRazorConfiguration.Latest; _logger.LogInformation($"Updating project '{project.Key}' to use the latest configuration ('{configuration.ConfigurationName}')'."); } - else if (currentConfiguration.Equals(configuration) && - currentRootNamespace == rootNamespace) + else if (currentConfiguration.ConfigurationName != configuration.ConfigurationName) { - _logger.LogTrace($"Updating project '{project.Key}'. The project is already using configuration '{configuration.ConfigurationName}' and root namespace '{rootNamespace}'."); + _logger.LogInformation($"Updating project '{project.Key}' to Razor configuration '{configuration.ConfigurationName}' with language version '{configuration.LanguageVersion}'."); + } + + if (currentRootNamespace != rootNamespace) + { + _logger.LogInformation($"Updating project '{project.Key}''s root namespace to '{rootNamespace}'."); } var hostProject = new HostProject(project.FilePath, project.IntermediateOutputPath, configuration, rootNamespace, displayName); - updater.ProjectChanged(hostProject, projectWorkspaceState); + updater.ProjectConfigurationChanged(hostProject); }, cancellationToken); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentState.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentState.cs index c3b47291e3..7c09f3bfc4 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentState.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentState.cs @@ -150,6 +150,15 @@ internal partial class DocumentState return false; } + public virtual DocumentState WithConfigurationChange() + { + var state = new DocumentState(HostDocument, Version + 1, _textAndVersion, _textLoader); + + // Do not cache computed state + + return state; + } + public virtual DocumentState WithImportsChange() { var state = new DocumentState(HostDocument, Version + 1, _textAndVersion, _textLoader); @@ -160,7 +169,7 @@ internal partial class DocumentState return state; } - public virtual DocumentState WithProjectChange() + public virtual DocumentState WithProjectWorkspaceStateChange() { var state = new DocumentState(HostDocument, Version + 1, _textAndVersion, _textLoader); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectDifference.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectDifference.cs index 20d383dd8e..f309380a70 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectDifference.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectDifference.cs @@ -8,9 +8,10 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem; [Flags] internal enum ProjectDifference { - None = 1 << 0, - ConfigurationChanged = 1 << 1, - DocumentAdded = 1 << 2, - DocumentRemoved = 1 << 3, - DocumentChanged = 1 << 4, + None = 0, + ConfigurationChanged = 1, + ProjectWorkspaceStateChanged = 2, + DocumentAdded = 4, + DocumentRemoved = 8, + DocumentChanged = 16, } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshotManager.Updater.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshotManager.Updater.cs index 57c016bfa5..12ce627279 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshotManager.Updater.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshotManager.Updater.cs @@ -50,8 +50,11 @@ internal partial class ProjectSnapshotManager public void ProjectRemoved(ProjectKey projectKey) => instance.ProjectRemoved(projectKey); - public void ProjectChanged(HostProject project, ProjectWorkspaceState projectWorkspaceState) - => instance.ProjectChanged(project, projectWorkspaceState); + public void ProjectConfigurationChanged(HostProject project) + => instance.ProjectConfigurationChanged(project); + + public void ProjectWorkspaceStateChanged(ProjectKey projectKey, ProjectWorkspaceState projectWorkspaceState) + => instance.ProjectWorkspaceStateChanged(projectKey, projectWorkspaceState); public void SolutionOpened() => instance.SolutionOpened(); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshotManager.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshotManager.cs index 9b7eba4a3a..1436c39a5d 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshotManager.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectSnapshotManager.cs @@ -306,7 +306,7 @@ internal partial class ProjectSnapshotManager : IProjectSnapshotManager, IDispos } } - private void ProjectChanged(HostProject hostProject, ProjectWorkspaceState projectWorkspaceState) + private void ProjectConfigurationChanged(HostProject hostProject) { if (_initialized) { @@ -316,7 +316,25 @@ internal partial class ProjectSnapshotManager : IProjectSnapshotManager, IDispos if (TryUpdate( hostProject.Key, documentFilePath: null, - new ProjectChangeAction(hostProject, projectWorkspaceState), + new HostProjectUpdatedAction(hostProject), + out var oldSnapshot, + out var newSnapshot)) + { + NotifyListeners(oldSnapshot, newSnapshot, documentFilePath: null, ProjectChangeKind.ProjectChanged); + } + } + + private void ProjectWorkspaceStateChanged(ProjectKey projectKey, ProjectWorkspaceState projectWorkspaceState) + { + if (_initialized) + { + _dispatcher.AssertRunningOnDispatcher(); + } + + if (TryUpdate( + projectKey, + documentFilePath: null, + new ProjectWorkspaceStateChangedAction(projectWorkspaceState), out var oldSnapshot, out var newSnapshot)) { @@ -573,8 +591,11 @@ internal partial class ProjectSnapshotManager : IProjectSnapshotManager, IDispos } } - case ProjectChangeAction(var hostProject, var workspaceState): - return new Entry(originalEntry.State.WithHostProjectAndWorkspaceState(hostProject, workspaceState)); + case ProjectWorkspaceStateChangedAction(var workspaceState): + return new Entry(originalEntry.State.WithProjectWorkspaceState(workspaceState)); + + case HostProjectUpdatedAction(var hostProject): + return new Entry(originalEntry.State.WithHostProject(hostProject)); default: throw new InvalidOperationException($"Unexpected action type {action.GetType()}"); 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 7d89c69336..37a5189547 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectState.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectState.cs @@ -21,6 +21,12 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem; // Internal tracker for DefaultProjectSnapshot internal class ProjectState { + private const ProjectDifference ClearConfigurationVersionMask = ProjectDifference.ConfigurationChanged; + + private const ProjectDifference ClearProjectWorkspaceStateVersionMask = + ProjectDifference.ConfigurationChanged | + ProjectDifference.ProjectWorkspaceStateChanged; + private const ProjectDifference ClearDocumentCollectionVersionMask = ProjectDifference.ConfigurationChanged | ProjectDifference.DocumentAdded | @@ -91,9 +97,7 @@ internal class ProjectState DocumentCollectionVersion = Version; } - if (older._projectEngine != null && - HostProject.Configuration == older.HostProject.Configuration && - CSharpLanguageVersion == older.CSharpLanguageVersion) + if ((difference & ClearConfigurationVersionMask) == 0 && older._projectEngine != null) { // Optimistically cache the RazorProjectEngine. _projectEngine = older.ProjectEngine; @@ -104,7 +108,9 @@ internal class ProjectState ConfigurationVersion = Version; } - if (ProjectWorkspaceState.Equals(older.ProjectWorkspaceState)) + if ((difference & ClearProjectWorkspaceStateVersionMask) == 0 || + ProjectWorkspaceState == older.ProjectWorkspaceState || + ProjectWorkspaceState.Equals(older.ProjectWorkspaceState)) { ProjectWorkspaceStateVersion = older.ProjectWorkspaceStateVersion; } @@ -112,6 +118,14 @@ internal class ProjectState { ProjectWorkspaceStateVersion = Version; } + + if ((difference & ClearProjectWorkspaceStateVersionMask) != 0 && + CSharpLanguageVersion != older.CSharpLanguageVersion) + { + // C# language version changed. This impacts the ProjectEngine, reset it. + _projectEngine = null; + ConfigurationVersion = Version; + } } // Internal set for testing. @@ -303,16 +317,20 @@ internal class ProjectState return state; } - public ProjectState WithHostProjectAndWorkspaceState(HostProject hostProject, ProjectWorkspaceState projectWorkspaceState) + public ProjectState WithHostProject(HostProject hostProject) { + if (hostProject is null) + { + throw new ArgumentNullException(nameof(hostProject)); + } + if (HostProject.Configuration.Equals(hostProject.Configuration) && - HostProject.RootNamespace == hostProject.RootNamespace && - ProjectWorkspaceState.Equals(projectWorkspaceState)) + HostProject.RootNamespace == hostProject.RootNamespace) { return this; } - var documents = Documents.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.WithProjectChange(), FilePathNormalizingComparer.Instance); + var documents = Documents.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.WithConfigurationChange(), FilePathNormalizingComparer.Instance); // If the host project has changed then we need to recompute the imports map var importsToRelatedDocuments = s_emptyImportsToRelatedDocuments; @@ -323,7 +341,25 @@ internal class ProjectState importsToRelatedDocuments = AddToImportsToRelatedDocuments(importsToRelatedDocuments, document.Value.HostDocument.FilePath, importTargetPaths); } - var state = new ProjectState(this, ProjectDifference.ConfigurationChanged, hostProject, projectWorkspaceState, documents, importsToRelatedDocuments); + var state = new ProjectState(this, ProjectDifference.ConfigurationChanged, hostProject, ProjectWorkspaceState, documents, importsToRelatedDocuments); + return state; + } + + public ProjectState WithProjectWorkspaceState(ProjectWorkspaceState projectWorkspaceState) + { + if (ProjectWorkspaceState == projectWorkspaceState) + { + return this; + } + + if (ProjectWorkspaceState.Equals(projectWorkspaceState)) + { + return this; + } + + var difference = ProjectDifference.ProjectWorkspaceStateChanged; + var documents = Documents.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.WithProjectWorkspaceStateChange(), FilePathNormalizingComparer.Instance); + var state = new ProjectState(this, difference, HostProject, projectWorkspaceState, documents, ImportsToRelatedDocuments); return state; } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/UpdateProjectAction.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/UpdateProjectAction.cs index 6ecc957629..bc6e89a202 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/UpdateProjectAction.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/UpdateProjectAction.cs @@ -30,4 +30,6 @@ internal record ProjectAddedAction(HostProject HostProject) : IUpdateProjectActi internal record ProjectRemovedAction(ProjectKey ProjectKey) : IUpdateProjectAction; -internal record ProjectChangeAction(HostProject HostProject, ProjectWorkspaceState WorkspaceState) : IUpdateProjectAction; +internal record HostProjectUpdatedAction(HostProject HostProject) : IUpdateProjectAction; + +internal record ProjectWorkspaceStateChangedAction(ProjectWorkspaceState WorkspaceState) : IUpdateProjectAction; 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 8d0cf1b08e..295ec7ec6c 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 @@ -85,7 +85,7 @@ internal class ProjectSnapshotSynchronizationService( if (state.projectWorkspaceState != null) { - updater.ProjectChanged(state.hostProject, state.projectWorkspaceState); + updater.ProjectWorkspaceStateChanged(state.hostProject.Key, state.projectWorkspaceState); } }, state: (hostProject, projectWorkspaceState: args.Newer.ProjectWorkspaceState), @@ -108,16 +108,31 @@ internal class ProjectSnapshotSynchronizationService( } else if (args.Kind == ProjectProxyChangeKind.ProjectChanged) { - if (!args.Older!.Configuration.Equals(args.Newer!.Configuration) || - !args.Older.ProjectWorkspaceState.Equals(args.Newer.ProjectWorkspaceState)) + if (!args.Older!.Configuration.Equals(args.Newer!.Configuration)) { 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 projectWorkspaceState = args.Newer.ProjectWorkspaceState; await _projectManager.UpdateAsync( - static (updater, state) => updater.ProjectChanged(state.hostProject, state.projectWorkspaceState), - state: (hostProject, projectWorkspaceState), + static (updater, hostProject) => updater.ProjectConfigurationChanged(hostProject), + state: hostProject, + CancellationToken.None); + } + else if (args.Older.ProjectWorkspaceState != args.Newer.ProjectWorkspaceState || + args.Older.ProjectWorkspaceState?.Equals(args.Newer.ProjectWorkspaceState) == false) + { + var guestPath = ResolveGuestPath(args.Newer.FilePath); + await _projectManager.UpdateAsync( + static (updater, state) => + { + var projectKeys = updater.GetAllProjectKeys(state.guestPath); + + foreach (var projectKey in projectKeys) + { + updater.ProjectWorkspaceStateChanged(projectKey, state.projectWorkspaceState); + } + }, + state: (guestPath, projectWorkspaceState: args.Newer.ProjectWorkspaceState), CancellationToken.None); } } @@ -137,7 +152,7 @@ internal class ProjectSnapshotSynchronizationService( if (state.projectWorkspaceState is not null) { - updater.ProjectChanged(state.hostProject, state.projectWorkspaceState); + updater.ProjectWorkspaceStateChanged(state.hostProject.Key, state.projectWorkspaceState); } }, state: (hostProject, projectWorkspaceState: projectHandle.ProjectWorkspaceState), 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 74ee53de74..de2e60c007 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/WindowsRazorProjectHostBase.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/WindowsRazorProjectHostBase.cs @@ -265,7 +265,7 @@ internal abstract partial class WindowsRazorProjectHostBase : OnceInitializedOnc protected static void UpdateProject(ProjectSnapshotManager.Updater updater, HostProject project) { - if (!updater.TryGetLoadedProject(project.Key, out var current)) + if (!updater.TryGetLoadedProject(project.Key, out _)) { // Just in case we somehow got in a state where VS didn't tell us that solution close was finished, lets just // ensure we're going to actually do something with the new project that we've just been told about. @@ -275,7 +275,7 @@ internal abstract partial class WindowsRazorProjectHostBase : OnceInitializedOnc } else { - updater.ProjectChanged(project, current.ProjectWorkspaceState); + updater.ProjectConfigurationChanged(project); } } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs index 3a4f66b2c1..e6b29390c6 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs @@ -157,18 +157,17 @@ internal sealed partial class ProjectWorkspaceStateGenerator( .UpdateAsync( static (updater, state) => { - var (projectSnapshot, workspaceState, logger, cancellationToken) = state; + var (projectKey, workspaceState, logger, cancellationToken) = state; if (cancellationToken.IsCancellationRequested) { return; } - logger.LogTrace($"Updating project with {workspaceState.TagHelpers.Length} tag helper(s) for '{projectSnapshot.Key}'"); - var hostProject = new HostProject(projectSnapshot.FilePath, projectSnapshot.IntermediateOutputPath, projectSnapshot.Configuration, projectSnapshot.RootNamespace); - updater.ProjectChanged(hostProject, workspaceState); + logger.LogTrace($"Updating project with {workspaceState.TagHelpers.Length} tag helper(s) for '{projectKey}'"); + updater.ProjectWorkspaceStateChanged(projectKey, workspaceState); }, - state: (projectSnapshot, workspaceState, _logger, cancellationToken), + state: (projectKey, workspaceState, _logger, cancellationToken), cancellationToken) .ConfigureAwait(false); } 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 7a6a69eff7..7662dfbf0f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeDocumentReferenceHolderTest.cs @@ -135,7 +135,7 @@ public class CodeDocumentReferenceHolderTest(ITestOutputHelper testOutput) : Lan // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProject with { Configuration = RazorConfiguration.Default, RootNamespace = "NewRootNamespace" }, documentSnapshot.Project.ProjectWorkspaceState); + updater.ProjectConfigurationChanged(s_hostProject with { Configuration = RazorConfiguration.Default, RootNamespace = "NewRootNamespace" }); }); PerformFullGC(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs index 691576244d..ffdff50874 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs @@ -46,7 +46,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp await projectManager.UpdateAsync(updater => { - updater.ProjectChanged(hostProject, ProjectWorkspaceState.Create([builder.Build()])); + updater.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Create([builder.Build()])); }); var uri = new Uri(hostDocument1.FilePath); @@ -106,7 +106,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp await projectManager.UpdateAsync(updater => { - updater.ProjectChanged(hostProject, ProjectWorkspaceState.Create([builder.Build()])); + updater.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Create([builder.Build()])); }); var uri = new Uri(hostDocument1.FilePath); @@ -177,7 +177,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp await projectManager.UpdateAsync(updater => { - updater.ProjectChanged(hostProject, ProjectWorkspaceState.Create([builder.Build()])); + updater.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Create([builder.Build()])); }); var uri = new Uri(hostDocument1.FilePath); @@ -332,7 +332,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp await projectManager.UpdateAsync(updater => { - updater.ProjectChanged(hostProject, ProjectWorkspaceState.Create([builder.Build()])); + updater.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Create([builder.Build()])); }); var uri = new Uri(hostDocument1.FilePath); 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 77827f12d7..7c05c89c15 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/OpenDocumentGeneratorTest.cs @@ -142,7 +142,8 @@ public class OpenDocumentGeneratorTest(ITestOutputHelper testOutput) : LanguageS updater.DocumentAdded(_hostProject1.Key, _documents[0], _documents[0].CreateEmptyTextLoader()); // Act - updater.ProjectChanged(_hostProject1, ProjectWorkspaceState.Create(LanguageVersion.CSharp8)); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, + ProjectWorkspaceState.Create(LanguageVersion.CSharp8)); }); // Assert @@ -165,7 +166,8 @@ public class OpenDocumentGeneratorTest(ITestOutputHelper testOutput) : LanguageS updater.DocumentOpened(_hostProject1.Key, _documents[0].FilePath, SourceText.From(string.Empty)); // Act - updater.ProjectChanged(_hostProject1, ProjectWorkspaceState.Create(LanguageVersion.CSharp8)); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, + ProjectWorkspaceState.Create(LanguageVersion.CSharp8)); }); // Assert 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 1c06d64b97..4c78d3dd3d 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 @@ -656,11 +656,10 @@ public class RenameEndpointTest(ITestOutputHelper testOutput) : LanguageServerTe var projectKey1 = await projectService.GetTestAccessor().AddProjectAsync( s_projectFilePath1, s_intermediateOutputPath1, RazorConfiguration.Default, RootNamespace1, displayName: null, DisposalToken); - var hostProject1 = new HostProject(s_indexFilePath1, s_intermediateOutputPath1, RazorConfiguration.Default, RootNamespace1, displayName: null); await projectManager.UpdateAsync(updater => { - updater.ProjectChanged(hostProject1, ProjectWorkspaceState.Create(tagHelpers)); + updater.ProjectWorkspaceStateChanged(projectKey1, ProjectWorkspaceState.Create(tagHelpers)); }); await projectService.AddDocumentToPotentialProjectsAsync(s_componentFilePath1, DisposalToken); @@ -679,11 +678,10 @@ public class RenameEndpointTest(ITestOutputHelper testOutput) : LanguageServerTe var projectKey2 = await projectService.GetTestAccessor().AddProjectAsync( s_projectFilePath2, s_intermediateOutputPath2, RazorConfiguration.Default, RootNamespace2, displayName: null, DisposalToken); - var hostProject2 = new HostProject(s_projectFilePath2, s_intermediateOutputPath2, RazorConfiguration.Default, RootNamespace2, displayName: null); await projectManager.UpdateAsync(updater => { - updater.ProjectChanged(hostProject2, ProjectWorkspaceState.Create(tagHelpers)); + updater.ProjectWorkspaceStateChanged(projectKey2, ProjectWorkspaceState.Create(tagHelpers)); }); await projectService.AddDocumentToPotentialProjectsAsync(s_componentFilePath3, DisposalToken); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/DocumentStateTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/DocumentStateTest.cs index 8a0de5c43c..2632887a2e 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/DocumentStateTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/DocumentStateTest.cs @@ -63,14 +63,14 @@ public class DocumentStateTest : ToolingTestBase } [Fact] - public void DocumentState_WithProjectChange_CachesSnapshotText() + public void DocumentState_WithConfigurationChange_CachesSnapshotText() { // Arrange var original = DocumentState.Create(_hostDocument, DocumentState.EmptyLoader) .WithText(_text, VersionStamp.Create()); // Act - var state = original.WithProjectChange(); + var state = original.WithConfigurationChange(); // Assert Assert.True(state.TryGetText(out _)); @@ -78,7 +78,7 @@ public class DocumentStateTest : ToolingTestBase } [Fact] - public async Task DocumentState_WithProjectChange_CachesLoadedText() + public async Task DocumentState_WithConfigurationChange_CachesLoadedText() { // Arrange var original = DocumentState.Create(_hostDocument, DocumentState.EmptyLoader) @@ -87,7 +87,7 @@ public class DocumentStateTest : ToolingTestBase await original.GetTextAsync(DisposalToken); // Act - var state = original.WithProjectChange(); + var state = original.WithConfigurationChange(); // Assert Assert.True(state.TryGetText(out _)); @@ -125,4 +125,36 @@ public class DocumentStateTest : ToolingTestBase Assert.True(state.TryGetText(out _)); Assert.True(state.TryGetTextVersion(out _)); } + + [Fact] + public void DocumentState_WithProjectWorkspaceStateChange_CachesSnapshotText() + { + // Arrange + var original = DocumentState.Create(_hostDocument, DocumentState.EmptyLoader) + .WithText(_text, VersionStamp.Create()); + + // Act + var state = original.WithProjectWorkspaceStateChange(); + + // Assert + Assert.True(state.TryGetText(out _)); + Assert.True(state.TryGetTextVersion(out _)); + } + + [Fact] + public async Task DocumentState_WithProjectWorkspaceStateChange_CachesLoadedText() + { + // Arrange + var original = DocumentState.Create(_hostDocument, DocumentState.EmptyLoader) + .WithTextLoader(_textLoader); + + await original.GetTextAsync(DisposalToken); + + // Act + var state = original.WithProjectWorkspaceStateChange(); + + // Assert + Assert.True(state.TryGetText(out _)); + Assert.True(state.TryGetTextVersion(out _)); + } } diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs index 1fce00bb94..7dd40de184 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectStateGeneratedOutputTest.cs @@ -154,7 +154,7 @@ public class ProjectStateGeneratedOutputTest : WorkspaceTestBase var changed = ProjectWorkspaceState.Default; // Act - var state = original.WithHostProjectAndWorkspaceState(original.HostProject, changed); + var state = original.WithProjectWorkspaceState(changed); // Assert var (actualOutput, actualInputVersion) = await GetOutputAsync(state, _hostDocument, DisposalToken); @@ -175,7 +175,7 @@ public class ProjectStateGeneratedOutputTest : WorkspaceTestBase var changed = ProjectWorkspaceState.Create(_someTagHelpers); // Act - var state = original.WithHostProjectAndWorkspaceState(original.HostProject, changed); + var state = original.WithProjectWorkspaceState(changed); // Assert var (actualOutput, actualInputVersion) = await GetOutputAsync(state, _hostDocument, DisposalToken); @@ -199,7 +199,7 @@ public class ProjectStateGeneratedOutputTest : WorkspaceTestBase var (originalOutput, originalInputVersion) = await GetOutputAsync(original, _hostDocument, DisposalToken); // Act - var state = original.WithHostProjectAndWorkspaceState(original.HostProject, changedWorkspaceState); + var state = original.WithProjectWorkspaceState(changedWorkspaceState); // Assert var (actualOutput, actualInputVersion) = await GetOutputAsync(state, _hostDocument, DisposalToken); @@ -219,7 +219,7 @@ public class ProjectStateGeneratedOutputTest : WorkspaceTestBase var (originalOutput, originalInputVersion) = await GetOutputAsync(original, _hostDocument, DisposalToken); // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProjectWithConfigurationChange, original.ProjectWorkspaceState); + var state = original.WithHostProject(_hostProjectWithConfigurationChange); // Assert var (actualOutput, actualInputVersion) = await GetOutputAsync(state, _hostDocument, DisposalToken); 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 e88073b55a..f1c3eb75ef 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 @@ -529,7 +529,7 @@ public class ProjectStateTest : WorkspaceTestBase } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_ConfigurationChange_UpdatesConfigurationState() + public void ProjectState_WithHostProject_ConfigurationChange_UpdatesConfigurationState() { // Arrange var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState) @@ -541,7 +541,7 @@ public class ProjectStateTest : WorkspaceTestBase var originalProjectWorkspaceStateVersion = original.ConfigurationVersion; // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProjectWithConfigurationChange, _projectWorkspaceState); + var state = original.WithHostProject(_hostProjectWithConfigurationChange); // Assert Assert.NotEqual(original.Version, state.Version); @@ -567,7 +567,7 @@ public class ProjectStateTest : WorkspaceTestBase } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_RootNamespaceChange_UpdatesConfigurationState() + public void ProjectState_WithHostProject_RootNamespaceChange_UpdatesConfigurationState() { // Arrange var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState) @@ -580,14 +580,14 @@ public class ProjectStateTest : WorkspaceTestBase _ = original.ConfigurationVersion; // Act - var state = original.WithHostProjectAndWorkspaceState(hostProjectWithRootNamespaceChange, _projectWorkspaceState); + var state = original.WithHostProject(hostProjectWithRootNamespaceChange); // Assert Assert.NotSame(original, state); } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_NoConfigurationChange_Noops() + public void ProjectState_WithHostProject_NoConfigurationChange_Noops() { // Arrange var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState) @@ -598,14 +598,14 @@ public class ProjectStateTest : WorkspaceTestBase _ = original.ProjectWorkspaceStateVersion; // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProject, _projectWorkspaceState); + var state = original.WithHostProject(_hostProject); // Assert Assert.Same(original, state); } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_CallsConfigurationChangeOnDocumentState() + public void ProjectState_WithHostProject_CallsConfigurationChangeOnDocumentState() { // Arrange var callCount = 0; @@ -618,7 +618,7 @@ public class ProjectStateTest : WorkspaceTestBase original.Documents = documents.ToImmutable(); // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProjectWithConfigurationChange, _projectWorkspaceState); + var state = original.WithHostProject(_hostProjectWithConfigurationChange); // Assert Assert.NotEqual(original.Version, state.Version); @@ -627,14 +627,14 @@ public class ProjectStateTest : WorkspaceTestBase } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_ResetsImportedDocuments() + public void ProjectState_WithHostProject_ResetsImportedDocuments() { // Arrange var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState); original = original.WithAddedHostDocument(TestProjectData.SomeProjectFile1, DocumentState.EmptyLoader); // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProjectWithConfigurationChange, _projectWorkspaceState); + var state = original.WithHostProject(_hostProjectWithConfigurationChange); // Assert var importMap = Assert.Single(state.ImportsToRelatedDocuments); @@ -643,7 +643,7 @@ public class ProjectStateTest : WorkspaceTestBase } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_Changed() + public void ProjectState_WithProjectWorkspaceState_Changed() { // Arrange var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState) @@ -657,7 +657,7 @@ public class ProjectStateTest : WorkspaceTestBase var changed = ProjectWorkspaceState.Create(_projectWorkspaceState.TagHelpers, LanguageVersion.CSharp6); // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProject, changed); + var state = original.WithProjectWorkspaceState(changed); // Assert Assert.NotEqual(original.Version, state.Version); @@ -682,7 +682,7 @@ public class ProjectStateTest : WorkspaceTestBase } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_Changed_TagHelpersChanged() + public void ProjectState_WithProjectWorkspaceState_Changed_TagHelpersChanged() { // Arrange var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState) @@ -696,7 +696,7 @@ public class ProjectStateTest : WorkspaceTestBase var changed = ProjectWorkspaceState.Default; // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProject, changed); + var state = original.WithProjectWorkspaceState(changed); // Assert Assert.NotEqual(original.Version, state.Version); @@ -716,7 +716,7 @@ public class ProjectStateTest : WorkspaceTestBase } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_IdenticalState_Caches() + public void ProjectState_WithProjectWorkspaceState_IdenticalState_Caches() { // Arrange var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState) @@ -730,21 +730,21 @@ public class ProjectStateTest : WorkspaceTestBase var changed = ProjectWorkspaceState.Create(original.TagHelpers, original.CSharpLanguageVersion); // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProject, changed); + var state = original.WithProjectWorkspaceState(changed); // Assert Assert.Same(original, state); } [Fact] - public void ProjectState_WithHostProjectAndWorkspaceState_CallsWorkspaceProjectChangeOnDocumentState() + public void ProjectState_WithProjectWorkspaceState_CallsWorkspaceProjectChangeOnDocumentState() { // Arrange var callCount = 0; var documents = ImmutableDictionary.CreateBuilder(FilePathComparer.Instance); - documents[_documents[1].FilePath] = TestDocumentState.Create(_documents[1], onConfigurationChange: () => callCount++); - documents[_documents[2].FilePath] = TestDocumentState.Create(_documents[2], onConfigurationChange: () => callCount++); + documents[_documents[1].FilePath] = TestDocumentState.Create(_documents[1], onProjectWorkspaceStateChange: () => callCount++); + documents[_documents[2].FilePath] = TestDocumentState.Create(_documents[2], onProjectWorkspaceStateChange: () => callCount++); var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState); original.Documents = documents.ToImmutable(); @@ -752,7 +752,7 @@ public class ProjectStateTest : WorkspaceTestBase var changed = ProjectWorkspaceState.Default; // Act - var state = original.WithHostProjectAndWorkspaceState(_hostProject, changed); + var state = original.WithProjectWorkspaceState(changed); // Assert Assert.NotEqual(original.Version, state.Version); @@ -991,7 +991,8 @@ public class ProjectStateTest : WorkspaceTestBase Action? onTextChange = null, Action? onTextLoaderChange = null, Action? onConfigurationChange = null, - Action? onImportsChange = null) + Action? onImportsChange = null, + Action? onProjectWorkspaceStateChange = null) { return new TestDocumentState( hostDocument, @@ -999,13 +1000,15 @@ public class ProjectStateTest : WorkspaceTestBase onTextChange, onTextLoaderChange, onConfigurationChange, - onImportsChange); + onImportsChange, + onProjectWorkspaceStateChange); } private readonly Action? _onTextChange; private readonly Action? _onTextLoaderChange; private readonly Action? _onConfigurationChange; private readonly Action? _onImportsChange; + private readonly Action? _onProjectWorkspaceStateChange; private TestDocumentState( HostDocument hostDocument, @@ -1013,13 +1016,15 @@ public class ProjectStateTest : WorkspaceTestBase Action? onTextChange, Action? onTextLoaderChange, Action? onConfigurationChange, - Action? onImportsChange) + Action? onImportsChange, + Action? onProjectWorkspaceStateChange) : base(hostDocument, version: 1, loader ?? EmptyLoader) { _onTextChange = onTextChange; _onTextLoaderChange = onTextLoaderChange; _onConfigurationChange = onConfigurationChange; _onImportsChange = onImportsChange; + _onProjectWorkspaceStateChange = onProjectWorkspaceStateChange; } public override DocumentState WithText(SourceText sourceText, VersionStamp textVersion) @@ -1034,10 +1039,10 @@ public class ProjectStateTest : WorkspaceTestBase return base.WithTextLoader(loader); } - public override DocumentState WithProjectChange() + public override DocumentState WithConfigurationChange() { _onConfigurationChange?.Invoke(); - return base.WithProjectChange(); + return base.WithConfigurationChange(); } public override DocumentState WithImportsChange() @@ -1045,5 +1050,11 @@ public class ProjectStateTest : WorkspaceTestBase _onImportsChange?.Invoke(); return base.WithImportsChange(); } + + public override DocumentState WithProjectWorkspaceStateChange() + { + _onProjectWorkspaceStateChange?.Invoke(); + return base.WithProjectWorkspaceStateChange(); + } } } 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 4abb011d44..d19a69bede 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 @@ -56,7 +56,7 @@ public class ProjectAvailabilityTests(ITestOutputHelper testOutput) : ToolingTes await projectManager.UpdateAsync(updater => { updater.ProjectAdded(hostProject); - updater.ProjectChanged(hostProject, projectWorkspaceState); + updater.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState); updater.DocumentAdded(hostProject.Key, hostDocument, TestMocks.CreateTextLoader(hostDocument.FilePath, text: "")); }); @@ -101,11 +101,11 @@ public class ProjectAvailabilityTests(ITestOutputHelper testOutput) : ToolingTes await projectManager.UpdateAsync(updater => { updater.ProjectAdded(hostProject1); - updater.ProjectChanged(hostProject1, projectWorkspaceState); + updater.ProjectWorkspaceStateChanged(hostProject1.Key, projectWorkspaceState); updater.DocumentAdded(hostProject1.Key, hostDocument, TestMocks.CreateTextLoader(hostDocument.FilePath, text: "")); updater.ProjectAdded(hostProject2); - updater.ProjectChanged(hostProject2, projectWorkspaceState); + updater.ProjectWorkspaceStateChanged(hostProject2.Key, projectWorkspaceState); updater.DocumentAdded(hostProject2.Key, hostDocument, TestMocks.CreateTextLoader(hostDocument.FilePath, text: "")); }); @@ -150,7 +150,7 @@ public class ProjectAvailabilityTests(ITestOutputHelper testOutput) : ToolingTes await projectManager.UpdateAsync(updater => { updater.ProjectAdded(hostProject1); - updater.ProjectChanged(hostProject1, projectWorkspaceState); + updater.ProjectWorkspaceStateChanged(hostProject1.Key, projectWorkspaceState); updater.DocumentAdded(hostProject1.Key, hostDocument, TestMocks.CreateTextLoader(hostDocument.FilePath, text: "")); updater.ProjectAdded(hostProject2); 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 280e6a1295..729a6f2462 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 @@ -170,7 +170,7 @@ public class ProjectSnapshotSynchronizationServiceTest : VisualStudioWorkspaceTe await _projectManager.UpdateAsync(updater => { updater.ProjectAdded(hostProject); - updater.ProjectChanged(hostProject, newHandle.ProjectWorkspaceState); + updater.ProjectConfigurationChanged(hostProject); }); var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged); @@ -214,7 +214,7 @@ public class ProjectSnapshotSynchronizationServiceTest : VisualStudioWorkspaceTe await _projectManager.UpdateAsync(updater => { updater.ProjectAdded(hostProject); - updater.ProjectChanged(hostProject, oldHandle.ProjectWorkspaceState); + updater.ProjectWorkspaceStateChanged(hostProject.Key, oldHandle.ProjectWorkspaceState); }); var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged); 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 ff77fe3c30..12e9c3e829 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 @@ -44,10 +44,10 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis await projectManager.UpdateAsync(updater => { updater.ProjectAdded(_hostProject1); - updater.ProjectChanged(_hostProject1, _projectWorkspaceState1); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1); updater.ProjectAdded(_hostProject2); - updater.ProjectChanged(_hostProject2, _projectWorkspaceState2); + updater.ProjectWorkspaceStateChanged(_hostProject2.Key, _projectWorkspaceState2); }); using var proxy = new ProjectSnapshotManagerProxy( @@ -77,7 +77,7 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis await projectManager.UpdateAsync(updater => { updater.ProjectAdded(_hostProject1); - updater.ProjectChanged(_hostProject1, _projectWorkspaceState1); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1); }); using var proxy = new ProjectSnapshotManagerProxy( @@ -102,13 +102,12 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis { // Change the project's configuration to force a changed event to be raised. var project = updater.GetLoadedProject(_hostProject1.Key); - updater.ProjectChanged(new( + updater.ProjectConfigurationChanged(new( project.FilePath, project.IntermediateOutputPath, FallbackRazorConfiguration.MVC_1_0, project.RootNamespace, - project.DisplayName), - _projectWorkspaceState1); + project.DisplayName)); }); await proxyAccessor.ProcessingChangedEventTestTask.AssumeNotNull().JoinAsync(); @@ -126,7 +125,7 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis await projectManager.UpdateAsync(updater => { updater.ProjectAdded(_hostProject1); - updater.ProjectChanged(_hostProject1, _projectWorkspaceState1); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1); }); var proxy = new ProjectSnapshotManagerProxy( @@ -144,13 +143,12 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis { // Change the project's configuration to force a changed event to be raised. var project = updater.GetLoadedProject(_hostProject1.Key); - updater.ProjectChanged(new( + updater.ProjectConfigurationChanged(new( project.FilePath, project.IntermediateOutputPath, FallbackRazorConfiguration.MVC_1_0, project.RootNamespace, - project.DisplayName), - _projectWorkspaceState1); + project.DisplayName)); }); // Assert @@ -166,7 +164,7 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis await projectManager.UpdateAsync(updater => { updater.ProjectAdded(_hostProject1); - updater.ProjectChanged(_hostProject1, _projectWorkspaceState1); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1); }); using var proxy = new ProjectSnapshotManagerProxy( @@ -198,10 +196,10 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis await projectManager.UpdateAsync(updater => { updater.ProjectAdded(_hostProject1); - updater.ProjectChanged(_hostProject1, _projectWorkspaceState1); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1); updater.ProjectAdded(_hostProject2); - updater.ProjectChanged(_hostProject2, _projectWorkspaceState2); + updater.ProjectWorkspaceStateChanged(_hostProject2.Key, _projectWorkspaceState2); }); using var proxy = new ProjectSnapshotManagerProxy( @@ -231,7 +229,7 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis await projectManager.UpdateAsync(updater => { updater.ProjectAdded(_hostProject1); - updater.ProjectChanged(_hostProject1, _projectWorkspaceState1); + updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1); }); using var proxy = new ProjectSnapshotManagerProxy( 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 0e5511874e..57d07c5b99 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 @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common.VisualStudio; @@ -143,7 +142,7 @@ public class FallbackProjectManagerTest : VisualStudioWorkspaceTestBase await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(hostProject, ProjectWorkspaceState.Default); + updater.ProjectConfigurationChanged(hostProject); }); project = Assert.Single(_projectManager.GetProjects()); 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 149e604c20..6f127b659d 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 @@ -268,7 +268,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase await _projectManager.UpdateAsync(updater => { updater.ProjectAdded(s_hostProject); - updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers); + updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers); }); var originalTagHelpers = await _projectManager.GetLoadedProject(s_hostProject.Key).GetTagHelpersAsync(DisposalToken); @@ -390,7 +390,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase await _projectManager.UpdateAsync(updater => { updater.ProjectAdded(s_hostProject); - updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers); + updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers); updater.DocumentAdded(s_hostProject.Key, s_documents[0], s_documents[0].CreateEmptyTextLoader()); updater.DocumentAdded(s_hostProject.Key, s_documents[1], s_documents[1].CreateEmptyTextLoader()); updater.DocumentAdded(s_hostProject.Key, s_documents[2], s_documents[2].CreateEmptyTextLoader()); @@ -640,7 +640,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProjectWithConfigurationChange, ProjectWorkspaceState.Default); + updater.ProjectConfigurationChanged(s_hostProjectWithConfigurationChange); }); // Assert @@ -655,7 +655,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase await _projectManager.UpdateAsync(updater => { updater.ProjectAdded(s_hostProject); - updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers); + updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers); }); using var listener = _projectManager.ListenToNotifications(); @@ -663,7 +663,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProjectWithConfigurationChange, _projectWorkspaceStateWithTagHelpers); + updater.ProjectConfigurationChanged(s_hostProjectWithConfigurationChange); }); // Assert @@ -686,7 +686,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProjectWithConfigurationChange, ProjectWorkspaceState.Default); + updater.ProjectConfigurationChanged(s_hostProjectWithConfigurationChange); }); // Assert @@ -703,7 +703,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProject, ProjectWorkspaceState.Default); + updater.ProjectConfigurationChanged(s_hostProject); }); // Assert @@ -745,7 +745,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers); + updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers); }); // Assert @@ -767,7 +767,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers); + updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers); }); // Assert @@ -791,7 +791,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers); + updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers); }); // Assert @@ -806,7 +806,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase await _projectManager.UpdateAsync(updater => { updater.ProjectAdded(s_hostProject); - updater.ProjectChanged(s_hostProject, ProjectWorkspaceState.Default); + updater.ProjectWorkspaceStateChanged(s_hostProject.Key, ProjectWorkspaceState.Default); }); using var listener = _projectManager.ListenToNotifications(); @@ -814,7 +814,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers); + updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers); }); // Assert diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectWorkspaceStateGeneratorTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectWorkspaceStateGeneratorTest.cs index 44973fea64..c1dca22323 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectWorkspaceStateGeneratorTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectWorkspaceStateGeneratorTest.cs @@ -120,7 +120,7 @@ public class ProjectWorkspaceStateGeneratorTest : VisualStudioWorkspaceTestBase await _projectManager.UpdateAsync(updater => { updater.ProjectAdded(_projectSnapshot.HostProject); - updater.ProjectChanged(_projectSnapshot.HostProject, _projectWorkspaceStateWithTagHelpers); + updater.ProjectWorkspaceStateChanged(_projectSnapshot.Key, _projectWorkspaceStateWithTagHelpers); }); // Act diff --git a/src/Razor/test/Microsoft.VisualStudio.LegacyEditor.Razor.Test/VisualStudioDocumentTrackerTest.cs b/src/Razor/test/Microsoft.VisualStudio.LegacyEditor.Razor.Test/VisualStudioDocumentTrackerTest.cs index 2d2f16ba30..adf75ef0fa 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LegacyEditor.Razor.Test/VisualStudioDocumentTrackerTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LegacyEditor.Razor.Test/VisualStudioDocumentTrackerTest.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common.VisualStudio; @@ -471,7 +470,7 @@ public class VisualStudioDocumentTrackerTest : VisualStudioWorkspaceTestBase // Act await _projectManager.UpdateAsync(updater => { - updater.ProjectChanged(_updatedHostProject, ProjectWorkspaceState.Default); + updater.ProjectConfigurationChanged(_updatedHostProject); }); // Assert