Open magikmw opened 2 weeks ago
I am unable to reproduce this using the git version of the CLI. Can you test the git version of the CLI on your end?
You can install the git version with:
cargo install --git https://github.com/DioxusLabs/dioxus dioxus-cli
I did run the command to install git version and checked again:
- // TODO: Implement event handling here -> listen to eve
nts in child
let accept_keys = [Key::Enter, Key::Character(" ".to_string())];
- if accept_keys.contains(&evt.key()){
+ if accept_keys.contains(&evt.key()) {
log::info!("{} pressed in {}", evt.key(), "{props.labelText}");
log::info!("{} pressed in {}", evt.key(), "{props.labelText}");
}
},
class: "flex flex-1 h-full w-3/4 items-center justify-center btn btn-outline my-1 py-1",
- div { class: "flex-none py-1", // TODO: Refactor into separate component
+ div { class: "flex-none py-1",
Icon { width: 24, height: 24, icon: props.icon, title: "{props.iconTitle}" }
- },
+ }
"{props.labelText}"
- input { // TODO: Refactor into separate component
+ input {
dx -V says:
dioxus 0.5.2
I can reproduce it now. The formatter doesn't like inline comments and removes them completely:
rsx! {
div { // this comment will be removed
"hi",
}
}
this also seems to affect the VSCode Dioxus extension. Block-level comments (/* .. */
) are also affected; doc comments (///
) however are not.
Adding to the list.
All comments are removed in event handlers (except doc comments):
rsx! {
div {
// also occurs in move || async move
onclick: move |_| {
// is removed
/* is removed */
}
}
}
I think it comes from here: https://github.com/DioxusLabs/dioxus/blob/472031d1f51557601797d1cb469f09e4f3e0ca71/packages/cli/src/cli/autoformat.rs#L249-L253
syn does not keep comments.
https://crates.io/crates/rustfmt-wrapper (or spawning rustfmt
directly) could be used instead.
This won't help in non-rust code, but I think it's a start.
I don't know if Dioxus developers would agree with this solution, but if they do, I would be happy to do it.
We try our best to preserve comments by writing out whitepace on rsx indents, but there's no way to preserve whitespace with prettyplease. I'd be interested in supporting the rustfmt wrapper approach, but it is convenient for autoformatting to not rely on rustfmt so we can use it in things like wasm.
Problem
Using
dx fmt
on source files is deleting comments, both in rsx macros and standard rust when using--all-code
.This is especially egregious because standard
rustfmt
formatter is really messing up any files with rsx in them, sodx fmt
is the only viable alternative.Steps To Reproduce
Steps to reproduce the behavior:
dx fmt -f yourfile.rs
Expected behavior
Comments should be left alone.
I'm not entirely sure how
rustfmt
does it, but with my limited experience with it, it seems to keep comments intact and relatively in the relevelant place after formatting.Screenshots
n/a
Environment:
Questionnaire