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

Relm4 format #385

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Relm4 format #385

wants to merge 14 commits into from

Conversation

AaronErhardt
Copy link
Member

DO NOT TRY THIS WITHOUT COMMITTING YOUR CHANGES BEFORE! THE TOOL ISN'T COMPLETE AND MAY CAUSE LOSS OF DATA.

Summary

  • Adds relm4-format as CLI tool for formatting code in the view macro
  • Moves internal macro code into another crate to allow reusing the code of the view macro for the formatter (proc-macros can't be used as regular dependency)

The tool can be installed with cargo install --path=PATH_TO_RELM4_FORMAT_CRATE.
It can be called from the command line with relm4-format file1 file2 or just relm4-format to format all Rust files contained in the working directory. Be cautious, commit all changes before using!

Checklist

  • cargo fmt
  • cargo clippy
  • cargo test
  • updated CHANGES.md

@euclio
Copy link
Member

euclio commented Jan 20, 2023

Would be nice to handle GTK macros like clone! too.

@AaronErhardt AaronErhardt changed the base branch from main to next March 18, 2023 21:31
@AaronErhardt AaronErhardt marked this pull request as ready for review March 18, 2023 21:31
@AaronErhardt AaronErhardt marked this pull request as draft March 18, 2023 21:32
@AaronErhardt AaronErhardt marked this pull request as ready for review March 20, 2023 22:29
@AaronErhardt AaronErhardt added the waits-on-review-expert A PR that requires a review by someone who's familiar with Relm4's internals label Mar 20, 2023
Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
@@ -13,6 +13,12 @@ impl Parse for ViewWidgets {

while input.peek(Token![,]) {
let _colon: Token![,] = input.parse()?;

// Allow ending with a comma after the last widget
Copy link
Contributor

Choose a reason for hiding this comment

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

This should really be it's own commit and probably a separate PR which could be merged immediately. Trailing comma support on the widgets is one of the rough edges of relm4 that I've encountered too often.

@PJungkamp
Copy link
Contributor

I haven't given this a proper review as I'm not familiar with the internals of relm4 yet. But I want to add some comments based on a quick scan of the code.

  • Why are the relm4-macros-internal and relm4-format crates nested in the relm4-macros directory? I find this quite unusual for a workspace. I think a having something like relm4-macros, relm4-macros2 and relm4-format all top-level next to the other workspace members might make more sense.
  • Adding conditional compilation with #[cfg(feature = format)] for the name_assigned_by_user probably isn't necessary. I think this attribute might also come in handy for fixing my issue relm4_macros::view! triggers clippy::used_underscore_binding lint. #532, where the view! macro uses a call site hygiene in places where mixed hygiene would be more appropriate.

@AaronErhardt
Copy link
Member Author

Thanks for your review!
This likely isn't going to be in its current form however, because parsing files with syn eliminates comments, which makes sense for macros which should ignore them, but makes proper formatting impossible (at least if you don't want to erase comments). It's more likely that - if I find time for this - I will work on an alternative crate to syn which not only could greatly improve parsing and error handling, but also allow parsing comments for formatters like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waits-on-review-expert A PR that requires a review by someone who's familiar with Relm4's internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants