diff --git a/Flow.Launcher.Localization.SourceGenerators/Localize/LocalizeSourceGenerator.cs b/Flow.Launcher.Localization.SourceGenerators/Localize/LocalizeSourceGenerator.cs index 5dc3058..a9594fd 100644 --- a/Flow.Launcher.Localization.SourceGenerators/Localize/LocalizeSourceGenerator.cs +++ b/Flow.Launcher.Localization.SourceGenerators/Localize/LocalizeSourceGenerator.cs @@ -465,8 +465,9 @@ private static PluginClassInfo GetValidPluginInfo( ImmutableArray pluginClasses, SourceProductionContext context) { - var nonNullExistClasses = pluginClasses.Where(p => p != null && p.PropertyName != null).ToArray(); - if (nonNullExistClasses.Length == 0) + // If p is null, this class does not implement IPluginI18n + var iPluginI18nClasses = pluginClasses.Where(p => p != null).ToArray(); + if (iPluginI18nClasses.Length == 0) { context.ReportDiagnostic(Diagnostic.Create( SourceGeneratorDiagnostics.CouldNotFindPluginEntryClass, @@ -475,7 +476,24 @@ private static PluginClassInfo GetValidPluginInfo( return null; } - foreach (var pluginClass in nonNullExistClasses) + // If p.PropertyName is null, this class does not have PluginInitContext property + var iPluginI18nClassesWithContext = iPluginI18nClasses.Where(p => p.PropertyName != null).ToArray(); + if (iPluginI18nClassesWithContext.Length == 0) + { + foreach (var pluginClass in iPluginI18nClasses) + { + context.ReportDiagnostic(Diagnostic.Create( + SourceGeneratorDiagnostics.CouldNotFindContextProperty, + pluginClass.Location, + pluginClass.ClassName + )); + } + return null; + } + + // Rest classes have implemented IPluginI18n and have PluginInitContext property + // Check if the property is valid + foreach (var pluginClass in iPluginI18nClassesWithContext) { if (pluginClass.IsValid == true) { diff --git a/Flow.Launcher.Localization.SourceGenerators/SourceGeneratorDiagnostics.cs b/Flow.Launcher.Localization.SourceGenerators/SourceGeneratorDiagnostics.cs index e74c915..d162cdb 100644 --- a/Flow.Launcher.Localization.SourceGenerators/SourceGeneratorDiagnostics.cs +++ b/Flow.Launcher.Localization.SourceGenerators/SourceGeneratorDiagnostics.cs @@ -8,7 +8,7 @@ public static class SourceGeneratorDiagnostics public static readonly DiagnosticDescriptor CouldNotFindResourceDictionaries = new DiagnosticDescriptor( "FLSG0001", "Could not find resource dictionaries", - "Could not find resource dictionaries. There must be a file named [LANG].xaml file (for example, en.xaml), and it must be specified in in your .csproj file.", + "Could not find resource dictionaries. There must be a `en.xaml` file under `Language` folder.", "Localization", DiagnosticSeverity.Warning, isEnabledByDefault: true @@ -17,7 +17,7 @@ public static class SourceGeneratorDiagnostics public static readonly DiagnosticDescriptor CouldNotFindPluginEntryClass = new DiagnosticDescriptor( "FLSG0002", "Could not find the main class of plugin", - $"Could not find the main class of your plugin. It must implement {Constants.PluginInterfaceName}.", + $"Could not find the main class of your plugin. It must implement `{Constants.PluginInterfaceName}`.", "Localization", DiagnosticSeverity.Warning, isEnabledByDefault: true @@ -26,7 +26,7 @@ public static class SourceGeneratorDiagnostics public static readonly DiagnosticDescriptor CouldNotFindContextProperty = new DiagnosticDescriptor( "FLSG0003", "Could not find plugin context property", - $"Could not find a property of type {Constants.PluginContextTypeName} in {{0}}. It must be a public static or internal static property of the main class of your plugin.", + $"Could not find a property of type `{Constants.PluginContextTypeName}` in `{{0}}`. It must be a public static or internal static property of the main class of your plugin.", "Localization", DiagnosticSeverity.Warning, isEnabledByDefault: true @@ -35,7 +35,7 @@ public static class SourceGeneratorDiagnostics public static readonly DiagnosticDescriptor ContextPropertyNotStatic = new DiagnosticDescriptor( "FLSG0004", "Plugin context property is not static", - "Context property {0} is not static. It must be static.", + "Context property `{0}` is not static. It must be static.", "Localization", DiagnosticSeverity.Warning, isEnabledByDefault: true @@ -44,7 +44,7 @@ public static class SourceGeneratorDiagnostics public static readonly DiagnosticDescriptor ContextPropertyIsPrivate = new DiagnosticDescriptor( "FLSG0005", "Plugin context property is private", - "Context property {0} is private. It must be either internal or public.", + "Context property `{0}` is private. It must be either internal or public.", "Localization", DiagnosticSeverity.Warning, isEnabledByDefault: true @@ -53,7 +53,7 @@ public static class SourceGeneratorDiagnostics public static readonly DiagnosticDescriptor ContextPropertyIsProtected = new DiagnosticDescriptor( "FLSG0006", "Plugin context property is protected", - "Context property {0} is protected. It must be either internal or public.", + "Context property `{0}` is protected. It must be either internal or public.", "Localization", DiagnosticSeverity.Warning, isEnabledByDefault: true @@ -62,7 +62,7 @@ public static class SourceGeneratorDiagnostics public static readonly DiagnosticDescriptor LocalizationKeyUnused = new DiagnosticDescriptor( "FLSG0007", "Localization key is unused", - $"Method '{Constants.ClassName}.{{0}}' is never used", + $"Method `{Constants.ClassName}.{{0}}` is never used", "Localization", DiagnosticSeverity.Warning, isEnabledByDefault: true