Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protobufectomy: c# codegen #1466

Open
wants to merge 3 commits into
base: noa/protobufectomy
Choose a base branch
from
Open
Changes from 1 commit
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
23 changes: 14 additions & 9 deletions crates/cli/src/subcommands/generate/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ fn autogen_csharp_product_table_common(
],
);

writeln!(output, "[SpacetimeDB.Type]");
writeln!(output, "[DataContract]");
writeln!(output, "[SpacetimeDB.Type]");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this transposition

write!(output, "public partial class {name}");
if let Some(schema) = &schema {
write!(
Expand All @@ -328,7 +328,9 @@ fn autogen_csharp_product_table_common(
}
writeln!(output);
indented_block(&mut output, |output| {
for field in &*product_type.elements {
let num_fields = product_type.elements.len();
for i in 0..num_fields {
let field = &product_type.elements[i];
let field_name = field
.name
.as_ref()
Expand All @@ -343,11 +345,14 @@ fn autogen_csharp_product_table_common(
field_name.to_case(Case::Pascal),
default_init(ctx, &field.algebraic_type)
);
if i + 1 != num_fields {
writeln!(output);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing an additional space in between each field, do we need this change? This is causing the diff for the API upgrade to be pretty insane: https://github.com/clockworklabs/BitCraftClient/pull/3586/files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I added this to make the emitted fields more readable, as the lines can get long. It's not a needed change tho, purely style. Should we keep or remove it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove it, if you feel strongly about the style change we can do it in a separate PR IMO - I just want the API upgrade to be as simple as possible.

}
}
writeln!(output);

// If this is a table, we want to generate event accessor and indexes
if let Some(schema) = &schema {
writeln!(output);
let constraints = schema.column_constraints();
let mut unique_indexes = Vec::new();
// Declare custom index dictionaries
Expand Down Expand Up @@ -647,7 +652,7 @@ pub fn autogen_csharp_globals(items: &[GenItem], namespace: &str) -> Vec<(String
);
writeln!(
output,
"public ReducerEvent(ClientApi.Event dbEvent, IReducerArgs? args) : base(dbEvent) => Args = args;"
"public ReducerEvent(TransactionUpdate update, IReducerArgs? args) : base(update) => Args = args;"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either we need to add using SpacetimeDB.ClientApi; to the top of this file or you need to fully qualify this path because it causes a compilation issue:

Assets/_Project/autogen/_Globals/SpacetimeDBClient.cs(515,23): error CS0246: The type or namespace name 'TransactionUpdate' could not be found (are you missing a using directive or an assembly reference?)

);
writeln!(output);
// Properties for reducer args
Expand Down Expand Up @@ -694,18 +699,18 @@ pub fn autogen_csharp_globals(items: &[GenItem], namespace: &str) -> Vec<(String

writeln!(
output,
"protected override ReducerEvent ReducerEventFromDbEvent(ClientApi.Event dbEvent)"
"protected override ReducerEvent ReducerEventFromDbEvent(TransactionUpdate update)"
);
indented_block(output, |output| {
writeln!(output, "var argBytes = dbEvent.FunctionCall.ArgBytes;");
writeln!(output, "IReducerArgs? args = dbEvent.FunctionCall.Reducer switch {{");
writeln!(output, "var encodedArgs = update.ReducerCall.Args;");
writeln!(output, "IReducerArgs? args = update.ReducerCall.ReducerName switch {{");
{
indent_scope!(output);
for (reducer, reducer_name) in std::iter::zip(&reducers, &reducer_names) {
let reducer_str_name = &reducer.name;
writeln!(
output,
"\"{reducer_str_name}\" => BSATNHelpers.FromProtoBytes<{reducer_name}ArgsStruct>(argBytes),"
"\"{reducer_str_name}\" => BSATNHelpers.Decode<{reducer_name}ArgsStruct>(encodedArgs),"
);
}
writeln!(output, "\"<none>\" => null,");
Expand All @@ -715,7 +720,7 @@ pub fn autogen_csharp_globals(items: &[GenItem], namespace: &str) -> Vec<(String
);
}
writeln!(output, "}};");
writeln!(output, "return new ReducerEvent(dbEvent, args);");
writeln!(output, "return new ReducerEvent(update, args);");
});
});

Expand Down
Loading