Skip to content

Commit 981f833

Browse files
authored
Combining the CompilationProvider is an anti-pattern, create an IncrementalValueProvider for the assembly name instead. (#8021)
1 parent e66d337 commit 981f833

File tree

7 files changed

+17
-16
lines changed

7 files changed

+17
-16
lines changed

src/HotChocolate/Core/src/Types.Analyzers/Generators/DataLoaderGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public sealed class DataLoaderGenerator : ISyntaxGenerator
1111
{
1212
public void Generate(
1313
SourceProductionContext context,
14-
Compilation compilation,
14+
string assemblyName,
1515
ImmutableArray<SyntaxInfo> syntaxInfos)
1616
{
1717
var dataLoaderDefaults = syntaxInfos.GetDataLoaderDefaults();

src/HotChocolate/Core/src/Types.Analyzers/Generators/DataLoaderModuleGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public sealed class DataLoaderModuleGenerator : ISyntaxGenerator
1010
{
1111
public void Generate(
1212
SourceProductionContext context,
13-
Compilation compilation,
13+
string assemblyName,
1414
ImmutableArray<SyntaxInfo> syntaxInfos)
1515
{
1616
var module = GetDataLoaderModuleInfo(syntaxInfos);

src/HotChocolate/Core/src/Types.Analyzers/Generators/ISyntaxGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public interface ISyntaxGenerator
88
{
99
void Generate(
1010
SourceProductionContext context,
11-
Compilation compilation,
11+
string assemblyName,
1212
ImmutableArray<SyntaxInfo> syntaxInfos);
1313
}

src/HotChocolate/Core/src/Types.Analyzers/Generators/MiddlewareGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public sealed class MiddlewareGenerator : ISyntaxGenerator
1212

1313
public void Generate(
1414
SourceProductionContext context,
15-
Compilation compilation,
15+
string assemblyName,
1616
ImmutableArray<SyntaxInfo> syntaxInfos)
1717
{
1818
if (syntaxInfos.IsEmpty)
1919
{
2020
return;
2121
}
2222

23-
var module = syntaxInfos.GetModuleInfo(compilation.AssemblyName, out _);
23+
var module = syntaxInfos.GetModuleInfo(assemblyName, out _);
2424

2525
// the generator is disabled.
2626
if(module.Options == ModuleOptions.Disabled)

src/HotChocolate/Core/src/Types.Analyzers/Generators/TypeModuleSyntaxGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ public sealed class TypeModuleSyntaxGenerator : ISyntaxGenerator
1111
{
1212
public void Generate(
1313
SourceProductionContext context,
14-
Compilation compilation,
14+
string assemblyName,
1515
ImmutableArray<SyntaxInfo> syntaxInfos)
16-
=> Execute(context, compilation, syntaxInfos);
16+
=> Execute(context, assemblyName, syntaxInfos);
1717

1818
private static void Execute(
1919
SourceProductionContext context,
20-
Compilation compilation,
20+
string assemblyName,
2121
ImmutableArray<SyntaxInfo> syntaxInfos)
2222
{
2323
if (syntaxInfos.IsEmpty)
2424
{
2525
return;
2626
}
2727

28-
var module = syntaxInfos.GetModuleInfo(compilation.AssemblyName, out var defaultModule);
28+
var module = syntaxInfos.GetModuleInfo(assemblyName, out var defaultModule);
2929

3030
// the generator is disabled.
3131
if (module.Options == ModuleOptions.Disabled)

src/HotChocolate/Core/src/Types.Analyzers/Generators/TypesSyntaxGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ public sealed class TypesSyntaxGenerator : ISyntaxGenerator
1111
{
1212
public void Generate(
1313
SourceProductionContext context,
14-
Compilation compilation,
14+
string assemblyName,
1515
ImmutableArray<SyntaxInfo> syntaxInfos)
1616
{
1717
if (syntaxInfos.IsEmpty)
1818
{
1919
return;
2020
}
2121

22-
var module = syntaxInfos.GetModuleInfo(compilation.AssemblyName, out _);
22+
var module = syntaxInfos.GetModuleInfo(assemblyName, out _);
2323

2424
// the generator is disabled.
2525
if(module.Options == ModuleOptions.Disabled)

src/HotChocolate/Core/src/Types.Analyzers/GraphQLServerGenerator.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
5858
.WithComparer(SyntaxInfoComparer.Default)
5959
.Collect();
6060

61-
var valueProvider = context.CompilationProvider.Combine(syntaxInfos);
61+
var assemblyNameProvider = context.CompilationProvider
62+
.Select(static (c, _) => c.AssemblyName!);
63+
64+
var valueProvider = assemblyNameProvider.Combine(syntaxInfos);
6265

6366
context.RegisterSourceOutput(
6467
valueProvider,
@@ -83,11 +86,9 @@ private static bool Predicate(SyntaxNode node)
8386

8487
private static void Execute(
8588
SourceProductionContext context,
86-
Compilation compilation,
89+
string assemblyName,
8790
ImmutableArray<SyntaxInfo> syntaxInfos)
8891
{
89-
var dictionary = new Dictionary<string, SyntaxInfo>();
90-
9192
foreach (var syntaxInfo in syntaxInfos.AsSpan())
9293
{
9394
if (syntaxInfo.Diagnostics.Length > 0)
@@ -101,7 +102,7 @@ private static void Execute(
101102

102103
foreach (var generator in _generators.AsSpan())
103104
{
104-
generator.Generate(context, compilation, syntaxInfos);
105+
generator.Generate(context, assemblyName, syntaxInfos);
105106
}
106107
}
107108
}

0 commit comments

Comments
 (0)