Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
02d8ef4
Entity Relations
Roudenn Aug 14, 2026
d9ec76c
Part 2
Roudenn Aug 15, 2026
feb6d23
Clean components on manual relation remove
Roudenn Aug 15, 2026
d97e4fc
Update RobustUnitTest.cs
Roudenn Aug 15, 2026
b36a612
More API methods to clear relations
Roudenn Aug 15, 2026
12f0760
Fix API methods
Roudenn Aug 15, 2026
f9a89fa
New ExperimentalTM generator for relations
Roudenn Aug 15, 2026
46ba8c6
Update EntityRelationsSystem.cs
Roudenn Aug 15, 2026
ef033eb
Make shutdown event codegen a bool parameter
Roudenn Aug 15, 2026
2d2cfcb
Update RobustServerSimulation.cs
Roudenn Aug 15, 2026
97117b7
Update EntityDeserializer.cs
Roudenn Aug 15, 2026
66ff141
Docs + analyzer fixes
Roudenn Aug 15, 2026
8b559a6
Review fixes
Roudenn Aug 16, 2026
3bdb07b
Add debug asserts if you make a self-reference
Roudenn Aug 16, 2026
d8e913e
Add a basic test for EntityRelations
Roudenn Aug 16, 2026
9565847
Fix test. fix dictionaries and nullable relations
Roudenn Aug 16, 2026
6733d74
EntityRelationGenerator -> EntityRelationAnalyzer
Roudenn Aug 16, 2026
b45a476
small doc fix
Roudenn Aug 16, 2026
ed70d47
EntityRelationsGeneratorTest
Roudenn Aug 16, 2026
27c1256
Update EntityRelationsGeneratorTest.cs
Roudenn Aug 16, 2026
b9c8ebd
SetRelation `dirty` parameter
Roudenn Aug 16, 2026
b3f49d6
Fix dictionary EntityRelation networking
Roudenn Aug 16, 2026
dea8fb5
Improve API and tests
Roudenn Aug 17, 2026
2f71711
Update EntityRelationsSystemTests.Networking.cs
Roudenn Aug 17, 2026
97186d4
Content API improvements (no I won't make tests)
Roudenn Aug 17, 2026
ed15bd6
Fix swapping Relations by setting them 2 in a row
Roudenn Aug 18, 2026
889823f
Improve collection Relations API even more
Roudenn Aug 19, 2026
01f5dcf
refactor: whitespaces, xml-doc indent, explicit braces and use patter…
Fildrance Aug 23, 2026
84708e3
refactor: extract methods
Fildrance Aug 23, 2026
6d1f358
Review changes
Roudenn Aug 26, 2026
49b1028
Fix network not networking
Roudenn Aug 26, 2026
46fa0cc
Simplify HasRelations method API
Roudenn Aug 26, 2026
acb9115
Merge remote-tracking branch 'upstream/master' into entity-relations
Roudenn Sep 26, 2026
bddcf8d
Merge remote-tracking branch 'upstream/master' into entity-relations
Roudenn Nov 1, 2026
1b378dc
Clear entity relations on `ComponentRemove`
Roudenn Nov 2, 2026
34adfa4
Remove explicit dirtying and fix component adds
Roudenn Nov 2, 2026
ac458c7
Move EntityRelation to separate serializer
Roudenn Nov 2, 2026
ca4c1ac
Merge remote-tracking branch 'upstream/master' into entity-relations
Roudenn Nov 4, 2026
4ce05cf
Local entity relations
Roudenn Nov 4, 2026
cd885ed
Fix local relations + add tests
Roudenn Nov 5, 2026
be4f1d8
Merge remote-tracking branch 'upstream/master' into entity-relations
Roudenn Nov 20, 2026
013c198
SetRemoveOnEmpty ensures the component when false
Roudenn Nov 20, 2026
f393e83
Fix codegen not working
Roudenn Nov 21, 2026
c63bb59
Throw away buggy EntityRelationSerializer
Roudenn Nov 21, 2026
81c5f01
Collection options for relations
Roudenn Nov 22, 2026
cac8740
Fix `ClearRelations` API shenanigans
Roudenn Nov 22, 2026
9cedcc3
Update EntitySystem.Proxy.cs
Roudenn Nov 22, 2026
dbb2e5e
Fix test
Roudenn Nov 22, 2026
1507492
Fix networking able to make invalid relations
Roudenn Nov 22, 2026
dabb4ec
Entity relation public constructor
Roudenn Nov 26, 2026
d6f0e05
start refactoring stuff
Roudenn Nov 29, 2026
a07d0c3
api
Roudenn Nov 29, 2026
5011852
Move API to EntityRelationsSystem and simplify it
Roudenn Nov 29, 2026
1110c11
Update EntityRelationsSystemTests.cs
Roudenn Nov 29, 2026
7aa2f9e
Remove collection settings
Roudenn Nov 29, 2026
b3aa028
Remove EntityRelation wrapper struct
Roudenn Nov 29, 2026
4ad6280
Reconstruct relations on deserialization
Roudenn Nov 29, 2026
e3ec9e8
Oops I did it wrong
Roudenn Nov 29, 2026
50b350d
prevent client from doing anything with relations
Roudenn Nov 29, 2026
1fe7468
Fix tests
Roudenn Nov 29, 2026
e20134d
Update EntityRelationsSystem.API.cs
Roudenn Nov 29, 2026
1ee7fd0
Merge remote-tracking branch 'upstream/master' into entity-relations
Roudenn Nov 29, 2026
d820b45
EntityQuery ensure comps
Roudenn Nov 29, 2026
221a6fb
I am likely doing something wrong...
Roudenn Nov 30, 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
453 changes: 453 additions & 0 deletions Robust.Analyzers.Tests/EntityRelationsGeneratorTest.cs

Large diffs are not rendered by default.

152 changes: 152 additions & 0 deletions Robust.Analyzers/EntityRelationsAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Robust.Roslyn.Shared;

namespace Robust.Analyzers;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class EntityRelationsAnalyzer : DiagnosticAnalyzer
{
private const string AutoGenerateEntityRelationsAttributeName = "Robust.Shared.Analyzers.AutoGenerateEntityRelationsAttribute";
private const string AutoRelationFieldAttributeName = "Robust.Shared.Analyzers.AutoRelationFieldAttribute";
// ReSharper disable once InconsistentNaming
private const string IComponentTypeName = "Robust.Shared.GameObjects.IComponent";

private static readonly DiagnosticDescriptor NotComponentDiagnostic = new(
Diagnostics.IdComponentRelationNotComponent,
"Class must be an IComponent to use AutoGenerateEntityRelations",
"Class '{0}' must implement IComponent to be used with [AutoGenerateEntityRelations]",
"Usage",
DiagnosticSeverity.Error,
true);

private static readonly DiagnosticDescriptor NoFieldsDiagnostic = new(
Diagnostics.IdComponentRelationNoFields,
"AutoGenerateEntityRelations has no fields",
"Class '{0}' has [AutoGenerateEntityRelations] but has no fields or properties with [AutoRelationField]",
"Usage",
DiagnosticSeverity.Warning,
true);

private static readonly DiagnosticDescriptor NoParentAttributeDiagnostic = new(
Diagnostics.IdComponentRelationNoParentAttribute,
"AutoRelationField on type of field without AutoGenerateEntityRelations",
"Field '{0}' has [AutoRelationField] but its containing type does not have [AutoGenerateEntityRelations]",
"Usage",
DiagnosticSeverity.Error,
true);

private static readonly DiagnosticDescriptor WrongTypeAttributeDiagnostic = new(
Diagnostics.IdComponentRelationWrongTypeAttribute,
"AutoRelationField has wrong type",
"Field '{0}' has [AutoRelationField] but is not of type 'EntityUid?' or any supported collection containing 'EntityUid?'",
"Usage",
DiagnosticSeverity.Error,
true);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [
NotComponentDiagnostic,
NoFieldsDiagnostic,
NoParentAttributeDiagnostic,
WrongTypeAttributeDiagnostic
];

public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();

context.RegisterSymbolAction(AnalyzeNamedType, SymbolKind.NamedType);
context.RegisterSymbolAction(AnalyzeFieldOrProperty, SymbolKind.Field, SymbolKind.Property);
}

private static void AnalyzeNamedType(SymbolAnalysisContext context)
{
if (context.Symbol is not INamedTypeSymbol symbol)
return;

if (!AttributeHelper.HasAttribute(symbol, AutoGenerateEntityRelationsAttributeName))
return;

var syntax = symbol.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() as TypeDeclarationSyntax;
var location = syntax?.Identifier.GetLocation() ?? symbol.Locations.FirstOrDefault();

// Check if it implements IComponent
if (!symbol.ImplementsInterface(IComponentTypeName))
{
context.ReportDiagnostic(
Diagnostic.Create(NotComponentDiagnostic, location, symbol.Name)
);
}

// Check if it has any fields with [AutoRelationField]
var hasFields = false;
foreach (var member in symbol.GetMembers())
{
if (member is not IFieldSymbol and not IPropertySymbol
|| !AttributeHelper.HasAttribute(member, AutoRelationFieldAttributeName))
{
continue;
}

hasFields = true;
break;
}

if (!hasFields)
{
context.ReportDiagnostic(
Diagnostic.Create(NoFieldsDiagnostic, location, symbol.Name));
}
}

private static void AnalyzeFieldOrProperty(SymbolAnalysisContext context)
{
var symbol = context.Symbol;

if (!AttributeHelper.HasAttribute(symbol, AutoRelationFieldAttributeName))
return;

var syntax = symbol.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax();
var location = syntax switch
{
PropertyDeclarationSyntax prop => prop.Identifier.GetLocation(),
VariableDeclaratorSyntax varDecl => varDecl.Identifier.GetLocation(),
_ => symbol.Locations.FirstOrDefault(),
};

// Check if parent has [AutoGenerateEntityRelations]
if (!AttributeHelper.HasAttribute(symbol.ContainingType, AutoGenerateEntityRelationsAttributeName))
{
context.ReportDiagnostic(
Diagnostic.Create(NoParentAttributeDiagnostic, location, symbol.Name));
}

// Check type validity
var type = symbol switch
{
IPropertySymbol property => property.Type,
IFieldSymbol field => field.Type,
_ => null
};

if (type is not INamedTypeSymbol namedType)
return;

switch (namedType)
{
case { Name: "Nullable", TypeArguments: [{ Name: "EntityUid" }] }:
case { Name: "List", TypeArguments: [{ Name: "EntityUid" }] }:
case { Name: "HashSet", TypeArguments: [{ Name: "EntityUid" }] }:
case { Name: "Dictionary", TypeArguments: [{ Name: "EntityUid" }, _] }:
case { Name: "Dictionary", TypeArguments: [_, { Name: "EntityUid" }] }:
return;
}

context.ReportDiagnostic(
Diagnostic.Create(WrongTypeAttributeDiagnostic, symbol.Locations[0], symbol.Name)
);
}
}
4 changes: 4 additions & 0 deletions Robust.Roslyn.Shared/Diagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public static class Diagnostics
public const string IdDataFieldOutsideDefinition = "RA0057";
public const string IdEntitySystemSubscriptionConversionPossible = "RA0058";
public const string IdEntitySystemNamingViolation = "RA0059";
public const string IdComponentRelationNotComponent = "RA0060";
public const string IdComponentRelationNoFields = "RA0061";
public const string IdComponentRelationNoParentAttribute = "RA0062";
public const string IdComponentRelationWrongTypeAttribute = "RA0063";

public static SuppressionDescriptor MeansImplicitAssignment =>
new SuppressionDescriptor("RADC1000", "CS0649", "Marked as implicitly assigned.");
Expand Down
Loading
Loading