DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
19.3k stars 735 forks source link

For/If exprs not being indented properly #2232

Closed XavDesbordes closed 2 months ago

XavDesbordes commented 2 months ago

Hi,

latest dioxus: using rsx! format on save in the dioxus plugin for Vs code. Linux

pictures worth 1000 words:

Normal loop in rust with my settings: normal_rust

Multi scoped, normal rust (to see the behavior when an offset is applied): normal_rust_scoped

inside rsx! block at top: inside_rsx_top

inside rsx! block: inside_rsx

here is the loop:

for (my_dummy_data, txt) in data_full_profile
                                        .read()
                                        .0
                                        .as_ref()
                                        .unwrap()
                                        .get()
                                        .dummy_data_for_example[0]
                                        .dummy_section
                                        .iter()
                                        .zip(data_full_profile
                                                .read()
                                                .0
                                                .as_ref()
                                                .unwrap()
                                                .get()
                                                .dummy_data_for_example[0]
                                                .strs
                                                .iter())
                                {}

The wrecked indentation becomes a distraction, even more so in a longish rsx!{}

Here to provide further info if needed.

Thanks!

jkelleyrtp commented 2 months ago

Ah, it's because we don't apply indentation to formatted exprs in for/if loops - guess I didn't expect anyone to use multiline exprs in those cases! Should be simple enough to fix

XavDesbordes commented 2 months ago

I acknowledge being a jackass but it really eases the bulk of data I have to deal with. Do you recommend a specific strategy ? Preparing the iterators out of the rsx!{} block maybe ? (Genuinely open to suggestions to make the app the most efficient as possible)

jkelleyrtp commented 2 months ago

You could extract out to a vec/iterator of elements - this could even be a separate function to clean things up a bit

    let profile = data_full_profile.read();
    let dummy = &profile.0.as_ref().unwrap().get().dummy_data_for_example[0];
    let profiles = dummy.dummy_section.iter().zip(dummy.strs.iter()).map(|s| {
        rsx! {
            div { "Some rendered content {s}" }
        }
    });

    rsx! {
        div { {profiles} }
    };
XavDesbordes commented 2 months ago

That's smart and I like it. Taken :+1: !

jkelleyrtp commented 2 months ago

We still need to format these exprs - so I'll leave this issue open and fix it in #2230

jkelleyrtp commented 2 months ago

Okay cool, should be released soon, your IDE (assuming you're using vscode) will autoupdate in the next day or so

XavDesbordes commented 2 months ago

@jkelleyrtp you rock, really !