Fix serialization source generator error when multiple partials of the same definition are user-defined (#5160)

This commit is contained in:
DrSmugleaf
2024-05-23 13:48:40 -07:00
committed by GitHub
parent d69c5500f2
commit f0b45d95cb

View File

@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -36,6 +34,7 @@ public class Generator : IIncrementalGenerator
var (compilation, declarations) = source;
var builder = new StringBuilder();
var containingTypes = new Stack<INamedTypeSymbol>();
var declarationsGenerated = new HashSet<string>();
foreach (var declaration in declarations)
{
@@ -44,6 +43,14 @@ public class Generator : IIncrementalGenerator
var type = compilation.GetSemanticModel(declaration.SyntaxTree).GetDeclaredSymbol(declaration)!;
var symbolName = type
.ToDisplayString()
.Replace('<', '{')
.Replace('>', '}');
if (!declarationsGenerated.Add(symbolName))
continue;
var nonPartial = !IsPartial(declaration);
var namespaceString = type.ContainingNamespace.IsGlobalNamespace
@@ -107,11 +114,6 @@ using Robust.Shared.Serialization.TypeSerializers.Interfaces;
{{containingTypesEnd}}
""");
var symbolName = type
.ToDisplayString()
.Replace('<', '{')
.Replace('>', '}');
var sourceText = CSharpSyntaxTree
.ParseText(builder.ToString())
.GetRoot()