зеркало из https://github.com/dotnet/razor.git
Update ProjectWorkspaceState and HostProject at the same time (#11191)
Preparation for ongoing work to hook up the Roslyn tokenizer and https://github.com/dotnet/razor/issues/11182 I suppose. There were three places that `UpdateProjectWorkspaceState` was called: 1. In `RazorProjectService`, just before calling `UpdateProjectConfiguration` 2. In `ProjectWorkspaceStateGenerator`, where we will need to add a call to `UpdateProjectConfiguration` in future, to wire up the tokenizer 3. In our LiveShare bits, in response to events from the above. Previous attempts to plumb through more things for `RazorConfiguration` resulted in RPS failures, that appeared to be simply more compilations of closed files. This makes sense because we were adding another update, which would have triggered another set of `ProjectChanged` events. I thought it would make more sense to combine these two updates together, so no matter which part of the project was being updated, there could be a single `ProjectChanged` notification. This is that.
This commit is contained in:
Коммит
95f862d12e
|
@ -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.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState);
|
||||
updater.ProjectChanged(hostProject, projectWorkspaceState);
|
||||
updater.DocumentAdded(hostProject.Key, hostDocument, textLoader);
|
||||
},
|
||||
CancellationToken.None);
|
||||
|
|
|
@ -369,34 +369,21 @@ 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.ConfigurationName != configuration.ConfigurationName)
|
||||
else if (currentConfiguration == configuration &&
|
||||
currentRootNamespace == 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}'.");
|
||||
_logger.LogTrace($"Updating project '{project.Key}'. The project is already using configuration '{configuration.ConfigurationName}' and root namespace '{rootNamespace}'.");
|
||||
}
|
||||
|
||||
var hostProject = new HostProject(project.FilePath, project.IntermediateOutputPath, configuration, rootNamespace, displayName);
|
||||
updater.ProjectConfigurationChanged(hostProject);
|
||||
updater.ProjectChanged(hostProject, projectWorkspaceState);
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
|
|
|
@ -150,15 +150,6 @@ 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);
|
||||
|
@ -169,7 +160,7 @@ internal partial class DocumentState
|
|||
return state;
|
||||
}
|
||||
|
||||
public virtual DocumentState WithProjectWorkspaceStateChange()
|
||||
public virtual DocumentState WithProjectChange()
|
||||
{
|
||||
var state = new DocumentState(HostDocument, Version + 1, _textAndVersion, _textLoader);
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
// 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,
|
||||
}
|
|
@ -50,11 +50,8 @@ internal partial class ProjectSnapshotManager
|
|||
public void ProjectRemoved(ProjectKey projectKey)
|
||||
=> instance.ProjectRemoved(projectKey);
|
||||
|
||||
public void ProjectConfigurationChanged(HostProject project)
|
||||
=> instance.ProjectConfigurationChanged(project);
|
||||
|
||||
public void ProjectWorkspaceStateChanged(ProjectKey projectKey, ProjectWorkspaceState projectWorkspaceState)
|
||||
=> instance.ProjectWorkspaceStateChanged(projectKey, projectWorkspaceState);
|
||||
public void ProjectChanged(HostProject project, ProjectWorkspaceState projectWorkspaceState)
|
||||
=> instance.ProjectChanged(project, projectWorkspaceState);
|
||||
|
||||
public void SolutionOpened()
|
||||
=> instance.SolutionOpened();
|
||||
|
|
|
@ -306,7 +306,7 @@ internal partial class ProjectSnapshotManager : IProjectSnapshotManager, IDispos
|
|||
}
|
||||
}
|
||||
|
||||
private void ProjectConfigurationChanged(HostProject hostProject)
|
||||
private void ProjectChanged(HostProject hostProject, ProjectWorkspaceState projectWorkspaceState)
|
||||
{
|
||||
if (_initialized)
|
||||
{
|
||||
|
@ -316,25 +316,7 @@ internal partial class ProjectSnapshotManager : IProjectSnapshotManager, IDispos
|
|||
if (TryUpdate(
|
||||
hostProject.Key,
|
||||
documentFilePath: null,
|
||||
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),
|
||||
new ProjectChangeAction(hostProject, projectWorkspaceState),
|
||||
out var oldSnapshot,
|
||||
out var newSnapshot))
|
||||
{
|
||||
|
@ -591,11 +573,8 @@ internal partial class ProjectSnapshotManager : IProjectSnapshotManager, IDispos
|
|||
}
|
||||
}
|
||||
|
||||
case ProjectWorkspaceStateChangedAction(var workspaceState):
|
||||
return new Entry(originalEntry.State.WithProjectWorkspaceState(workspaceState));
|
||||
|
||||
case HostProjectUpdatedAction(var hostProject):
|
||||
return new Entry(originalEntry.State.WithHostProject(hostProject));
|
||||
case ProjectChangeAction(var hostProject, var workspaceState):
|
||||
return new Entry(originalEntry.State.WithHostProjectAndWorkspaceState(hostProject, workspaceState));
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"Unexpected action type {action.GetType()}");
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
|
@ -21,17 +20,6 @@ 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 |
|
||||
ProjectDifference.DocumentRemoved;
|
||||
|
||||
private static readonly ImmutableDictionary<string, DocumentState> s_emptyDocuments = ImmutableDictionary.Create<string, DocumentState>(FilePathNormalizingComparer.Instance);
|
||||
private static readonly ImmutableDictionary<string, ImmutableArray<string>> s_emptyImportsToRelatedDocuments = ImmutableDictionary.Create<string, ImmutableArray<string>>(FilePathNormalizingComparer.Instance);
|
||||
private readonly object _lock;
|
||||
|
@ -70,7 +58,7 @@ internal class ProjectState
|
|||
|
||||
private ProjectState(
|
||||
ProjectState older,
|
||||
ProjectDifference difference,
|
||||
bool numberOfDocumentsMayHaveChanged,
|
||||
HostProject hostProject,
|
||||
ProjectWorkspaceState projectWorkspaceState,
|
||||
ImmutableDictionary<string, DocumentState> documents,
|
||||
|
@ -87,17 +75,19 @@ internal class ProjectState
|
|||
|
||||
_lock = new object();
|
||||
|
||||
if ((difference & ClearDocumentCollectionVersionMask) == 0)
|
||||
if (numberOfDocumentsMayHaveChanged)
|
||||
{
|
||||
DocumentCollectionVersion = Version;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Document collection hasn't changed
|
||||
DocumentCollectionVersion = older.DocumentCollectionVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
DocumentCollectionVersion = Version;
|
||||
}
|
||||
|
||||
if ((difference & ClearConfigurationVersionMask) == 0 && older._projectEngine != null)
|
||||
if (older._projectEngine != null &&
|
||||
HostProject.Configuration == older.HostProject.Configuration &&
|
||||
CSharpLanguageVersion == older.CSharpLanguageVersion)
|
||||
{
|
||||
// Optimistically cache the RazorProjectEngine.
|
||||
_projectEngine = older.ProjectEngine;
|
||||
|
@ -108,9 +98,7 @@ internal class ProjectState
|
|||
ConfigurationVersion = Version;
|
||||
}
|
||||
|
||||
if ((difference & ClearProjectWorkspaceStateVersionMask) == 0 ||
|
||||
ProjectWorkspaceState == older.ProjectWorkspaceState ||
|
||||
ProjectWorkspaceState.Equals(older.ProjectWorkspaceState))
|
||||
if (ProjectWorkspaceState.Equals(older.ProjectWorkspaceState))
|
||||
{
|
||||
ProjectWorkspaceStateVersion = older.ProjectWorkspaceStateVersion;
|
||||
}
|
||||
|
@ -118,14 +106,6 @@ 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.
|
||||
|
@ -196,16 +176,6 @@ internal class ProjectState
|
|||
|
||||
public ProjectState WithAddedHostDocument(HostDocument hostDocument, TextLoader loader)
|
||||
{
|
||||
if (hostDocument is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hostDocument));
|
||||
}
|
||||
|
||||
if (loader is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(loader));
|
||||
}
|
||||
|
||||
// Ignore attempts to 'add' a document with different data, we only
|
||||
// care about one, so it might as well be the one we have.
|
||||
if (Documents.ContainsKey(hostDocument.FilePath))
|
||||
|
@ -229,17 +199,12 @@ internal class ProjectState
|
|||
}
|
||||
}
|
||||
|
||||
var state = new ProjectState(this, ProjectDifference.DocumentAdded, HostProject, ProjectWorkspaceState, documents, importsToRelatedDocuments);
|
||||
var state = new ProjectState(this, numberOfDocumentsMayHaveChanged: true, HostProject, ProjectWorkspaceState, documents, importsToRelatedDocuments);
|
||||
return state;
|
||||
}
|
||||
|
||||
public ProjectState WithRemovedHostDocument(HostDocument hostDocument)
|
||||
{
|
||||
if (hostDocument is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hostDocument));
|
||||
}
|
||||
|
||||
if (!Documents.ContainsKey(hostDocument.FilePath))
|
||||
{
|
||||
return this;
|
||||
|
@ -261,17 +226,12 @@ internal class ProjectState
|
|||
var importTargetPaths = GetImportDocumentTargetPaths(hostDocument);
|
||||
var importsToRelatedDocuments = RemoveFromImportsToRelatedDocuments(ImportsToRelatedDocuments, hostDocument, importTargetPaths);
|
||||
|
||||
var state = new ProjectState(this, ProjectDifference.DocumentRemoved, HostProject, ProjectWorkspaceState, documents, importsToRelatedDocuments);
|
||||
var state = new ProjectState(this, numberOfDocumentsMayHaveChanged: true, HostProject, ProjectWorkspaceState, documents, importsToRelatedDocuments);
|
||||
return state;
|
||||
}
|
||||
|
||||
public ProjectState WithChangedHostDocument(HostDocument hostDocument, SourceText sourceText, VersionStamp textVersion)
|
||||
{
|
||||
if (hostDocument is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hostDocument));
|
||||
}
|
||||
|
||||
if (!Documents.TryGetValue(hostDocument.FilePath, out var document))
|
||||
{
|
||||
return this;
|
||||
|
@ -287,17 +247,12 @@ internal class ProjectState
|
|||
}
|
||||
}
|
||||
|
||||
var state = new ProjectState(this, ProjectDifference.DocumentChanged, HostProject, ProjectWorkspaceState, documents, ImportsToRelatedDocuments);
|
||||
var state = new ProjectState(this, numberOfDocumentsMayHaveChanged: false, HostProject, ProjectWorkspaceState, documents, ImportsToRelatedDocuments);
|
||||
return state;
|
||||
}
|
||||
|
||||
public ProjectState WithChangedHostDocument(HostDocument hostDocument, TextLoader loader)
|
||||
{
|
||||
if (hostDocument is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hostDocument));
|
||||
}
|
||||
|
||||
if (!Documents.TryGetValue(hostDocument.FilePath, out var document))
|
||||
{
|
||||
return this;
|
||||
|
@ -313,24 +268,20 @@ internal class ProjectState
|
|||
}
|
||||
}
|
||||
|
||||
var state = new ProjectState(this, ProjectDifference.DocumentChanged, HostProject, ProjectWorkspaceState, documents, ImportsToRelatedDocuments);
|
||||
var state = new ProjectState(this, numberOfDocumentsMayHaveChanged: false, HostProject, ProjectWorkspaceState, documents, ImportsToRelatedDocuments);
|
||||
return state;
|
||||
}
|
||||
|
||||
public ProjectState WithHostProject(HostProject hostProject)
|
||||
public ProjectState WithHostProjectAndWorkspaceState(HostProject hostProject, ProjectWorkspaceState projectWorkspaceState)
|
||||
{
|
||||
if (hostProject is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hostProject));
|
||||
}
|
||||
|
||||
if (HostProject.Configuration.Equals(hostProject.Configuration) &&
|
||||
HostProject.RootNamespace == hostProject.RootNamespace)
|
||||
HostProject.RootNamespace == hostProject.RootNamespace &&
|
||||
ProjectWorkspaceState.Equals(projectWorkspaceState))
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
var documents = Documents.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.WithConfigurationChange(), FilePathNormalizingComparer.Instance);
|
||||
var documents = Documents.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.WithProjectChange(), FilePathNormalizingComparer.Instance);
|
||||
|
||||
// If the host project has changed then we need to recompute the imports map
|
||||
var importsToRelatedDocuments = s_emptyImportsToRelatedDocuments;
|
||||
|
@ -341,25 +292,7 @@ internal class ProjectState
|
|||
importsToRelatedDocuments = AddToImportsToRelatedDocuments(importsToRelatedDocuments, document.Value.HostDocument.FilePath, importTargetPaths);
|
||||
}
|
||||
|
||||
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);
|
||||
var state = new ProjectState(this, numberOfDocumentsMayHaveChanged: true, hostProject, projectWorkspaceState, documents, importsToRelatedDocuments);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -372,7 +305,7 @@ internal class ProjectState
|
|||
{
|
||||
if (!importsToRelatedDocuments.TryGetValue(importTargetPath, out var relatedDocuments))
|
||||
{
|
||||
relatedDocuments = ImmutableArray.Create<string>();
|
||||
relatedDocuments = [];
|
||||
}
|
||||
|
||||
relatedDocuments = relatedDocuments.Add(documentFilePath);
|
||||
|
|
|
@ -30,6 +30,4 @@ internal record ProjectAddedAction(HostProject HostProject) : IUpdateProjectActi
|
|||
|
||||
internal record ProjectRemovedAction(ProjectKey ProjectKey) : IUpdateProjectAction;
|
||||
|
||||
internal record HostProjectUpdatedAction(HostProject HostProject) : IUpdateProjectAction;
|
||||
|
||||
internal record ProjectWorkspaceStateChangedAction(ProjectWorkspaceState WorkspaceState) : IUpdateProjectAction;
|
||||
internal record ProjectChangeAction(HostProject HostProject, ProjectWorkspaceState WorkspaceState) : IUpdateProjectAction;
|
||||
|
|
|
@ -85,7 +85,7 @@ internal class ProjectSnapshotSynchronizationService(
|
|||
|
||||
if (state.projectWorkspaceState != null)
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(state.hostProject.Key, state.projectWorkspaceState);
|
||||
updater.ProjectChanged(state.hostProject, state.projectWorkspaceState);
|
||||
}
|
||||
},
|
||||
state: (hostProject, projectWorkspaceState: args.Newer.ProjectWorkspaceState),
|
||||
|
@ -108,31 +108,16 @@ internal class ProjectSnapshotSynchronizationService(
|
|||
}
|
||||
else if (args.Kind == ProjectProxyChangeKind.ProjectChanged)
|
||||
{
|
||||
if (!args.Older!.Configuration.Equals(args.Newer!.Configuration))
|
||||
if (!args.Older!.Configuration.Equals(args.Newer!.Configuration) ||
|
||||
!args.Older.ProjectWorkspaceState.Equals(args.Newer.ProjectWorkspaceState))
|
||||
{
|
||||
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, 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),
|
||||
static (updater, state) => updater.ProjectChanged(state.hostProject, state.projectWorkspaceState),
|
||||
state: (hostProject, projectWorkspaceState),
|
||||
CancellationToken.None);
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +137,7 @@ internal class ProjectSnapshotSynchronizationService(
|
|||
|
||||
if (state.projectWorkspaceState is not null)
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(state.hostProject.Key, state.projectWorkspaceState);
|
||||
updater.ProjectChanged(state.hostProject, state.projectWorkspaceState);
|
||||
}
|
||||
},
|
||||
state: (hostProject, projectWorkspaceState: projectHandle.ProjectWorkspaceState),
|
||||
|
|
|
@ -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 _))
|
||||
if (!updater.TryGetLoadedProject(project.Key, out var current))
|
||||
{
|
||||
// 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.ProjectConfigurationChanged(project);
|
||||
updater.ProjectChanged(project, current.ProjectWorkspaceState);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,17 +157,18 @@ internal sealed partial class ProjectWorkspaceStateGenerator(
|
|||
.UpdateAsync(
|
||||
static (updater, state) =>
|
||||
{
|
||||
var (projectKey, workspaceState, logger, cancellationToken) = state;
|
||||
var (projectSnapshot, workspaceState, logger, cancellationToken) = state;
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogTrace($"Updating project with {workspaceState.TagHelpers.Length} tag helper(s) for '{projectKey}'");
|
||||
updater.ProjectWorkspaceStateChanged(projectKey, workspaceState);
|
||||
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);
|
||||
},
|
||||
state: (projectKey, workspaceState, _logger, cancellationToken),
|
||||
state: (projectSnapshot, workspaceState, _logger, cancellationToken),
|
||||
cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ public class CodeDocumentReferenceHolderTest(ITestOutputHelper testOutput) : Lan
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectConfigurationChanged(s_hostProject with { Configuration = RazorConfiguration.Default, RootNamespace = "NewRootNamespace" });
|
||||
updater.ProjectChanged(s_hostProject with { Configuration = RazorConfiguration.Default, RootNamespace = "NewRootNamespace" }, documentSnapshot.Project.ProjectWorkspaceState);
|
||||
});
|
||||
|
||||
PerformFullGC();
|
||||
|
|
|
@ -46,7 +46,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
|
|||
|
||||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Create([builder.Build()]));
|
||||
updater.ProjectChanged(hostProject, ProjectWorkspaceState.Create([builder.Build()]));
|
||||
});
|
||||
|
||||
var uri = new Uri(hostDocument1.FilePath);
|
||||
|
@ -106,7 +106,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
|
|||
|
||||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Create([builder.Build()]));
|
||||
updater.ProjectChanged(hostProject, ProjectWorkspaceState.Create([builder.Build()]));
|
||||
});
|
||||
|
||||
var uri = new Uri(hostDocument1.FilePath);
|
||||
|
@ -177,7 +177,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
|
|||
|
||||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Create([builder.Build()]));
|
||||
updater.ProjectChanged(hostProject, ProjectWorkspaceState.Create([builder.Build()]));
|
||||
});
|
||||
|
||||
var uri = new Uri(hostDocument1.FilePath);
|
||||
|
@ -332,7 +332,7 @@ public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutp
|
|||
|
||||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Create([builder.Build()]));
|
||||
updater.ProjectChanged(hostProject, ProjectWorkspaceState.Create([builder.Build()]));
|
||||
});
|
||||
|
||||
var uri = new Uri(hostDocument1.FilePath);
|
||||
|
|
|
@ -142,8 +142,7 @@ public class OpenDocumentGeneratorTest(ITestOutputHelper testOutput) : LanguageS
|
|||
updater.DocumentAdded(_hostProject1.Key, _documents[0], _documents[0].CreateEmptyTextLoader());
|
||||
|
||||
// Act
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject1.Key,
|
||||
ProjectWorkspaceState.Create(LanguageVersion.CSharp8));
|
||||
updater.ProjectChanged(_hostProject1, ProjectWorkspaceState.Create(LanguageVersion.CSharp8));
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -166,8 +165,7 @@ public class OpenDocumentGeneratorTest(ITestOutputHelper testOutput) : LanguageS
|
|||
updater.DocumentOpened(_hostProject1.Key, _documents[0].FilePath, SourceText.From(string.Empty));
|
||||
|
||||
// Act
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject1.Key,
|
||||
ProjectWorkspaceState.Create(LanguageVersion.CSharp8));
|
||||
updater.ProjectChanged(_hostProject1, ProjectWorkspaceState.Create(LanguageVersion.CSharp8));
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
|
|
@ -656,10 +656,11 @@ 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.ProjectWorkspaceStateChanged(projectKey1, ProjectWorkspaceState.Create(tagHelpers));
|
||||
updater.ProjectChanged(hostProject1, ProjectWorkspaceState.Create(tagHelpers));
|
||||
});
|
||||
|
||||
await projectService.AddDocumentToPotentialProjectsAsync(s_componentFilePath1, DisposalToken);
|
||||
|
@ -678,10 +679,11 @@ 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.ProjectWorkspaceStateChanged(projectKey2, ProjectWorkspaceState.Create(tagHelpers));
|
||||
updater.ProjectChanged(hostProject2, ProjectWorkspaceState.Create(tagHelpers));
|
||||
});
|
||||
|
||||
await projectService.AddDocumentToPotentialProjectsAsync(s_componentFilePath3, DisposalToken);
|
||||
|
|
|
@ -63,14 +63,14 @@ public class DocumentStateTest : ToolingTestBase
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void DocumentState_WithConfigurationChange_CachesSnapshotText()
|
||||
public void DocumentState_WithProjectChange_CachesSnapshotText()
|
||||
{
|
||||
// Arrange
|
||||
var original = DocumentState.Create(_hostDocument, DocumentState.EmptyLoader)
|
||||
.WithText(_text, VersionStamp.Create());
|
||||
|
||||
// Act
|
||||
var state = original.WithConfigurationChange();
|
||||
var state = original.WithProjectChange();
|
||||
|
||||
// Assert
|
||||
Assert.True(state.TryGetText(out _));
|
||||
|
@ -78,7 +78,7 @@ public class DocumentStateTest : ToolingTestBase
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DocumentState_WithConfigurationChange_CachesLoadedText()
|
||||
public async Task DocumentState_WithProjectChange_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.WithConfigurationChange();
|
||||
var state = original.WithProjectChange();
|
||||
|
||||
// Assert
|
||||
Assert.True(state.TryGetText(out _));
|
||||
|
@ -125,36 +125,4 @@ 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 _));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ public class ProjectStateGeneratedOutputTest : WorkspaceTestBase
|
|||
var changed = ProjectWorkspaceState.Default;
|
||||
|
||||
// Act
|
||||
var state = original.WithProjectWorkspaceState(changed);
|
||||
var state = original.WithHostProjectAndWorkspaceState(original.HostProject, 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.WithProjectWorkspaceState(changed);
|
||||
var state = original.WithHostProjectAndWorkspaceState(original.HostProject, 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.WithProjectWorkspaceState(changedWorkspaceState);
|
||||
var state = original.WithHostProjectAndWorkspaceState(original.HostProject, 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.WithHostProject(_hostProjectWithConfigurationChange);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProjectWithConfigurationChange, original.ProjectWorkspaceState);
|
||||
|
||||
// Assert
|
||||
var (actualOutput, actualInputVersion) = await GetOutputAsync(state, _hostDocument, DisposalToken);
|
||||
|
|
|
@ -529,7 +529,7 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithHostProject_ConfigurationChange_UpdatesConfigurationState()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_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.WithHostProject(_hostProjectWithConfigurationChange);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProjectWithConfigurationChange, _projectWorkspaceState);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(original.Version, state.Version);
|
||||
|
@ -567,7 +567,7 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithHostProject_RootNamespaceChange_UpdatesConfigurationState()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_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.WithHostProject(hostProjectWithRootNamespaceChange);
|
||||
var state = original.WithHostProjectAndWorkspaceState(hostProjectWithRootNamespaceChange, _projectWorkspaceState);
|
||||
|
||||
// Assert
|
||||
Assert.NotSame(original, state);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithHostProject_NoConfigurationChange_Noops()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_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.WithHostProject(_hostProject);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProject, _projectWorkspaceState);
|
||||
|
||||
// Assert
|
||||
Assert.Same(original, state);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithHostProject_CallsConfigurationChangeOnDocumentState()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_CallsConfigurationChangeOnDocumentState()
|
||||
{
|
||||
// Arrange
|
||||
var callCount = 0;
|
||||
|
@ -618,7 +618,7 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
original.Documents = documents.ToImmutable();
|
||||
|
||||
// Act
|
||||
var state = original.WithHostProject(_hostProjectWithConfigurationChange);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProjectWithConfigurationChange, _projectWorkspaceState);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(original.Version, state.Version);
|
||||
|
@ -627,14 +627,14 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithHostProject_ResetsImportedDocuments()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_ResetsImportedDocuments()
|
||||
{
|
||||
// Arrange
|
||||
var original = ProjectState.Create(ProjectEngineFactoryProvider, LanguageServerFeatureOptions, _hostProject, _projectWorkspaceState);
|
||||
original = original.WithAddedHostDocument(TestProjectData.SomeProjectFile1, DocumentState.EmptyLoader);
|
||||
|
||||
// Act
|
||||
var state = original.WithHostProject(_hostProjectWithConfigurationChange);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProjectWithConfigurationChange, _projectWorkspaceState);
|
||||
|
||||
// Assert
|
||||
var importMap = Assert.Single(state.ImportsToRelatedDocuments);
|
||||
|
@ -643,7 +643,7 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithProjectWorkspaceState_Changed()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_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.WithProjectWorkspaceState(changed);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProject, changed);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(original.Version, state.Version);
|
||||
|
@ -682,7 +682,7 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithProjectWorkspaceState_Changed_TagHelpersChanged()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_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.WithProjectWorkspaceState(changed);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProject, changed);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(original.Version, state.Version);
|
||||
|
@ -716,7 +716,7 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithProjectWorkspaceState_IdenticalState_Caches()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_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.WithProjectWorkspaceState(changed);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProject, changed);
|
||||
|
||||
// Assert
|
||||
Assert.Same(original, state);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProjectState_WithProjectWorkspaceState_CallsWorkspaceProjectChangeOnDocumentState()
|
||||
public void ProjectState_WithHostProjectAndWorkspaceState_CallsWorkspaceProjectChangeOnDocumentState()
|
||||
{
|
||||
// Arrange
|
||||
var callCount = 0;
|
||||
|
||||
var documents = ImmutableDictionary.CreateBuilder<string, DocumentState>(FilePathComparer.Instance);
|
||||
documents[_documents[1].FilePath] = TestDocumentState.Create(_documents[1], onProjectWorkspaceStateChange: () => callCount++);
|
||||
documents[_documents[2].FilePath] = TestDocumentState.Create(_documents[2], onProjectWorkspaceStateChange: () => callCount++);
|
||||
documents[_documents[1].FilePath] = TestDocumentState.Create(_documents[1], onConfigurationChange: () => callCount++);
|
||||
documents[_documents[2].FilePath] = TestDocumentState.Create(_documents[2], onConfigurationChange: () => 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.WithProjectWorkspaceState(changed);
|
||||
var state = original.WithHostProjectAndWorkspaceState(_hostProject, changed);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(original.Version, state.Version);
|
||||
|
@ -991,8 +991,7 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
Action? onTextChange = null,
|
||||
Action? onTextLoaderChange = null,
|
||||
Action? onConfigurationChange = null,
|
||||
Action? onImportsChange = null,
|
||||
Action? onProjectWorkspaceStateChange = null)
|
||||
Action? onImportsChange = null)
|
||||
{
|
||||
return new TestDocumentState(
|
||||
hostDocument,
|
||||
|
@ -1000,15 +999,13 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
onTextChange,
|
||||
onTextLoaderChange,
|
||||
onConfigurationChange,
|
||||
onImportsChange,
|
||||
onProjectWorkspaceStateChange);
|
||||
onImportsChange);
|
||||
}
|
||||
|
||||
private readonly Action? _onTextChange;
|
||||
private readonly Action? _onTextLoaderChange;
|
||||
private readonly Action? _onConfigurationChange;
|
||||
private readonly Action? _onImportsChange;
|
||||
private readonly Action? _onProjectWorkspaceStateChange;
|
||||
|
||||
private TestDocumentState(
|
||||
HostDocument hostDocument,
|
||||
|
@ -1016,15 +1013,13 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
Action? onTextChange,
|
||||
Action? onTextLoaderChange,
|
||||
Action? onConfigurationChange,
|
||||
Action? onImportsChange,
|
||||
Action? onProjectWorkspaceStateChange)
|
||||
Action? onImportsChange)
|
||||
: base(hostDocument, version: 1, loader ?? EmptyLoader)
|
||||
{
|
||||
_onTextChange = onTextChange;
|
||||
_onTextLoaderChange = onTextLoaderChange;
|
||||
_onConfigurationChange = onConfigurationChange;
|
||||
_onImportsChange = onImportsChange;
|
||||
_onProjectWorkspaceStateChange = onProjectWorkspaceStateChange;
|
||||
}
|
||||
|
||||
public override DocumentState WithText(SourceText sourceText, VersionStamp textVersion)
|
||||
|
@ -1039,10 +1034,10 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
return base.WithTextLoader(loader);
|
||||
}
|
||||
|
||||
public override DocumentState WithConfigurationChange()
|
||||
public override DocumentState WithProjectChange()
|
||||
{
|
||||
_onConfigurationChange?.Invoke();
|
||||
return base.WithConfigurationChange();
|
||||
return base.WithProjectChange();
|
||||
}
|
||||
|
||||
public override DocumentState WithImportsChange()
|
||||
|
@ -1050,11 +1045,5 @@ public class ProjectStateTest : WorkspaceTestBase
|
|||
_onImportsChange?.Invoke();
|
||||
return base.WithImportsChange();
|
||||
}
|
||||
|
||||
public override DocumentState WithProjectWorkspaceStateChange()
|
||||
{
|
||||
_onProjectWorkspaceStateChange?.Invoke();
|
||||
return base.WithProjectWorkspaceStateChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class ProjectAvailabilityTests(ITestOutputHelper testOutput) : ToolingTes
|
|||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(hostProject);
|
||||
updater.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState);
|
||||
updater.ProjectChanged(hostProject, 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.ProjectWorkspaceStateChanged(hostProject1.Key, projectWorkspaceState);
|
||||
updater.ProjectChanged(hostProject1, projectWorkspaceState);
|
||||
updater.DocumentAdded(hostProject1.Key, hostDocument, TestMocks.CreateTextLoader(hostDocument.FilePath, text: ""));
|
||||
|
||||
updater.ProjectAdded(hostProject2);
|
||||
updater.ProjectWorkspaceStateChanged(hostProject2.Key, projectWorkspaceState);
|
||||
updater.ProjectChanged(hostProject2, 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.ProjectWorkspaceStateChanged(hostProject1.Key, projectWorkspaceState);
|
||||
updater.ProjectChanged(hostProject1, projectWorkspaceState);
|
||||
updater.DocumentAdded(hostProject1.Key, hostDocument, TestMocks.CreateTextLoader(hostDocument.FilePath, text: ""));
|
||||
|
||||
updater.ProjectAdded(hostProject2);
|
||||
|
|
|
@ -170,7 +170,7 @@ public class ProjectSnapshotSynchronizationServiceTest : VisualStudioWorkspaceTe
|
|||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(hostProject);
|
||||
updater.ProjectConfigurationChanged(hostProject);
|
||||
updater.ProjectChanged(hostProject, newHandle.ProjectWorkspaceState);
|
||||
});
|
||||
|
||||
var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged);
|
||||
|
@ -214,7 +214,7 @@ public class ProjectSnapshotSynchronizationServiceTest : VisualStudioWorkspaceTe
|
|||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(hostProject);
|
||||
updater.ProjectWorkspaceStateChanged(hostProject.Key, oldHandle.ProjectWorkspaceState);
|
||||
updater.ProjectChanged(hostProject, oldHandle.ProjectWorkspaceState);
|
||||
});
|
||||
|
||||
var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged);
|
||||
|
|
|
@ -44,10 +44,10 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis
|
|||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(_hostProject1);
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1);
|
||||
updater.ProjectChanged(_hostProject1, _projectWorkspaceState1);
|
||||
|
||||
updater.ProjectAdded(_hostProject2);
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject2.Key, _projectWorkspaceState2);
|
||||
updater.ProjectChanged(_hostProject2, _projectWorkspaceState2);
|
||||
});
|
||||
|
||||
using var proxy = new ProjectSnapshotManagerProxy(
|
||||
|
@ -77,7 +77,7 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis
|
|||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(_hostProject1);
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1);
|
||||
updater.ProjectChanged(_hostProject1, _projectWorkspaceState1);
|
||||
});
|
||||
|
||||
using var proxy = new ProjectSnapshotManagerProxy(
|
||||
|
@ -102,12 +102,13 @@ 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.ProjectConfigurationChanged(new(
|
||||
updater.ProjectChanged(new(
|
||||
project.FilePath,
|
||||
project.IntermediateOutputPath,
|
||||
FallbackRazorConfiguration.MVC_1_0,
|
||||
project.RootNamespace,
|
||||
project.DisplayName));
|
||||
project.DisplayName),
|
||||
_projectWorkspaceState1);
|
||||
});
|
||||
|
||||
await proxyAccessor.ProcessingChangedEventTestTask.AssumeNotNull().JoinAsync();
|
||||
|
@ -125,7 +126,7 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis
|
|||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(_hostProject1);
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1);
|
||||
updater.ProjectChanged(_hostProject1, _projectWorkspaceState1);
|
||||
});
|
||||
|
||||
var proxy = new ProjectSnapshotManagerProxy(
|
||||
|
@ -143,12 +144,13 @@ 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.ProjectConfigurationChanged(new(
|
||||
updater.ProjectChanged(new(
|
||||
project.FilePath,
|
||||
project.IntermediateOutputPath,
|
||||
FallbackRazorConfiguration.MVC_1_0,
|
||||
project.RootNamespace,
|
||||
project.DisplayName));
|
||||
project.DisplayName),
|
||||
_projectWorkspaceState1);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -164,7 +166,7 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis
|
|||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(_hostProject1);
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1);
|
||||
updater.ProjectChanged(_hostProject1, _projectWorkspaceState1);
|
||||
});
|
||||
|
||||
using var proxy = new ProjectSnapshotManagerProxy(
|
||||
|
@ -196,10 +198,10 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis
|
|||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(_hostProject1);
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1);
|
||||
updater.ProjectChanged(_hostProject1, _projectWorkspaceState1);
|
||||
|
||||
updater.ProjectAdded(_hostProject2);
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject2.Key, _projectWorkspaceState2);
|
||||
updater.ProjectChanged(_hostProject2, _projectWorkspaceState2);
|
||||
});
|
||||
|
||||
using var proxy = new ProjectSnapshotManagerProxy(
|
||||
|
@ -229,7 +231,7 @@ public class ProjectSnapshotManagerProxyTest(ITestOutputHelper testOutput) : Vis
|
|||
await projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(_hostProject1);
|
||||
updater.ProjectWorkspaceStateChanged(_hostProject1.Key, _projectWorkspaceState1);
|
||||
updater.ProjectChanged(_hostProject1, _projectWorkspaceState1);
|
||||
});
|
||||
|
||||
using var proxy = new ProjectSnapshotManagerProxy(
|
||||
|
|
|
@ -5,6 +5,7 @@ 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;
|
||||
|
@ -142,7 +143,7 @@ public class FallbackProjectManagerTest : VisualStudioWorkspaceTestBase
|
|||
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectConfigurationChanged(hostProject);
|
||||
updater.ProjectChanged(hostProject, ProjectWorkspaceState.Default);
|
||||
});
|
||||
|
||||
project = Assert.Single(_projectManager.GetProjects());
|
||||
|
|
|
@ -268,7 +268,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(s_hostProject);
|
||||
updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers);
|
||||
updater.ProjectChanged(s_hostProject, _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.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers);
|
||||
updater.ProjectChanged(s_hostProject, _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.ProjectConfigurationChanged(s_hostProjectWithConfigurationChange);
|
||||
updater.ProjectChanged(s_hostProjectWithConfigurationChange, ProjectWorkspaceState.Default);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -655,7 +655,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(s_hostProject);
|
||||
updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers);
|
||||
updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers);
|
||||
});
|
||||
|
||||
using var listener = _projectManager.ListenToNotifications();
|
||||
|
@ -663,7 +663,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectConfigurationChanged(s_hostProjectWithConfigurationChange);
|
||||
updater.ProjectChanged(s_hostProjectWithConfigurationChange, _projectWorkspaceStateWithTagHelpers);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -686,7 +686,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectConfigurationChanged(s_hostProjectWithConfigurationChange);
|
||||
updater.ProjectChanged(s_hostProjectWithConfigurationChange, ProjectWorkspaceState.Default);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -703,7 +703,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectConfigurationChanged(s_hostProject);
|
||||
updater.ProjectChanged(s_hostProject, ProjectWorkspaceState.Default);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -745,7 +745,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers);
|
||||
updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -767,7 +767,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers);
|
||||
updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -791,7 +791,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers);
|
||||
updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
@ -806,7 +806,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(s_hostProject);
|
||||
updater.ProjectWorkspaceStateChanged(s_hostProject.Key, ProjectWorkspaceState.Default);
|
||||
updater.ProjectChanged(s_hostProject, ProjectWorkspaceState.Default);
|
||||
});
|
||||
|
||||
using var listener = _projectManager.ListenToNotifications();
|
||||
|
@ -814,7 +814,7 @@ public class ProjectSnapshotManagerTest : VisualStudioWorkspaceTestBase
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectWorkspaceStateChanged(s_hostProject.Key, _projectWorkspaceStateWithTagHelpers);
|
||||
updater.ProjectChanged(s_hostProject, _projectWorkspaceStateWithTagHelpers);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
|
|
@ -120,7 +120,7 @@ public class ProjectWorkspaceStateGeneratorTest : VisualStudioWorkspaceTestBase
|
|||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectAdded(_projectSnapshot.HostProject);
|
||||
updater.ProjectWorkspaceStateChanged(_projectSnapshot.Key, _projectWorkspaceStateWithTagHelpers);
|
||||
updater.ProjectChanged(_projectSnapshot.HostProject, _projectWorkspaceStateWithTagHelpers);
|
||||
});
|
||||
|
||||
// Act
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
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;
|
||||
|
@ -470,7 +471,7 @@ public class VisualStudioDocumentTrackerTest : VisualStudioWorkspaceTestBase
|
|||
// Act
|
||||
await _projectManager.UpdateAsync(updater =>
|
||||
{
|
||||
updater.ProjectConfigurationChanged(_updatedHostProject);
|
||||
updater.ProjectChanged(_updatedHostProject, ProjectWorkspaceState.Default);
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
|
Загрузка…
Ссылка в новой задаче