Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7938a0c
Update ClangSharp.PInvokeGenerator
Exanite Apr 14, 2026
78b8ec4
Update comment on ModifyAllReferencesAsync in TransformHandles
Exanite Apr 14, 2026
a11ef49
Format files using CSharpier
Exanite Apr 14, 2026
9cf0637
Remove GetTypeInfo call
Exanite Apr 14, 2026
8c05ec7
Get the compilation once*
Exanite Apr 14, 2026
fe50783
Compare against _relevantIdentifiers set before calling GetSymbolInfo
Exanite Apr 14, 2026
9cb75e1
Skip using directives
Exanite Apr 14, 2026
5638221
Add ProfilingScope
Exanite Apr 14, 2026
a0ea115
Add comment on _relevantIdentifiers
Exanite Apr 14, 2026
ed941db
Fix field naming convention in ProfilingScope
Exanite Apr 14, 2026
8d5b978
Optimize document renaming in PrettifyNames
Exanite Apr 14, 2026
878a90f
Use normalized relative paths during conflict checking
Exanite Apr 14, 2026
9d52a44
Remove NormalizeWhitespace calls (much faster, but breaks generator)
Exanite Apr 15, 2026
aaafeff
Fix issue where the syntax tree gets corrupted due to reparsing
Exanite Apr 16, 2026
f63b15a
Edit comment and error message
Exanite Apr 16, 2026
46c2035
Avoid normalizing the syntax node twice when formatting
Exanite Apr 16, 2026
0d81c61
Avoid rebuilding the _relevantIdentifiers set for every document
Exanite Apr 16, 2026
bd2d79c
Move collections in ResolveConflictsProcessor to be closer to where t…
Exanite Apr 16, 2026
364015d
Preserve original line ending behavior
Exanite Apr 16, 2026
00d83bc
Update SDL to v3.44 from v3.2.4 to fix compile error
Exanite Apr 16, 2026
aa13c48
Revert change to get the compilation once during ModifyAllReferencesA…
Exanite Apr 17, 2026
7d56e23
Revert "Update SDL to v3.44 from v3.2.4 to fix compile error"
Exanite Apr 17, 2026
07e05f0
Revert "Update ClangSharp.PInvokeGenerator"
Exanite Apr 17, 2026
514b866
Revert "Preserve original line ending behavior"
Exanite Apr 17, 2026
1f1428e
Add comment on why UsingDirectiveSyntaxes are skipped
Exanite Apr 17, 2026
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
4 changes: 1 addition & 3 deletions sources/SilkTouch/SilkTouch/Mods/AddApiProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ rewriter.Profile is null
logger.LogDebug("No profile identified for {}", path);
}

ctx.SourceProject = doc.WithSyntaxRoot(
rewriter.Visit(root).NormalizeWhitespace()
).Project;
ctx.SourceProject = doc.WithSyntaxRoot(rewriter.Visit(root)).Project;
rewriter.Profile = null;
}
}
Expand Down
12 changes: 5 additions & 7 deletions sources/SilkTouch/SilkTouch/Mods/AddOpaqueStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ public Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
{
var qualified = name.LastIndexOf('.');
var ns =
qualified != -1
? ModUtils.NamespaceIntoIdentifierName(name.AsSpan()[..qualified])
: _defaultNamespaces.TryGetValue(ctx.JobKey, out var def)
? ModUtils.NamespaceIntoIdentifierName(def)
: null;
qualified != -1 ? ModUtils.NamespaceIntoIdentifierName(name.AsSpan()[..qualified])
: _defaultNamespaces.TryGetValue(ctx.JobKey, out var def)
? ModUtils.NamespaceIntoIdentifierName(def)
: null;
if (ns is null)
{
logger.LogWarning(
Expand Down Expand Up @@ -107,8 +106,7 @@ public Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
)
)
)
)
.NormalizeWhitespace(),
),
filePath: proj.FullPath(fname)
).Project;
}
Expand Down
9 changes: 2 additions & 7 deletions sources/SilkTouch/SilkTouch/Mods/AddVTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,8 +1454,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)

rw.Reset();
proj = doc.WithSyntaxRoot(
rw.Visit(node)?.NormalizeWhitespace()
?? throw new InvalidOperationException("Visit returned null")
rw.Visit(node) ?? throw new InvalidOperationException("Visit returned null")
).Project;
if (rw.InterfacePartials.Count == 0)
{
Expand Down Expand Up @@ -1515,11 +1514,7 @@ rw.ClassName is not null
)
{
proj = proj
?.AddDocument(
Path.GetFileName(fname),
root.NormalizeWhitespace(),
filePath: proj.FullPath(fname)
)
?.AddDocument(Path.GetFileName(fname), root, filePath: proj.FullPath(fname))
.Project;
}

Expand Down
2 changes: 1 addition & 1 deletion sources/SilkTouch/SilkTouch/Mods/BakeSourceSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ .. ctx
{
proj = proj.AddDocument(
Path.GetFileName(bakedPath),
bakedRoot.NormalizeWhitespace(),
bakedRoot,
// we can forgive the below nulls because RelativePath checks them, and returns null if they're null.
filePath: proj.FullPath(bakedPath)
).Project;
Expand Down
38 changes: 20 additions & 18 deletions sources/SilkTouch/SilkTouch/Mods/ChangeNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public Task<List<ResponseFile>> BeforeScrapeAsync(string key, List<ResponseFile>

rsps[i] = rsp with
{
GeneratorConfiguration = rsp.GeneratorConfiguration.ToWrapper() with {
GeneratorConfiguration = rsp.GeneratorConfiguration.ToWrapper() with
{
DefaultNamespace = def,
WithNamespaces = with,
},
Expand Down Expand Up @@ -91,7 +92,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
var doc =
proj!.GetDocument(docId) ?? throw new InvalidOperationException("Document missing");
proj = doc.WithSyntaxRoot(
rewriter.Visit(await doc.GetSyntaxRootAsync(ct))?.NormalizeWhitespace()
rewriter.Visit(await doc.GetSyntaxRootAsync(ct))
Comment thread
Exanite marked this conversation as resolved.
?? throw new InvalidOperationException("Visit returned null.")
).Project;
}
Expand All @@ -116,17 +117,16 @@ public Rewriter(
_usingsToAdd.Clear();
return base.VisitCompilationUnit(node) switch
{
CompilationUnitSyntax syntax
=> syntax.AddUsings(
_usingsToAdd
.Select(x => UsingDirective(ModUtils.NamespaceIntoIdentifierName(x)))
.Where(x =>
syntax.Usings.All(y => x.Name?.ToString() != y.Name?.ToString())
)
.ToArray()
),
CompilationUnitSyntax syntax => syntax.AddUsings(
_usingsToAdd
.Select(x => UsingDirective(ModUtils.NamespaceIntoIdentifierName(x)))
.Where(x =>
syntax.Usings.All(y => x.Name?.ToString() != y.Name?.ToString())
)
.ToArray()
),
{ } ret => ret,
null => null
null => null,
};
}

Expand All @@ -140,10 +140,11 @@ CompilationUnitSyntax syntax
}
return base.VisitNamespaceDeclaration(node) switch
{
NamespaceDeclarationSyntax syntax
=> syntax.WithName(ModUtils.NamespaceIntoIdentifierName(newNs)),
NamespaceDeclarationSyntax syntax => syntax.WithName(
ModUtils.NamespaceIntoIdentifierName(newNs)
),
{ } ret => ret,
null => null
null => null,
};
}

Expand All @@ -159,10 +160,11 @@ FileScopedNamespaceDeclarationSyntax node
}
return base.VisitFileScopedNamespaceDeclaration(node) switch
{
FileScopedNamespaceDeclarationSyntax syntax
=> syntax.WithName(ModUtils.NamespaceIntoIdentifierName(newNs)),
FileScopedNamespaceDeclarationSyntax syntax => syntax.WithName(
ModUtils.NamespaceIntoIdentifierName(newNs)
),
{ } ret => ret,
null => null
null => null,
};
}
}
Expand Down
11 changes: 3 additions & 8 deletions sources/SilkTouch/SilkTouch/Mods/Common/MSBuildModContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,8 @@ private static async Task<string> ToNormalisedStringAsync(
CancellationToken ct = default
)
{
var result = await CodeFormatter.FormatAsync(
root.NormalizeWhitespace().SyntaxTree,
_opts,
ct
);
return !result.CompilationErrors.Any()
? result.Code
: root.NormalizeWhitespace(eol: "\n").ToFullString();
Comment thread
Exanite marked this conversation as resolved.
var normalizedRoot = root.NormalizeWhitespace(eol: "\n");
var result = await CodeFormatter.FormatAsync(normalizedRoot.SyntaxTree, _opts, ct);
return !result.CompilationErrors.Any() ? result.Code : normalizedRoot.ToFullString();
}
}
2 changes: 1 addition & 1 deletion sources/SilkTouch/SilkTouch/Mods/ExtractHandles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
project = project
.AddDocument(
Path.GetFileName(relativePath),
node.NormalizeWhitespace(),
node,
filePath: project.FullPath(relativePath)
)
.Project;
Expand Down
8 changes: 3 additions & 5 deletions sources/SilkTouch/SilkTouch/Mods/ExtractNestedTyping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
// This is also where extracted enums are processed.
rewriter.File = fname;
project = doc.WithSyntaxRoot(
rewriter.Visit(node)?.NormalizeWhitespace()
rewriter.Visit(node)
?? throw new InvalidOperationException("Rewriter returned null")
).Project;

Expand All @@ -110,8 +110,7 @@ rewriter.Namespace is not null
)
)
: SingletonList<MemberDeclarationSyntax>(newStruct)
)
.NormalizeWhitespace(),
),
filePath: project.FullPath(
$"{fname.AsSpan()[..fname.LastIndexOf('/')]}/{newStruct.Identifier}.gen.cs"
)
Expand Down Expand Up @@ -174,8 +173,7 @@ rewriter.Namespace is not null
.WithMembers(SingletonList(typeDecl))
)
: SingletonList(typeDecl)
)
.NormalizeWhitespace(),
),
filePath: project.FullPath($"{dir}/{identifier}.gen.cs")
)
.Project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
var doc =
proj!.GetDocument(docId) ?? throw new InvalidOperationException("Document missing");
proj = doc.WithSyntaxRoot(
rewriter.Visit(await doc.GetSyntaxRootAsync(ct))?.NormalizeWhitespace()
rewriter.Visit(await doc.GetSyntaxRootAsync(ct))
?? throw new InvalidOperationException("Visit returned null.")
).Project;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,40 @@ public class IdentifierRenamingTransformer : LocationTransformer
{
private ISymbol symbol = null!;

private readonly IReadOnlyDictionary<string, List<(ISymbol Symbol, string NewName)>> newNameLookup;
Comment thread
Exanite marked this conversation as resolved.
private readonly IReadOnlyDictionary<
string,
List<(ISymbol Symbol, string NewName)>
> newNameLookup;

/// <summary>
/// Creates a new IdentifierRenamingTransformer.
/// </summary>
/// <param name="newNames">The new names for each symbol</param>
public IdentifierRenamingTransformer(IEnumerable<(ISymbol Symbol, string NewName)> newNames) : this(CreateNameLookup(newNames)) {}
public IdentifierRenamingTransformer(IEnumerable<(ISymbol Symbol, string NewName)> newNames)
: this(CreateNameLookup(newNames)) { }

/// <summary>
/// Creates a new IdentifierRenamingTransformer.
/// </summary>
/// <param name="newNameLookup">The new names for each symbol grouped by symbol name.</param>
public IdentifierRenamingTransformer(IReadOnlyDictionary<string, List<(ISymbol Symbol, string NewName)>> newNameLookup)
public IdentifierRenamingTransformer(
IReadOnlyDictionary<string, List<(ISymbol Symbol, string NewName)>> newNameLookup
)
{
this.newNameLookup = newNameLookup;
}

/// <summary>
/// Creates a name lookup dictionary designed for <see cref="IdentifierRenamingTransformer"/>.
/// </summary>
public static IReadOnlyDictionary<string, List<(ISymbol Symbol, string NewName)>> CreateNameLookup(IEnumerable<(ISymbol Symbol, string NewName)> names)
public static IReadOnlyDictionary<
string,
List<(ISymbol Symbol, string NewName)>
> CreateNameLookup(IEnumerable<(ISymbol Symbol, string NewName)> names)
{
return names.GroupBy(t => t.Symbol.Name).ToDictionary(group => group.Key, group => group.ToList());
return names
.GroupBy(t => t.Symbol.Name)
.ToDictionary(group => group.Key, group => group.ToList());
}

/// <inheritdoc />
Expand Down Expand Up @@ -68,7 +79,7 @@ private SyntaxToken GetRenamed(ISymbol symbol, SyntaxToken currentNameIdentifier
return currentNameIdentifier;
}

// ----- Types -----
// ----- Types -----

/// <inheritdoc />
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
Expand Down
Loading
Loading