bsn! macro code quality improvements: codegen, error handling, tests, docs#23561
bsn! macro code quality improvements: codegen, error handling, tests, docs#23561NicoZweifel wants to merge 15 commits intobevyengine:mainfrom
Conversation
| function, | ||
| args, | ||
| }) => { | ||
| // NOTE: The odd turbofish line break below avoids breaking rustfmt |
There was a problem hiding this comment.
Maybe I misunderstand but this didn't do anything for me so I removed it.
| scene_list | ||
| .0 | ||
| .to_tokens(bevy_scene, bevy_ecs, bevy_asset, entity_refs); | ||
| // NOTE: The odd turbofish line breaks below avoid breaking rustfmt |
| } | ||
| } | ||
| None => { | ||
| // NOTE: It is very important to still produce outputs for None field values. This is what |
There was a problem hiding this comment.
Are you sure that this behavior was retained?
I think we still need to push the field access to keep autocomplete working properly.
There was a problem hiding this comment.
I kinda forgot to get back to this actually, my bad. I wanted to add a PR comment here. Thanks for catching that. I should've turned this into a TODO and I think it should either be removed for now or I am re-adding the proposed suggestion.
I could not find that this makes a difference for me when testing the lsp on main or on this branch at an earlier time but I also noticed that there is still an issue with the auto complete for sure.
I understand the logic behind it but I wanted a way to confirm the behavior.
I would not be opposed to adding a test for it either, I do think this behavior should be tested if it is added/kept.
I'll spend a bit more time to resolve this.
There was a problem hiding this comment.
It turns out there were a few missing pieces to make this work correctly but I am happy with it now.
I added tests to make sure the assigments and errors in the macro expansion stay in the same location.
The order is essential for the auto correct to work when there are errors present.
I tested the enum and pretty much anything I could think of:
Objective
This originated from playing around with the
bsn!macro to find out how well the lsp integration works during actual usage when typing new fields etc.It started by adding
new_spannedto report errors. I restructured as I saw fit for now as some of the locations were quite heavily indented, although I'm not opposed to doing it differently. I do think it is an improvement overall.Changes
BsnCodegenCtxto clean up the function signatures and to allow accumulation of errorssyn::Resultreturn types, allowing for optional short circuit behavior.is_const, add tests.BsnTokenStreamtraitNotes
is_constandpath_type, making them real unit tests that follow AAA without taking more space to do it, we can also type them all out if that's not alright but I think it's okay here for these tests.Testing
cargo testcargo benchcargo run --example bsn