Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Revert changes to how projects are updated #11225

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ await projectManager.UpdateAsync(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,34 @@ private Task AddOrUpdateProjectCoreAsync(
_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 == 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ public bool TryGetTextVersion(out VersionStamp result)
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);
Expand All @@ -160,14 +169,12 @@ public virtual DocumentState WithImportsChange()
return state;
}

public virtual DocumentState WithProjectChange(bool cacheComputedState)
public virtual DocumentState WithProjectWorkspaceStateChange()
{
var state = new DocumentState(HostDocument, Version + 1, _textAndVersion, _textLoader);

if (cacheComputedState)
{
state._computedState = new ComputedStateTracker(_computedState);
}
// Optimistically cache the computed state
state._computedState = new ComputedStateTracker(_computedState);

return state;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;

namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;

[Flags]
internal enum ProjectDifference
{
None = 0,
ConfigurationChanged = 1,
ProjectWorkspaceStateChanged = 2,
DocumentAdded = 4,
DocumentRemoved = 8,
DocumentChanged = 16,
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public void ProjectAdded(HostProject project)
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void ProjectAdded(HostProject hostProject)
}
}

private void ProjectChanged(HostProject hostProject, ProjectWorkspaceState projectWorkspaceState)
private void ProjectConfigurationChanged(HostProject hostProject)
{
if (_initialized)
{
Expand All @@ -316,7 +316,25 @@ private void ProjectChanged(HostProject hostProject, ProjectWorkspaceState proje
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))
{
Expand Down Expand Up @@ -573,8 +591,11 @@ private static Entry ComputeNewEntry(Entry originalEntry, IUpdateProjectAction a
}
}

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()}");
Expand Down
Loading