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

rstml 0.12 and enforce braces in attribute values #2753

Closed
wants to merge 3 commits into from

Conversation

blorbb
Copy link
Contributor

@blorbb blorbb commented Aug 1, 2024

This is an implementation of the first half of #2196

Invalid values were added in rstml 0.12.0 (related: rs-tml/rstml#54) which allows incomplete expressions to be expanded. Alongside this implementation, rust-analyzer support is significantly improved:

image

Even with an invalid expression, rust-analyzer can provide autocomplete suggestions.

Note: rstml 0.12 adds a generic to a few structs (NodeElement, Node). I'm not actually sure what this generic is for, I just added what the compiler told me to add. Testing the changes to leptos_hot_reload may be good.

Minor issue: for some reason, adding #[allow(unused_brace)] directly at the expression expansion would break rust-analyzer and it wouldn't provide suggestions. #[allow(unused_braces)] has been added to the entire view! expansion, which allows all unused braces, so some legitimate warnings might disappear.

@benwis
Copy link
Contributor

benwis commented Aug 1, 2024

I'm excited, looks like you have a couple conflicts. Once those are resolved, is it ready for testing?

@blorbb
Copy link
Contributor Author

blorbb commented Aug 1, 2024

Oh this PR was mergeable before and had 1 commit, I think @gbj your force push broke some things. Is it possible to revert that? Otherwise I can just fix it up later, looks like I can just accept everything on the upstream side and it should work fine.

@blorbb blorbb force-pushed the attr-value-braces branch from 6d059d6 to 80e8d49 Compare August 2, 2024 00:26
@blorbb
Copy link
Contributor Author

blorbb commented Aug 2, 2024

nvm fixed it up (thanks to some friends who know git way better than me), should be ready now @benwis

@gbj
Copy link
Collaborator

gbj commented Aug 2, 2024

Sorry @blorbb I suspect it is at least in part on my own limited git skills — when I rebase leptos_0.7 onto main and have conflicts, after resolving I tend to force-push but of course that screws up PRs that are onto leptos_0.7 themselves. I'm trying to finish things off in the next few days so it can merge into main and we can be in a more normal dev cycle at least.

This looks good to me in general, and the compile error seems helpful at least. Maybe worth adding a note about how to migrate automatically with leptosfmt?

I assume that all of the examples and many doctests will be broken when this is merged, because they aren't currently using braces for attribute values — Does that sound accurate?

If so one of us should

  1. run leptosfmt on all the examples as a starting point (and restore any deleted comments...)
  2. run leptosfmt to add braces

@blorbb
Copy link
Contributor Author

blorbb commented Aug 2, 2024

Oh yeah I just fixed up the braces rust told me about, totally forgot about examples! Does leptosfmt work on examples and docs?

Adding a comment explaining how to migrate might be quite a lot of noise, could you perhaps create a migration guide on GitHub/leptos.dev so that the note can link to a website(+heading) instead of a full explanation? It doesn't seem like there's a one-line command to configure leptosfmt to use the "AlwaysUnlessLit" brace style.

@blorbb
Copy link
Contributor Author

blorbb commented Aug 3, 2024

I ran leptosfmt on the examples and tried to fix up all the comments. Also manually added braces to the docs (many doctests are still broken due to other reasons, I haven't fixed other issues in the commit).

I went through most of the diff but I'm not 100% sure that I fixed every comment changed by leptosfmt, you may want to look through it again to double-check

@gbj
Copy link
Collaborator

gbj commented Aug 4, 2024

I have now merged the 0.7 branch into main, to help avoid the conflicts that have come from juggling main, 0.7, PRs to main, and PRs to 0.7. Could you please open a new PR against main? This will also allow CI to run, which will catch missing cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants