Skip to content

Improve diagnostics #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,9 @@ private static PluginClassInfo GetValidPluginInfo(
ImmutableArray<PluginClassInfo> 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,
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <AdditionalFiles /> in your .csproj file.",
"Could not find resource dictionaries. There must be a `en.xaml` file under `Language` folder.",
"Localization",
DiagnosticSeverity.Warning,
isEnabledByDefault: true
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading