Skip to content

Commit 70179b3

Browse files
committed
Remove hashset for fallback projects
Realised that this was unnecessary with recent changes
1 parent 05a6f62 commit 70179b3

File tree

3 files changed

+16
-41
lines changed

3 files changed

+16
-41
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultRazorDynamicFileInfoProvider.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,13 @@ public Task RemoveDynamicFileInfoAsync(ProjectId projectId, string? projectFileP
270270
throw new ArgumentNullException(nameof(filePath));
271271
}
272272

273-
_fallbackProjectManager.DynamicFileRemoved(projectId, projectFilePath, filePath);
273+
var projectKey = TryFindProjectKeyForProjectId(projectId);
274+
if (projectKey is not { } razorProjectKey)
275+
{
276+
return Task.CompletedTask;
277+
}
278+
279+
_fallbackProjectManager.DynamicFileRemoved(projectId, razorProjectKey, projectFilePath, filePath);
274280

275281
// ---------------------------------------------------------- NOTE & CAUTION --------------------------------------------------------------
276282
//

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/FallbackProjectManager.cs

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Immutable;
65
using System.Composition;
76
using System.IO;
87
using Microsoft.AspNetCore.Razor.Telemetry;
@@ -30,23 +29,16 @@ internal sealed class FallbackProjectManager(
3029
private readonly ProjectSnapshotManagerAccessor _projectSnapshotManagerAccessor = projectSnapshotManagerAccessor;
3130
private readonly ITelemetryReporter _telemetryReporter = telemetryReporter;
3231

33-
private ImmutableHashSet<ProjectId> _fallbackProjectIds = ImmutableHashSet<ProjectId>.Empty;
34-
3532
internal void DynamicFileAdded(ProjectId projectId, ProjectKey razorProjectKey, string projectFilePath, string filePath)
3633
{
3734
try
3835
{
3936
var project = _projectSnapshotManagerAccessor.Instance.GetLoadedProject(razorProjectKey);
40-
if (_fallbackProjectIds.Contains(projectId))
37+
if (project is ProjectSnapshot { HostProject: FallbackHostProject })
4138
{
42-
// The project might have started as a fallback project, but it might have been upgraded by our getting CPS info
43-
// about it. In that case, leave the CPS bits to do the work
44-
if (project is ProjectSnapshot { HostProject: FallbackHostProject })
45-
{
46-
// If this is a fallback project, then Roslyn may not track documents in the project, so these dynamic file notifications
47-
// are the only way to know about files in the project.
48-
AddFallbackDocument(razorProjectKey, filePath, projectFilePath);
49-
}
39+
// If this is a fallback project, then Roslyn may not track documents in the project, so these dynamic file notifications
40+
// are the only way to know about files in the project.
41+
AddFallbackDocument(razorProjectKey, filePath, projectFilePath);
5042
}
5143
else if (project is null)
5244
{
@@ -62,11 +54,12 @@ internal void DynamicFileAdded(ProjectId projectId, ProjectKey razorProjectKey,
6254
}
6355
}
6456

65-
internal void DynamicFileRemoved(ProjectId projectId, string projectFilePath, string filePath)
57+
internal void DynamicFileRemoved(ProjectId projectId, ProjectKey razorProjectKey, string projectFilePath, string filePath)
6658
{
6759
try
6860
{
69-
if (_fallbackProjectIds.Contains(projectId))
61+
var project = _projectSnapshotManagerAccessor.Instance.GetLoadedProject(razorProjectKey);
62+
if (project is ProjectSnapshot { HostProject: FallbackHostProject })
7063
{
7164
// If this is a fallback project, then Roslyn may not track documents in the project, so these dynamic file notifications
7265
// are the only way to know about files in the project.
@@ -93,11 +86,6 @@ private void AddFallbackProject(ProjectId projectId, string filePath)
9386
return;
9487
}
9588

96-
if (!ImmutableInterlocked.Update(ref _fallbackProjectIds, (set, id) => set.Add(id), project.Id))
97-
{
98-
return;
99-
}
100-
10189
var rootNamespace = project.DefaultNamespace;
10290

10391
// We create this as a fallback project so that other parts of the system can reason about them - eg we don't do code
@@ -182,21 +170,4 @@ private void RemoveFallbackDocument(ProjectId projectId, string filePath, string
182170

183171
return project;
184172
}
185-
186-
internal TestAccessor GetTestAccessor()
187-
{
188-
return new TestAccessor(this);
189-
}
190-
191-
internal readonly struct TestAccessor
192-
{
193-
private readonly FallbackProjectManager _instance;
194-
195-
internal TestAccessor(FallbackProjectManager instance)
196-
{
197-
_instance = instance;
198-
}
199-
200-
internal ImmutableHashSet<ProjectId> ProjectIds => _instance._fallbackProjectIds;
201-
}
202173
}

src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/FallbackProjectManagerTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public void DynamicFileAdded_KnownProject_DoesNothing()
4848

4949
_fallbackProjectManger.DynamicFileAdded(projectId, hostProject.Key, SomeProject.FilePath, SomeProjectFile1.FilePath);
5050

51-
Assert.Empty(_fallbackProjectManger.GetTestAccessor().ProjectIds);
51+
var project = Assert.Single(_projectSnapshotManager.GetProjects());
52+
Assert.IsNotType<FallbackHostProject>(((ProjectSnapshot)project).HostProject);
5253
}
5354

5455
[Fact]
@@ -63,9 +64,6 @@ public void DynamicFileAdded_UnknownProject_Adds()
6364

6465
_fallbackProjectManger.DynamicFileAdded(projectId, SomeProject.Key, SomeProject.FilePath, SomeProjectFile1.FilePath);
6566

66-
var actualId = Assert.Single(_fallbackProjectManger.GetTestAccessor().ProjectIds);
67-
Assert.Equal(projectId, actualId);
68-
6967
var project = Assert.Single(_projectSnapshotManager.GetProjects());
7068
Assert.Equal("DisplayName", project.DisplayName);
7169
Assert.Equal("RootNamespace", project.RootNamespace);

0 commit comments

Comments
 (0)