Fix: #2604, Fix: #2240, Fix: #2341, Fix #1355 - Better error handling and and spaces handling in autofmt (#2736)

* add new autofmt sample
* Feat: implement rustfmt::skip support for rsx
* generally improve error handling with better expect messages
* wip: nested rsx formatting and expression formatting
* nested rsx formatting works
* collapse autofmt crate
* cast indent through macros
* use proper whitespace
* no more eating comments!
* Use proper error handling
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-07-30 18:36:13 -07:00
1 parent ef0202f999
commit 828cc502f1
47 files changed
+1621 -1055

No files matched your search

+38 -14
View File
@@ -103,12 +103,22 @@ fn app() -> Element {
rsx! {
div {
{
let millis = timer.with(|t| t.duration().saturating_sub(t.started_at.map(|x| x.elapsed()).unwrap_or(Duration::ZERO)).as_millis());
format!("{:02}:{:02}:{:02}.{:01}",
millis / 1000 / 3600 % 3600,
millis / 1000 / 60 % 60,
millis / 1000 % 60,
millis / 100 % 10)
let millis = timer
.with(|t| {
t
.duration()
.saturating_sub(
t.started_at.map(|x| x.elapsed()).unwrap_or(Duration::ZERO),
)
.as_millis()
});
format!(
"{:02}:{:02}:{:02}.{:01}",
millis / 1000 / 3600 % 3600,
millis / 1000 / 60 % 60,
millis / 1000 % 60,
millis / 100 % 10,
)
}
}
div {
@@ -119,7 +129,7 @@ fn app() -> Element {
value: format!("{:02}", timer.read().hours),
oninput: move |e| {
timer.write().hours = e.value().parse().unwrap_or(0);
}
},
}
input {
@@ -129,7 +139,7 @@ fn app() -> Element {
value: format!("{:02}", timer.read().minutes),
oninput: move |e| {
timer.write().minutes = e.value().parse().unwrap_or(0);
}
},
}
input {
@@ -139,7 +149,7 @@ fn app() -> Element {
value: format!("{:02}", timer.read().seconds),
oninput: move |e| {
timer.write().seconds = e.value().parse().unwrap_or(0);
}
},
}
}
@@ -155,7 +165,7 @@ fn app() -> Element {
};
})
},
{ timer.with(|t| if t.started_at.is_none() { "Start" } else { "Stop" }) }
{timer.with(|t| if t.started_at.is_none() { "Start" } else { "Stop" })}
}
div { id: "app",
button {
@@ -165,7 +175,11 @@ fn app() -> Element {
window_preferences.write().with_decorations = !decorations;
},
{
format!("with decorations{}", if window_preferences.read().with_decorations { " ✓" } else { "" }).to_string()
format!(
"with decorations{}",
if window_preferences.read().with_decorations { " ✓" } else { "" },
)
.to_string()
}
}
button {
@@ -178,7 +192,10 @@ fn app() -> Element {
},
width: 100,
{
format!("always on top{}", if window_preferences.read().always_on_top { " ✓" } else { "" })
format!(
"always on top{}",
if window_preferences.read().always_on_top { " ✓" } else { "" },
)
}
}
}
@@ -186,8 +203,15 @@ fn app() -> Element {
exit_button(
Duration::from_secs(3),
|trigger, delay| rsx! {
{format!("{:0.1?}", trigger.read().map(|inst| (delay.as_secs_f32() - inst.elapsed().as_secs_f32()))) }
}
{
format!(
"{:0.1?}",
trigger
.read()
.map(|inst| (delay.as_secs_f32() - inst.elapsed().as_secs_f32())),
)
}
},
)
}
}
@@ -11,7 +11,7 @@ fn main() {
None
};
})
}
},
}
}
}
@@ -2,12 +2,22 @@ fn main() {
rsx! {
div {
{
let millis = timer.with(|t| t.duration().saturating_sub(t.started_at.map(|x| x.elapsed()).unwrap_or(Duration::ZERO)).as_millis());
format!("{:02}:{:02}:{:02}.{:01}",
millis / 1000 / 3600 % 3600,
millis / 1000 / 60 % 60,
millis / 1000 % 60,
millis / 100 % 10)
let millis = timer
.with(|t| {
t
.duration()
.saturating_sub(
t.started_at.map(|x| x.elapsed()).unwrap_or(Duration::ZERO),
)
.as_millis()
});
format!(
"{:02}:{:02}:{:02}.{:01}",
millis / 1000 / 3600 % 3600,
millis / 1000 / 60 % 60,
millis / 1000 % 60,
millis / 100 % 10,
)
}
}
div {
@@ -18,7 +28,7 @@ fn main() {
value: format!("{:02}", timer.read().hours),
oninput: move |e| {
timer.write().hours = e.value().parse().unwrap_or(0);
}
},
}
// some comment
input {
@@ -28,7 +38,7 @@ fn main() {
value: format!("{:02}", timer.read().hours),
oninput: move |e| {
timer.write().hours = e.value().parse().unwrap_or(0);
}
},
}
}
}
+36
View File
@@ -0,0 +1,36 @@
/// dont format this component
#[rustfmt::skip]
#[component]
fn SidebarSection() -> Element {
rsx! {
div {
"hi" div {} div {}
}
}
}
/// dont format this component
#[component]
fn SidebarSection() -> Element {
// format this
rsx! {
div { "hi" }
}
// and this
rsx! {
div {
"hi"
div {}
div {}
}
}
// but not this
#[rustfmt::skip]
rsx! {
div {
"hi" div {} div {}
}
}
}
@@ -0,0 +1,32 @@
/// dont format this component
#[rustfmt::skip]
#[component]
fn SidebarSection() -> Element {
rsx! {
div {
"hi" div {} div {}
}
}
}
/// dont format this component
#[component]
fn SidebarSection() -> Element {
// format this
rsx! {
div { "hi" }
}
// and this
rsx! {
div { "hi" div {} div {} }
}
// but not this
#[rustfmt::skip]
rsx! {
div {
"hi" div {} div {}
}
}
}