Skip to content

Commit 77b605c

Browse files
authored
Don't switch runtime / design time solutions if cohosting is on (#80065)
1 parent ec0bb2c commit 77b605c

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.CodeAnalysis.Options;
6+
7+
internal class LegacyRazorOptions
8+
{
9+
public static readonly Option2<bool> UseCohosting = new("razor_use_cohosting", defaultValue: false);
10+
}

src/Features/Core/Portable/Workspace/CompileTimeSolutionProvider.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Threading.Tasks;
1515
using Microsoft.CodeAnalysis.Collections;
1616
using Microsoft.CodeAnalysis.Host.Mef;
17+
using Microsoft.CodeAnalysis.Options;
1718
using Microsoft.CodeAnalysis.PooledObjects;
1819
using Microsoft.CodeAnalysis.Shared.Extensions;
1920
using Roslyn.Utilities;
@@ -28,17 +29,13 @@ namespace Microsoft.CodeAnalysis.Host;
2829
internal sealed class CompileTimeSolutionProvider : ICompileTimeSolutionProvider
2930
{
3031
[ExportWorkspaceServiceFactory(typeof(ICompileTimeSolutionProvider), [WorkspaceKind.Host]), Shared]
31-
private sealed class Factory : IWorkspaceServiceFactory
32+
[method: ImportingConstructor]
33+
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
34+
private sealed class Factory(IGlobalOptionService globalOptions) : IWorkspaceServiceFactory
3235
{
33-
[ImportingConstructor]
34-
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
35-
public Factory()
36-
{
37-
}
38-
3936
[Obsolete(MefConstruction.FactoryMethodMessage, error: true)]
4037
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
41-
=> new CompileTimeSolutionProvider(workspaceServices.Workspace);
38+
=> new CompileTimeSolutionProvider(workspaceServices.Workspace, globalOptions);
4239
}
4340

4441
private const string RazorEncConfigFileName = "RazorSourceGenerator.razorencconfig";
@@ -52,6 +49,8 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
5249
private static readonly ImmutableArray<string> s_razorSourceGeneratorFileNamePrefixes = s_razorSourceGeneratorAssemblyNames
5350
.SelectAsArray(static assemblyName => Path.Combine(assemblyName, RazorSourceGeneratorTypeName));
5451

52+
private readonly bool _useCohosting;
53+
5554
private readonly object _gate = new();
5655

5756
/// <summary>
@@ -65,8 +64,9 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
6564

6665
private Solution? _lastCompileTimeSolution;
6766

68-
public CompileTimeSolutionProvider(Workspace workspace)
67+
public CompileTimeSolutionProvider(Workspace workspace, IGlobalOptionService globalOptions)
6968
{
69+
_useCohosting = globalOptions.GetOption(LegacyRazorOptions.UseCohosting);
7070
_ = workspace.RegisterWorkspaceChangedHandler((e) =>
7171
{
7272
if (e.Kind is WorkspaceChangeKind.SolutionCleared or WorkspaceChangeKind.SolutionRemoved)
@@ -89,6 +89,12 @@ private static bool IsRazorAnalyzerConfig(TextDocumentState documentState)
8989

9090
public Solution GetCompileTimeSolution(Solution designTimeSolution)
9191
{
92+
if (_useCohosting)
93+
{
94+
// when cohosting is on, the design time and runtime solutions are the same
95+
return designTimeSolution;
96+
}
97+
9298
lock (_gate)
9399
{
94100
_designTimeToCompileTimeSolution.TryGetValue(designTimeSolution, out var cachedCompileTimeSolution);

src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,5 +420,6 @@ public bool TryFetch(LocalUserRegistryOptionPersister persister, OptionKey2 opti
420420
{"dotnet_validate_compilation_tracker_states", new FeatureFlagStorage(@"Roslyn.ValidateCompilationTrackerStates")},
421421
{"dotnet_source_generator_execution", new RoamingProfileStorage("TextEditor.Roslyn.Specific.SourceGeneratorExecution")},
422422
{"xaml_enable_lsp_intellisense", new FeatureFlagStorage(@"Xaml.EnableLspIntelliSense")},
423+
{"razor_use_cohosting", new FeatureFlagStorage("Razor.LSP.UseRazorCohostServer")},
423424
};
424425
}

0 commit comments

Comments
 (0)