Skip to content

Commit 1536c15

Browse files
committed
Add INameTrimmer.Order property and sort trimmers by that instead of version
1 parent 22a2c95 commit 1536c15

File tree

7 files changed

+57
-16
lines changed

7 files changed

+57
-16
lines changed

sources/SilkTouch/SilkTouch/Mods/MixKhronosData.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ public record Configuration
216216
}
217217

218218
/// <inheritdoc />
219-
// non-versioned trimmer (and needs to be a big number to come after the default trimmers)
220-
public Version Version { get; } = new(42, 42, 42, 42);
219+
Version INameTrimmer.Version { get; } = new(0, 0, 0);
220+
221+
/// <inheritdoc/>
222+
int INameTrimmer.Order => (int)TrimmerOrder.MixKhronosData;
221223

222224
/// <inheritdoc />
223225
public async Task InitializeAsync(IModContext ctx, CancellationToken ct = default)

sources/SilkTouch/SilkTouch/Mods/PrettifyNames.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
100100
.Append(new NameAffixerEarlyTrimmer(visitor.AffixTypes))
101101
.Append(new NameAffixerLateTrimmer(visitor.AffixTypes))
102102
.Append(new PrettifyNamesTrimmer())
103-
.OrderBy(x => x.Version)
103+
.OrderBy(x => x.Order)
104104
.ToArray();
105105

106106
// Create a type name dictionary to trim the type names.
@@ -1347,11 +1347,11 @@ public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)
13471347

13481348
private class NameAffixerEarlyTrimmer(Dictionary<string, TypeAffixData> affixTypes) : INameTrimmer
13491349
{
1350-
// TODO: This setup has become insane. Think of a better one.
1351-
/// <summary>
1352-
/// Use high-ish version to ensure this trimmer runs after the global prefix trimmer and before MixKhronosData.
1353-
/// </summary>
1354-
public Version Version => new(21, 21, 21);
1350+
/// <inheritdoc/>
1351+
public Version Version => new(0, 0, 0);
1352+
1353+
/// <inheritdoc/>
1354+
public int Order => (int)TrimmerOrder.NameAffixerEarlyTrimmer;
13551355

13561356
public void Trim(NameTrimmerContext context)
13571357
{
@@ -1378,10 +1378,11 @@ public void Trim(NameTrimmerContext context)
13781378

13791379
private class NameAffixerLateTrimmer(Dictionary<string, TypeAffixData> affixTypes) : INameTrimmer
13801380
{
1381-
/// <summary>
1382-
/// Use high version to ensure this trimmer runs second to last.
1383-
/// </summary>
1384-
public Version Version => new(999, 999, 999);
1381+
/// <inheritdoc/>
1382+
public Version Version => new(0, 0, 0);
1383+
1384+
/// <inheritdoc/>
1385+
public int Order => (int)TrimmerOrder.NameAffixerLateTrimmer;
13851386

13861387
public void Trim(NameTrimmerContext context)
13871388
{
@@ -1408,10 +1409,11 @@ public void Trim(NameTrimmerContext context)
14081409

14091410
private class PrettifyNamesTrimmer : INameTrimmer
14101411
{
1411-
/// <summary>
1412-
/// Use really high version to ensure this trimmer runs last.
1413-
/// </summary>
1414-
public Version Version => new(9999, 9999, 9999);
1412+
/// <inheritdoc/>
1413+
public Version Version => new(0, 0, 0);
1414+
1415+
/// <inheritdoc/>
1416+
public int Order => (int)TrimmerOrder.PrettifyNamesTrimmer;
14151417

14161418
public void Trim(NameTrimmerContext context)
14171419
{

sources/SilkTouch/SilkTouch/Naming/INameTrimmer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public interface INameTrimmer
1515
/// </summary>
1616
Version Version { get; }
1717

18+
/// <summary>
19+
/// Used to define the order that the trimmers will run in.
20+
/// Higher values indicate that the trimmer should run later.
21+
/// </summary>
22+
int Order { get; }
23+
1824
/// <summary>
1925
/// Trims prefixes from the given constituent names within the given container.
2026
/// </summary>

sources/SilkTouch/SilkTouch/Naming/NameTrimmer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public class NameTrimmer : INameTrimmer
1414
/// <inheritdoc />
1515
public virtual Version Version => new(3, 0);
1616

17+
/// <inheritdoc/>
18+
public virtual int Order => (int)TrimmerOrder.NameTrimmer;
19+
1720
/// <summary>
1821
/// Determines whether a second pass without using <see cref="GetTrimmingName"/> is warranted.
1922
/// </summary>

sources/SilkTouch/SilkTouch/Naming/NameTrimmer217.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class NameTrimmer217 : NameTrimmer
1313
/// <inheritdoc />
1414
public override Version Version => new(2, 17);
1515

16+
/// <inheritdoc/>
17+
public override int Order => (int)TrimmerOrder.NameTrimmer217;
18+
1619
/// <inheritdoc />
1720
protected override bool HasRawPass => false;
1821

sources/SilkTouch/SilkTouch/Naming/NameTrimmer218.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class NameTrimmer218 : NameTrimmer
1111
/// <inheritdoc />
1212
public override Version Version => new(2, 18);
1313

14+
/// <inheritdoc/>
15+
public override int Order => (int)TrimmerOrder.NameTrimmer218;
16+
1417
/// <inheritdoc />
1518
protected override bool HasRawPass => false;
1619

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.SilkTouch.Naming;
5+
6+
/// <summary>
7+
/// Defines the order for SilkTouch's <see cref="INameTrimmer"/> implementations.
8+
/// </summary>
9+
internal enum TrimmerOrder
10+
{
11+
NameTrimmer = 100,
12+
NameTrimmer217 = 110,
13+
NameTrimmer218 = 120,
14+
15+
NameAffixerEarlyTrimmer = 200,
16+
17+
MixKhronosData = 300,
18+
19+
NameAffixerLateTrimmer = 400,
20+
21+
PrettifyNamesTrimmer = 500,
22+
}

0 commit comments

Comments
 (0)