Skip to content

Commit a51562b

Browse files
Move cohost options to explicit class (#11566)
Co-authored-by: Chris Sienkiewicz <chsienki@microsoft.com>
1 parent 1874a91 commit a51562b

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Microsoft.NET.Sdk.Razor.SourceGenerators;
2+
3+
internal static class RazorCohostingOptions
4+
{
5+
/// <summary>
6+
/// True if razor is running in the cohosting mode
7+
/// </summary>
8+
internal static bool UseRazorCohostServer { get; set; } = false;
9+
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ public partial class RazorSourceGenerator : IIncrementalGenerator
1919
{
2020
private static RazorSourceGeneratorEventSource Log => RazorSourceGeneratorEventSource.Log;
2121

22-
internal static bool UseRazorCohostServer { get; set; } = false;
23-
2422
// Testing usage only.
2523
private readonly string? _testSuppressUniqueIds;
2624

@@ -40,7 +38,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
4038
var compilation = context.CompilationProvider;
4139

4240
// determine if we should suppress this run and filter out all the additional files and references if so
43-
var isGeneratorSuppressed = analyzerConfigOptions.CheckGlobalFlagSet("SuppressRazorSourceGenerator").Select((suppress, _) => !UseRazorCohostServer && suppress);
41+
var isGeneratorSuppressed = analyzerConfigOptions.CheckGlobalFlagSet("SuppressRazorSourceGenerator").Select((suppress, _) => !RazorCohostingOptions.UseRazorCohostServer && suppress);
4442
var additionalTexts = context.AdditionalTextsProvider.EmptyOrCachedWhen(isGeneratorSuppressed, true);
4543
var metadataRefs = context.MetadataReferencesProvider.EmptyOrCachedWhen(isGeneratorSuppressed, true);
4644

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Initialization/RemoteLanguageServerFeatureOptions.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,10 @@ public void SetOptions(RemoteClientInitializationOptions options)
2020
{
2121
_options = options;
2222

23-
if (options.UseRazorCohostServer)
24-
{
25-
// ensure the source generator is in the correct mode
26-
SetGeneratorToCohostMode();
27-
}
23+
// ensure the source generator is in the correct mode
24+
RazorCohostingOptions.UseRazorCohostServer = options.UseRazorCohostServer;
2825
}
2926

30-
/// <summary>
31-
/// Sets the generator into cohosting mode.
32-
/// </summary>
33-
/// <remarks>
34-
/// This is explicitly a separate method so that if not used we don't unnecessarily JIT any of the generator code.
35-
/// </remarks>
36-
private static void SetGeneratorToCohostMode() => RazorSourceGenerator.UseRazorCohostServer = true;
37-
3827
public override bool SupportsFileManipulation => _options.SupportsFileManipulation;
3928

4029
public override string CSharpVirtualDocumentSuffix => _options.CSharpVirtualDocumentSuffix;

0 commit comments

Comments
 (0)