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

Reorder compile errors for #[derive(GodotClass)] #773

Merged

Conversation

fpdotmonkey
Copy link
Contributor

This addresses an issue where relatively major compile errors would be shown only after smaller errors were fixed. This is problematic since fixing a large error has a high chance of invalidating the work for the small error.

In my eyes, the error priority goes with each of these, in order.

  1. Scale - if the error requires a larger change
  2. Locality - if the error requires changes away from the error site
  3. Complexity - if the change for the error carries a lot of meaning

There were two main cases addressed, unsupported tuple structs and editor plugins. Replacing a tuple struct with a regular struct is a very large change. It would require rewriting the struct definition and possibly also distant trait definitions. Because of the large scale, I made the lack of tuple struct support the highest priority error. Editor plugins can error a lot because the class macro needs all three of editor_plugin, tool, and base=EditorPlugin. I prioritized the message for base because it is complex, implementing WithBaseField for the struct, and could also involve non-local changes. tool is easy to fix, so doesn't need priority.

Since this isn't easily testable, here's a couple cases that gave errors in the wrong order before.

// fix the tuple struct, and then an error would occur on rename
#[derive(GodotClass)]
#[class(rename = "Not an identifier")]
struct TupleStructErrorsBeforeRename(String);

// the error is no base, then no tool, and last nonsense is invalid
#[derive(GodotClass)]
#[class(editor_plugin, nonsense)]
struct EditorPluginNoBaseErrorsBeforeNoTool {}

Addresses #545

@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-773

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

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

Thanks a lot, great improvement!

Comment on lines 357 to 359
// This needs to be separate from parse_fields because it needs to
// run before parse_struct_attributes since error from here demands
// a larger refactor than from there, so should be seen first.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe split this sentence, it's a bit hard to understand. And feel free to use longer lines 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What width do you prefer? This is already wider than the 72 characters I normally use

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 excuse me, I always forget that my editor opens narrower than 80 chars. I need to adjust that.

Copy link
Member

Choose a reason for hiding this comment

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

i believe we use 120-145.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly, https://godot-rust.github.io/book/contribute/conventions.html:

Line width is 120-145 characters (mostly relevant for comments).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha 👍

}
}

/// Returns field names and 1 base field, if available
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Returns field names and 1 base field, if available
/// Returns field names and 1 base field, if available.

Comment on lines 353 to 355
/// Fetches data for all named fields for a struct
///
/// Errors if `class` is a tuple struct
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Fetches data for all named fields for a struct
///
/// Errors if `class` is a tuple struct
/// Fetches data for all named fields for a struct.
///
/// Errors if `class` is a tuple struct.

Comment on lines 314 to 328
// Requires #[class(tool, base=EditorPlugin)].
if !is_tool {
if base_ty != ident("EditorPlugin") {
return bail!(
attr_key,
"#[class(editor_plugin)] requires additional key `tool`"
"#[class(editor_plugin)] requires additional key-value `base=EditorPlugin`"
);
}
if base_ty != ident("EditorPlugin") {
if !is_tool {
return bail!(
attr_key,
"#[class(editor_plugin)] requires additional key-value `base=EditorPlugin`"
"#[class(editor_plugin)] requires additional key `tool`"
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe write a comment about the reasoning behind the order, to avoid that future refactors change it again. You can also link to this PR for details.

@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: register Register classes, functions and other symbols to GDScript labels Jun 22, 2024
@fpdotmonkey fpdotmonkey force-pushed the better-derive-gd-class-error-messages branch 2 times, most recently from f0856b3 to 8c52f6b Compare June 22, 2024 14:37
This addresses an issue where relatively major compile errors would be
shown only after smaller errors were fixed.  This is problematic since
fixing a large error has a high chance of invalidating the work for the
small error.

In my eyes, the error priority goes with each of these, in order.
1. Scale - if the error requires a larger change
2. Locality - if the error requires changes away from the error site
3. Complexity - if the change for the error carries a lot of meaning

There were two main cases addressed, unsupported tuple structs and
editor plugins.  Replacing a tuple struct with a regular struct is a
very large change.  It would require rewriting the struct definition and
possibly also distant trait definitions.  Because of the large scale, I
made the lack of tuple struct support the highest priority error.
Editor plugins can error a lot because the `class` macro needs all three
of `editor_plugin`, `tool`, and `base=EditorPlugin`.  I prioritized the
message for `base` because it is complex, implementing `WithBaseField`
for the struct, and could also involve non-local changes.  `tool` is
easy to fix, so doesn't need priority.

Since this isn't easily testable, here's a couple cases that gave errors
in the wrong order before.

```rs
// fix the tuple struct, and then an error would occur on rename
\#[derive(GodotClass)]
\#[class(rename = "Not an identifier")]
struct TupleStructErrorsBeforeRename(String);

// the error is no base, then no tool, and last nonsense is invalid
\#[derive(GodotClass)]
\#[class(editor_plugin, nonsense)]
struct EditorPluginNoBaseErrorsBeforeNoTool {}
```
@fpdotmonkey fpdotmonkey force-pushed the better-derive-gd-class-error-messages branch from 8c52f6b to 5bb8ff5 Compare June 22, 2024 19:52
@fpdotmonkey fpdotmonkey requested a review from Bromeon June 24, 2024 09:59
@Bromeon Bromeon added this pull request to the merge queue Jun 26, 2024
Merged via the queue into godot-rust:master with commit 02c11b5 Jun 26, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: register Register classes, functions and other symbols to GDScript quality-of-life No new functionality, but improves ergonomics/internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants