Merge pull request #64852 from paulloz/dotnet6-export-category-attribute
C#: Preserve order of exported fields/categories
This commit is contained in:
commit
a8476c04f4
@ -275,5 +275,13 @@ namespace Godot.SourceGenerators
|
|||||||
yield return new GodotFieldData(field, marshalType.Value);
|
yield return new GodotFieldData(field, marshalType.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string Path(this Location location)
|
||||||
|
=> location.SourceTree?.GetLineSpan(location.SourceSpan).Path
|
||||||
|
?? location.GetLineSpan().Path;
|
||||||
|
|
||||||
|
public static int StartLine(this Location location)
|
||||||
|
=> location.SourceTree?.GetLineSpan(location.SourceSpan).StartLinePosition.Line
|
||||||
|
?? location.GetLineSpan().StartLinePosition.Line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,26 @@ namespace Godot.SourceGenerators
|
|||||||
public IFieldSymbol FieldSymbol { get; }
|
public IFieldSymbol FieldSymbol { get; }
|
||||||
public MarshalType Type { get; }
|
public MarshalType Type { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct GodotPropertyOrFieldData
|
||||||
|
{
|
||||||
|
public GodotPropertyOrFieldData(ISymbol symbol, MarshalType type)
|
||||||
|
{
|
||||||
|
Symbol = symbol;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GodotPropertyOrFieldData(GodotPropertyData propertyData)
|
||||||
|
: this(propertyData.PropertySymbol, propertyData.Type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public GodotPropertyOrFieldData(GodotFieldData fieldData)
|
||||||
|
: this(fieldData.FieldSymbol, fieldData.Type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISymbol Symbol { get; }
|
||||||
|
public MarshalType Type { get; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,28 +225,21 @@ namespace Godot.SourceGenerators
|
|||||||
.Append(dictionaryType)
|
.Append(dictionaryType)
|
||||||
.Append("();\n");
|
.Append("();\n");
|
||||||
|
|
||||||
foreach (var property in godotClassProperties)
|
// To retain the definition order (and display categories correctly), we want to
|
||||||
|
// iterate over fields and properties at the same time, sorted by line number.
|
||||||
|
var godotClassPropertiesAndFields = Enumerable.Empty<GodotPropertyOrFieldData>()
|
||||||
|
.Concat(godotClassProperties.Select(propertyData => new GodotPropertyOrFieldData(propertyData)))
|
||||||
|
.Concat(godotClassFields.Select(fieldData => new GodotPropertyOrFieldData(fieldData)))
|
||||||
|
.OrderBy(data => data.Symbol.Locations[0].Path())
|
||||||
|
.ThenBy(data => data.Symbol.Locations[0].StartLine());
|
||||||
|
|
||||||
|
foreach (var member in godotClassPropertiesAndFields)
|
||||||
{
|
{
|
||||||
foreach (var groupingInfo in DetermineGroupingPropertyInfo(property.PropertySymbol))
|
foreach (var groupingInfo in DetermineGroupingPropertyInfo(member.Symbol))
|
||||||
AppendGroupingPropertyInfo(source, groupingInfo);
|
AppendGroupingPropertyInfo(source, groupingInfo);
|
||||||
|
|
||||||
var propertyInfo = DeterminePropertyInfo(context, typeCache,
|
var propertyInfo = DeterminePropertyInfo(context, typeCache,
|
||||||
property.PropertySymbol, property.Type);
|
member.Symbol, member.Type);
|
||||||
|
|
||||||
if (propertyInfo == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
AppendPropertyInfo(source, propertyInfo.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var field in godotClassFields)
|
|
||||||
{
|
|
||||||
|
|
||||||
foreach (var groupingInfo in DetermineGroupingPropertyInfo(field.FieldSymbol))
|
|
||||||
AppendGroupingPropertyInfo(source, groupingInfo);
|
|
||||||
|
|
||||||
var propertyInfo = DeterminePropertyInfo(context, typeCache,
|
|
||||||
field.FieldSymbol, field.Type);
|
|
||||||
|
|
||||||
if (propertyInfo == null)
|
if (propertyInfo == null)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user