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 3 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 @@ -4,10 +4,9 @@

Rule ID | Category | Severity | Notes
--------|----------|----------|-------
FLSG0001 | Localization | Warning | FLSG0001_CouldNotFindResourceDictionaries
FLSG0001 | Localization | Warning | FLSG0001_LocalizationKeyUnused
FLSG0002 | Localization | Warning | FLSG0002_CouldNotFindPluginEntryClass
FLSG0003 | Localization | Warning | FLSG0003_CouldNotFindContextProperty
FLSG0004 | Localization | Warning | FLSG0004_ContextPropertyNotStatic
FLSG0005 | Localization | Warning | FLSG0005_ContextPropertyIsPrivate
FLSG0006 | Localization | Warning | FLSG0006_ContextPropertyIsProtected
FLSG0007 | Localization | Warning | FLSG0007_LocalizationKeyUnused
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@ private void Execute(SourceProductionContext spc,
ImmutableArray<AdditionalText> AdditionalTexts) data)
{
var xamlFiles = data.AdditionalTexts;
if (xamlFiles.Length == 0)
{
spc.ReportDiagnostic(Diagnostic.Create(
SourceGeneratorDiagnostics.CouldNotFindResourceDictionaries,
Location.None
));
return;
}

var compilation = data.Item1.Compilation;
var configOptions = data.Item1.Item1.ConfigOptionsProvider;
var pluginClasses = data.Item1.Item1.Item1.PluginClassInfos;
Expand Down Expand Up @@ -465,8 +456,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 +467,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 @@ -5,10 +5,10 @@ namespace Flow.Launcher.Localization.SourceGenerators
{
public static class SourceGeneratorDiagnostics
{
public static readonly DiagnosticDescriptor CouldNotFindResourceDictionaries = new DiagnosticDescriptor(
public static readonly DiagnosticDescriptor LocalizationKeyUnused = 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.",
"Localization key is unused",
$"Method `{Constants.ClassName}.{{0}}` is never used",
"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,16 +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.",
"Localization",
DiagnosticSeverity.Warning,
isEnabledByDefault: true
);

public static readonly DiagnosticDescriptor LocalizationKeyUnused = new DiagnosticDescriptor(
"FLSG0007",
"Localization key is unused",
$"Method '{Constants.ClassName}.{{0}}' is never used",
"Context property `{0}` is protected. It must be either internal or public.",
"Localization",
DiagnosticSeverity.Warning,
isEnabledByDefault: true
Expand Down
Loading