Skip to content

Commit d98785e

Browse files
authored
Merge release/dev17.8 to release/dev17.9 (#9510)
2 parents 50409b0 + 64b0c3f commit d98785e

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public DefaultRazorDynamicFileInfoProvider(
4343
_lspEditorFeatureDetector = lspEditorFeatureDetector ?? throw new ArgumentNullException(nameof(lspEditorFeatureDetector));
4444
_filePathService = filePathService ?? throw new ArgumentNullException(nameof(filePathService));
4545
_projectSnapshotManagerAccessor = projectSnapshotManagerAccessor ?? throw new ArgumentNullException(nameof(projectSnapshotManagerAccessor));
46-
_fallbackProjectManager = fallbackProjectManager;
46+
_fallbackProjectManager = fallbackProjectManager ?? throw new ArgumentNullException(nameof(fallbackProjectManager));
4747
_entries = new ConcurrentDictionary<Key, Entry>();
4848
_createEmptyEntry = (key) => new Entry(CreateEmptyInfo(key));
4949
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT license. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Razor.Language;
5+
6+
namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;
7+
8+
internal class FallbackHostProject : HostProject
9+
{
10+
public FallbackHostProject(string projectFilePath, string intermediateOutputPath, RazorConfiguration razorConfiguration, string rootNamespace, string displayName)
11+
: base(projectFilePath, intermediateOutputPath, razorConfiguration, rootNamespace, displayName)
12+
{
13+
}
14+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ private void AddFallbackProject(ProjectId projectId, string filePath)
8282
}
8383

8484
var rootNamespace = project.DefaultNamespace ?? "ASP";
85-
var hostProject = new HostProject(project.FilePath, intermediateOutputPath, FallbackRazorConfiguration.Latest, rootNamespace, project.Name);
85+
86+
// We create this as a fallback project so that other parts of the system can reason about them - eg we don't do code
87+
// generation for closed files for documents in these projects. If these projects become "real", either because capabilities
88+
// change or simply a timing difference between Roslyn and our CPS components, the HostProject instance associated with
89+
// the project will be updated, and it will no longer be a fallback project.
90+
var hostProject = new FallbackHostProject(project.FilePath, intermediateOutputPath, FallbackRazorConfiguration.Latest, rootNamespace, project.Name);
8691

8792
_projectSnapshotManagerAccessor.Instance.ProjectAdded(hostProject);
8893

src/Razor/src/Microsoft.VisualStudio.Editor.Razor/BackgroundDocumentGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ public void Enqueue(IProjectSnapshot project, IDocumentSnapshot document)
134134
throw new ArgumentNullException(nameof(document));
135135
}
136136

137+
if (project is ProjectSnapshot { HostProject: FallbackHostProject })
138+
{
139+
// We don't support closed file code generation for fallback projects
140+
return;
141+
}
142+
137143
_dispatcher.AssertDispatcherThread();
138144

139145
lock (Work)

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,34 @@ public void DynamicFileAdded_UnknownProject_Adds()
6868
Assert.Equal("DisplayName", project.DisplayName);
6969
Assert.Equal("RootNamespace", project.RootNamespace);
7070

71+
Assert.IsType<FallbackHostProject>(((ProjectSnapshot)project).HostProject);
72+
7173
var documentFilePath = Assert.Single(project.DocumentFilePaths);
7274
Assert.Equal(SomeProjectFile1.FilePath, documentFilePath);
7375
}
7476

77+
[Fact]
78+
public void DynamicFileAdded_UnknownToKnownProject_NotFallbackHostProject()
79+
{
80+
var projectId = ProjectId.CreateNewId();
81+
var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Default, "DisplayName", "AssemblyName", LanguageNames.CSharp, filePath: SomeProject.FilePath)
82+
.WithCompilationOutputInfo(new CompilationOutputInfo().WithAssemblyPath(Path.Combine(SomeProject.IntermediateOutputPath, "SomeProject.dll")))
83+
.WithDefaultNamespace("RootNamespace");
84+
85+
Workspace.TryApplyChanges(Workspace.CurrentSolution.AddProject(projectInfo));
86+
87+
_fallbackProjectManger.DynamicFileAdded(projectId, SomeProject.Key, SomeProject.FilePath, SomeProjectFile1.FilePath);
88+
89+
var project = Assert.Single(_projectSnapshotManager.GetProjects());
90+
Assert.IsType<FallbackHostProject>(((ProjectSnapshot)project).HostProject);
91+
92+
var hostProject = new HostProject(SomeProject.FilePath, SomeProject.IntermediateOutputPath, RazorConfiguration.Default, "RootNamespace", "DisplayName");
93+
_projectSnapshotManager.ProjectConfigurationChanged(hostProject);
94+
95+
project = Assert.Single(_projectSnapshotManager.GetProjects());
96+
Assert.IsNotType<FallbackHostProject>(((ProjectSnapshot)project).HostProject);
97+
}
98+
7599
[Fact]
76100
public void DynamicFileAdded_TrackedProject_AddsDocuments()
77101
{

0 commit comments

Comments
 (0)