Skip to content

Commit f79cbb9

Browse files
committed
Fix useDI issue
1 parent 81f4889 commit f79cbb9

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

Flow.Launcher.Localization.SourceGenerators/Localize/EnumSourceGenerator.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,22 @@ private void Execute(SourceProductionContext spc,
7272
var assemblyNamespace = compilation.AssemblyName ?? Constants.DefaultNamespace;
7373
var useDI = configOptions.GetFLLUseDependencyInjection();
7474

75-
var pluginInfo = PluginInfoHelper.GetValidPluginInfoAndReportDiagnostic(pluginClasses, spc, useDI);
76-
77-
if (pluginInfo == null) return;
75+
PluginClassInfo pluginInfo;
76+
if (useDI)
77+
{
78+
// If we use dependency injection, we do not need to check if there is a valid plugin context
79+
// Also we do not need to return the plugin info
80+
pluginInfo = null;
81+
}
82+
else
83+
{
84+
pluginInfo = PluginInfoHelper.GetValidPluginInfoAndReportDiagnostic(pluginClasses, spc);
85+
if (pluginInfo == null)
86+
{
87+
// If we cannot find a valid plugin info, we do not need to generate the source
88+
return;
89+
}
90+
}
7891

7992
foreach (var enumDeclaration in enumsDeclarations.Distinct())
8093
{

Flow.Launcher.Localization.SourceGenerators/Localize/LocalizeSourceGenerator.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,22 @@ private void Execute(SourceProductionContext spc,
100100
var assemblyNamespace = compilation.AssemblyName ?? Constants.DefaultNamespace;
101101
var useDI = configOptions.GetFLLUseDependencyInjection();
102102

103-
var pluginInfo = PluginInfoHelper.GetValidPluginInfoAndReportDiagnostic(pluginClasses, spc, useDI);
104-
105-
if (pluginInfo == null) return;
103+
PluginClassInfo pluginInfo;
104+
if (useDI)
105+
{
106+
// If we use dependency injection, we do not need to check if there is a valid plugin context
107+
// Also we do not need to return the plugin info
108+
pluginInfo = null;
109+
}
110+
else
111+
{
112+
pluginInfo = PluginInfoHelper.GetValidPluginInfoAndReportDiagnostic(pluginClasses, spc);
113+
if (pluginInfo == null)
114+
{
115+
// If we cannot find a valid plugin info, we do not need to generate the source
116+
return;
117+
}
118+
}
106119

107120
GenerateSource(
108121
spc,

Flow.Launcher.Localization.SourceGenerators/PluginInfoHelper.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ internal class PluginInfoHelper
99
{
1010
public static PluginClassInfo GetValidPluginInfoAndReportDiagnostic(
1111
ImmutableArray<PluginClassInfo> pluginClasses,
12-
SourceProductionContext context,
13-
bool useDI)
12+
SourceProductionContext context)
1413
{
1514
// If p is null, this class does not implement IPluginI18n
1615
var iPluginI18nClasses = pluginClasses.Where(p => p != null).ToArray();
@@ -23,13 +22,6 @@ public static PluginClassInfo GetValidPluginInfoAndReportDiagnostic(
2322
return null;
2423
}
2524

26-
// If we use dependency injection, we do not need to check if there is a valid plugin context
27-
// Also we do not need to return the plugin info
28-
if (useDI)
29-
{
30-
return null;
31-
}
32-
3325
// If p.PropertyName is null, this class does not have PluginInitContext property
3426
var iPluginI18nClassesWithContext = iPluginI18nClasses.Where(p => p.PropertyName != null).ToArray();
3527
if (iPluginI18nClassesWithContext.Length == 0)

0 commit comments

Comments
 (0)