Skip to content

Commit 1ffd5f0

Browse files
committed
Support CouldNotFindPluginEntryClass & CouldNotFindContextProperty diagnostics
1 parent 8bf2747 commit 1ffd5f0

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,9 @@ private static PluginClassInfo GetValidPluginInfo(
465465
ImmutableArray<PluginClassInfo> pluginClasses,
466466
SourceProductionContext context)
467467
{
468-
var nonNullExistClasses = pluginClasses.Where(p => p != null && p.PropertyName != null).ToArray();
469-
if (nonNullExistClasses.Length == 0)
468+
// If p is null, this class does not implement IPluginI18n
469+
var iPluginI18nClasses = pluginClasses.Where(p => p != null).ToArray();
470+
if (iPluginI18nClasses.Length == 0)
470471
{
471472
context.ReportDiagnostic(Diagnostic.Create(
472473
SourceGeneratorDiagnostics.CouldNotFindPluginEntryClass,
@@ -475,7 +476,24 @@ private static PluginClassInfo GetValidPluginInfo(
475476
return null;
476477
}
477478

478-
foreach (var pluginClass in nonNullExistClasses)
479+
// If p.PropertyName is null, this class does not have PluginInitContext property
480+
var iPluginI18nClassesWithContext = iPluginI18nClasses.Where(p => p.PropertyName != null).ToArray();
481+
if (iPluginI18nClassesWithContext.Length == 0)
482+
{
483+
foreach (var pluginClass in iPluginI18nClasses)
484+
{
485+
context.ReportDiagnostic(Diagnostic.Create(
486+
SourceGeneratorDiagnostics.CouldNotFindContextProperty,
487+
pluginClass.Location,
488+
pluginClass.ClassName
489+
));
490+
}
491+
return null;
492+
}
493+
494+
// Rest classes have implemented IPluginI18n and have PluginInitContext property
495+
// Check if the property is valid
496+
foreach (var pluginClass in iPluginI18nClassesWithContext)
479497
{
480498
if (pluginClass.IsValid == true)
481499
{

0 commit comments

Comments
 (0)