Skip to content

Commit 36c7395

Browse files
authored
Merge pull request #32 from Flow-Launcher/unused_keys
Tell users unused keys & Generate all strings
2 parents 1b056cf + 20035ed commit 36c7395

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

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

+8-24
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
4545
.Collect()
4646
.SelectMany((files, _) => files);
4747

48-
// TODO: Add support for usedKeys
4948
var invocationKeys = context.SyntaxProvider
5049
.CreateSyntaxProvider(
5150
predicate: (n, _) => n is InvocationExpressionSyntax,
@@ -100,7 +99,6 @@ private void Execute(SourceProductionContext spc,
10099
var localizedStrings = data.Item1.Item1.Item1.Item1.LocalizableStrings;
101100

102101
var assemblyName = compilation.AssemblyName ?? Constants.DefaultNamespace;
103-
var optimizationLevel = compilation.Options.OptimizationLevel;
104102
var useDI = configOptions.GetFLLUseDependencyInjection();
105103

106104
var pluginInfo = GetValidPluginInfo(pluginClasses, spc, useDI);
@@ -109,7 +107,6 @@ private void Execute(SourceProductionContext spc,
109107
spc,
110108
xamlFiles[0],
111109
localizedStrings,
112-
optimizationLevel,
113110
assemblyName,
114111
useDI,
115112
pluginInfo,
@@ -383,7 +380,6 @@ private static (string Summary, ImmutableArray<LocalizableStringParam> Parameter
383380

384381
#region Get Used Localization Keys
385382

386-
// TODO: Add support for usedKeys
387383
private static string GetLocalizationKeyFromInvocation(GeneratorSyntaxContext context, CancellationToken ct)
388384
{
389385
if (ct.IsCancellationRequested)
@@ -548,28 +544,22 @@ private static void GenerateSource(
548544
SourceProductionContext spc,
549545
AdditionalText xamlFile,
550546
ImmutableArray<LocalizableString> localizedStrings,
551-
OptimizationLevel optimizationLevel,
552547
string assemblyName,
553548
bool useDI,
554549
PluginClassInfo pluginInfo,
555550
IEnumerable<string> usedKeys)
556551
{
557-
// Get unusedKeys if we need to optimize
558-
IEnumerable<string> unusedKeys = new List<string>();
559-
if (optimizationLevel == OptimizationLevel.Release)
560-
{
561-
unusedKeys = localizedStrings
552+
// Report unusedKeys
553+
var unusedKeys = localizedStrings
562554
.Select(ls => ls.Key)
563555
.ToImmutableHashSet()
564556
.Except(usedKeys);
565-
566-
foreach (var key in unusedKeys)
567-
{
568-
spc.ReportDiagnostic(Diagnostic.Create(
569-
SourceGeneratorDiagnostics.LocalizationKeyUnused,
570-
Location.None,
571-
key));
572-
}
557+
foreach (var key in unusedKeys)
558+
{
559+
spc.ReportDiagnostic(Diagnostic.Create(
560+
SourceGeneratorDiagnostics.LocalizationKeyUnused,
561+
Location.None,
562+
key));
573563
}
574564

575565
var sourceBuilder = new StringBuilder();
@@ -636,12 +626,6 @@ private static void GenerateSource(
636626
// Generate localization methods
637627
foreach (var ls in localizedStrings)
638628
{
639-
// TODO: Add support for usedKeys
640-
/*if (unusedKeys.Contains(ls.Key))
641-
{
642-
continue;
643-
}*/
644-
645629
GenerateDocComments(sourceBuilder, ls, tabString);
646630
GenerateLocalizationMethod(sourceBuilder, ls, getTranslation, tabString);
647631
}

0 commit comments

Comments
 (0)