Skip to content

Commit 700d939

Browse files
Change IFallbackProjectManager.IsFallbackProject to take a ProjectKey
Update IFallbackProjectManager.IsFallbackProject(...) to take a ProjectKey rather than a ProjectSnapshot. In addition, this commit includes a couple of changes to reorder some checks to avoid creating a ProjectSnapshot if it's not a fallback project.
1 parent da6d4c2 commit 700d939

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Documents/EditorDocumentManagerListener.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ private Task Document_OpenedAsync(object sender, CancellationToken cancellationT
247247
{
248248
var (document, fallbackProjectManager, telemetryReporter, cancellationToken) = state;
249249

250-
if (updater.TryGetProject(document.ProjectKey, out var project) &&
251-
fallbackProjectManager.IsFallbackProject(project))
250+
if (fallbackProjectManager.IsFallbackProject(document.ProjectKey) &&
251+
updater.TryGetProject(document.ProjectKey, out var project))
252252
{
253253
// The user is opening a document that is part of a fallback project. This is a scenario we are very interested in knowing more about
254254
// so fire some telemetry. We can't log details about the project, for PII reasons, but we can use document count and tag helper count

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/BackgroundDocumentGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public virtual void Enqueue(ProjectSnapshot project, DocumentSnapshot document)
9696
return;
9797
}
9898

99-
if (_fallbackProjectManager.IsFallbackProject(project))
99+
if (_fallbackProjectManager.IsFallbackProject(project.Key))
100100
{
101101
// We don't support closed file code generation for fallback projects
102102
return;

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/FallbackProjectManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ private void ProjectManager_Changed(object sender, ProjectChangeEventArgs e)
7070
}
7171
}
7272

73-
public bool IsFallbackProject(ProjectSnapshot project)
74-
=> _fallbackProjects.Contains(project.Key);
73+
public bool IsFallbackProject(ProjectKey projectKey)
74+
=> _fallbackProjects.Contains(projectKey);
7575

7676
internal void DynamicFileAdded(
7777
ProjectId projectId,
@@ -84,7 +84,7 @@ internal void DynamicFileAdded(
8484
{
8585
if (_projectManager.TryGetProject(razorProjectKey, out var project))
8686
{
87-
if (IsFallbackProject(project))
87+
if (IsFallbackProject(razorProjectKey))
8888
{
8989
// If this is a fallback project, then Roslyn may not track documents in the project, so these dynamic file notifications
9090
// are the only way to know about files in the project.
@@ -114,8 +114,8 @@ internal void DynamicFileRemoved(
114114
{
115115
try
116116
{
117-
if (_projectManager.TryGetProject(razorProjectKey, out var project) &&
118-
IsFallbackProject(project))
117+
if (IsFallbackProject(razorProjectKey) &&
118+
_projectManager.TryGetProject(razorProjectKey, out var project))
119119
{
120120
// If this is a fallback project, then Roslyn may not track documents in the project, so these dynamic file notifications
121121
// are the only way to know about files in the project.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

4-
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
4+
using Microsoft.AspNetCore.Razor.ProjectSystem;
55

66
namespace Microsoft.VisualStudio.Razor.ProjectSystem;
77

88
internal interface IFallbackProjectManager
99
{
10-
bool IsFallbackProject(ProjectSnapshot project);
10+
bool IsFallbackProject(ProjectKey projectKey);
1111
}

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DocumentGenerator/BackgroundDocumentGeneratorTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class BackgroundDocumentGeneratorTest(ITestOutputHelper testOutput) : Vis
3434
private static readonly HostProject s_hostProject2 = TestProjectData.AnotherProject with { Configuration = FallbackRazorConfiguration.MVC_1_0 };
3535

3636
private static IFallbackProjectManager s_fallbackProjectManager = StrictMock.Of<IFallbackProjectManager>(x =>
37-
x.IsFallbackProject(It.IsAny<ProjectSnapshot>()) == false);
37+
x.IsFallbackProject(It.IsAny<ProjectKey>()) == false);
3838

3939
private readonly TestDynamicFileInfoProvider _dynamicFileInfoProvider = new();
4040

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Documents/EditorDocumentManagerListenerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class EditorDocumentManagerListenerTest(ITestOutputHelper testOutput) : V
3232
targetPath: "/path/to/file1.razor");
3333

3434
private static IFallbackProjectManager s_fallbackProjectManager = StrictMock.Of<IFallbackProjectManager>(x =>
35-
x.IsFallbackProject(It.IsAny<ProjectSnapshot>()) == false);
35+
x.IsFallbackProject(It.IsAny<ProjectKey>()) == false);
3636

3737
[UIFact]
3838
public async Task ProjectManager_Changed_RemoveDocument_RemovesDocument()

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/FallbackProjectManagerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ await _projectManager.UpdateAsync(updater =>
7575
await WaitForProjectManagerUpdatesAsync();
7676

7777
var project = Assert.Single(_projectManager.GetProjects());
78-
Assert.False(_fallbackProjectManger.IsFallbackProject(project));
78+
Assert.False(_fallbackProjectManger.IsFallbackProject(project.Key));
7979
}
8080

8181
[UIFact]
@@ -102,7 +102,7 @@ public async Task DynamicFileAdded_UnknownProject_Adds()
102102
Assert.Equal("DisplayName", project.DisplayName);
103103
Assert.Equal("RootNamespace", project.RootNamespace);
104104

105-
Assert.True(_fallbackProjectManger.IsFallbackProject(project));
105+
Assert.True(_fallbackProjectManger.IsFallbackProject(project.Key));
106106

107107
var documentFilePath = Assert.Single(project.DocumentFilePaths);
108108
Assert.Equal(SomeProjectFile1.FilePath, documentFilePath);
@@ -130,7 +130,7 @@ public async Task DynamicFileAdded_UnknownToKnownProject_NotFallbackHostProject(
130130
await WaitForProjectManagerUpdatesAsync();
131131

132132
var project = Assert.Single(_projectManager.GetProjects());
133-
Assert.True(_fallbackProjectManger.IsFallbackProject(project));
133+
Assert.True(_fallbackProjectManger.IsFallbackProject(project.Key));
134134

135135
var hostProject = SomeProject with
136136
{
@@ -144,7 +144,7 @@ await _projectManager.UpdateAsync(updater =>
144144
});
145145

146146
project = Assert.Single(_projectManager.GetProjects());
147-
Assert.False(_fallbackProjectManger.IsFallbackProject(project));
147+
Assert.False(_fallbackProjectManger.IsFallbackProject(project.Key));
148148
}
149149

150150
[UIFact]

0 commit comments

Comments
 (0)