Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 11 additions & 6 deletions crates/bindings-csharp/BSATN.Codegen/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public abstract record BaseTypeDeclaration<M>
public readonly string ShortName;
public readonly string FullName;
public readonly TypeKind Kind;
public EquatableArray<M> Members { get; init; }
public readonly EquatableArray<M> Members;

protected abstract M ConvertMember(IFieldSymbol field, DiagReporter diag);
protected abstract M ConvertMember(int index, IFieldSymbol field, DiagReporter diag);

public BaseTypeDeclaration(GeneratorAttributeSyntaxContext context, DiagReporter diag)
{
Expand Down Expand Up @@ -134,10 +134,12 @@ public BaseTypeDeclaration(GeneratorAttributeSyntaxContext context, DiagReporter
Scope = new(typeSyntax);
ShortName = type.Name;
FullName = SymbolToName(type);
Members = new(fields.Select(field => ConvertMember(field, diag)).ToImmutableArray());
Members = new(
fields.Select((field, index) => ConvertMember(index, field, diag)).ToImmutableArray()
);
}

public virtual Scope.Extensions ToExtensions()
public Scope.Extensions ToExtensions()
{
string read,
write;
Expand Down Expand Up @@ -261,8 +263,11 @@ record TypeDeclaration : BaseTypeDeclaration<MemberDeclaration>
public TypeDeclaration(GeneratorAttributeSyntaxContext context, DiagReporter diag)
: base(context, diag) { }

protected override MemberDeclaration ConvertMember(IFieldSymbol field, DiagReporter diag) =>
new(field, diag);
protected override MemberDeclaration ConvertMember(
int index,
IFieldSymbol field,
DiagReporter diag
) => new(field, diag);
}

[Generator]
Expand Down
19 changes: 13 additions & 6 deletions crates/bindings-csharp/Codegen.Tests/fixtures/diag/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,14 @@ public partial struct TestDuplicateTableName { }
}

[SpacetimeDB.Table]
[SpacetimeDB.Index]
public partial struct TestIndexWithoutColumns { }

[SpacetimeDB.Table]
[SpacetimeDB.Index(BTree = [])]
public partial struct TestIndexWithEmptyColumns { }
[SpacetimeDB.Index.BTree(Name = "TestIndexWithoutColumns")]
[SpacetimeDB.Index.BTree(Name = "TestIndexWithEmptyColumns", Columns = [])]
[SpacetimeDB.Index.BTree(Name = "TestUnknownColumns", Columns = ["UnknownColumn"])]
public partial struct TestIndexIssues
{
[SpacetimeDB.Index.BTree(Name = "TestUnexpectedColumns", Columns = ["UnexpectedColumn"])]
public int SelfIndexingColumn;
}

[SpacetimeDB.Table(
Name = "TestScheduleWithoutPrimaryKey",
Expand All @@ -385,6 +387,11 @@ public partial struct TestIndexWithEmptyColumns { }
Scheduled = "DummyScheduledReducer",
ScheduledAt = nameof(ScheduleAtWrongType)
)]
[SpacetimeDB.Table(
Name = "TestScheduleWithMissingScheduleAtField",
Scheduled = "DummyScheduledReducer",
ScheduledAt = "MissingField"
)]
public partial struct TestScheduleIssues
{
[SpacetimeDB.PrimaryKey(Table = "TestScheduleWithWrongPrimaryKeyType")]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading